Skip to content

Commit aa07ab9

Browse files
committed
Fix for default cache directory
1 parent 814645e commit aa07ab9

2 files changed

Lines changed: 13 additions & 22 deletions

File tree

music_assistant/__main__.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import asyncio
77
import logging
88
import os
9+
import shutil
910
import subprocess
1011
import sys
1112
import threading
@@ -44,15 +45,11 @@ def get_arguments() -> argparse.Namespace:
4445
os.getenv("XDG_DATA_HOME", os.path.join(os.path.expanduser("~"), ".local", "share")),
4546
"music-assistant",
4647
)
47-
# determine default cache directory
48-
if os.path.isdir(old_cache_dir := os.path.join(default_data_dir, ".cache")):
49-
# prefer (existing) legacy directory
50-
default_cache_dir = old_cache_dir
51-
else:
52-
default_cache_dir = os.path.join(
53-
os.getenv("XDG_CACHE_HOME", os.path.join(os.path.expanduser("~"), ".cache")),
54-
"music-assistant",
55-
)
48+
49+
default_cache_dir = os.path.join(
50+
os.getenv("XDG_CACHE_HOME", os.path.join(os.path.expanduser("~"), ".cache")),
51+
"music-assistant",
52+
)
5653

5754
parser.add_argument(
5855
"--data-dir",
@@ -200,7 +197,14 @@ def main() -> None:
200197
data_dir = args.data_dir
201198
cache_dir = args.cache_dir
202199

200+
# move legacy cache directory
201+
old_cache_dir = os.path.join(data_dir, ".cache")
202+
if os.path.isdir(old_cache_dir) and old_cache_dir != cache_dir:
203+
with suppress(OSError):
204+
shutil.move(old_cache_dir, cache_dir)
205+
203206
os.makedirs(data_dir, exist_ok=True)
207+
os.makedirs(cache_dir, exist_ok=True)
204208

205209
# TEMP: override options though hass config file
206210
hass_options_file = os.path.join(data_dir, "options.json")

music_assistant/mass.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -855,16 +855,3 @@ async def _setup_storage(self) -> None:
855855
await mkdirs(self.storage_path)
856856
if not await isdir(self.cache_path):
857857
await mkdirs(self.cache_path)
858-
# cleanup old cache files from their old locations
859-
# TODO: Remove this code after MA version 2.5+
860-
old_cache_db = os.path.join(self.storage_path, "cache.db")
861-
if await isfile(old_cache_db):
862-
await rmfile(old_cache_db)
863-
for filename in await listdir(self.storage_path):
864-
if filename.startswith(("spotify", "collage")):
865-
old_loc = os.path.join(self.storage_path, filename)
866-
new_loc = os.path.join(self.cache_path, filename)
867-
if await isfile(new_loc):
868-
await rmfile(old_loc)
869-
else:
870-
await rename(old_loc, new_loc)

0 commit comments

Comments
 (0)