|
6 | 6 | import asyncio |
7 | 7 | import logging |
8 | 8 | import os |
| 9 | +import shutil |
9 | 10 | import subprocess |
10 | 11 | import sys |
11 | 12 | import threading |
@@ -44,15 +45,11 @@ def get_arguments() -> argparse.Namespace: |
44 | 45 | os.getenv("XDG_DATA_HOME", os.path.join(os.path.expanduser("~"), ".local", "share")), |
45 | 46 | "music-assistant", |
46 | 47 | ) |
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 | + ) |
56 | 53 |
|
57 | 54 | parser.add_argument( |
58 | 55 | "--data-dir", |
@@ -200,7 +197,14 @@ def main() -> None: |
200 | 197 | data_dir = args.data_dir |
201 | 198 | cache_dir = args.cache_dir |
202 | 199 |
|
| 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 | + |
203 | 206 | os.makedirs(data_dir, exist_ok=True) |
| 207 | + os.makedirs(cache_dir, exist_ok=True) |
204 | 208 |
|
205 | 209 | # TEMP: override options though hass config file |
206 | 210 | hass_options_file = os.path.join(data_dir, "options.json") |
|
0 commit comments