Remove legacy key file support after DB migration

- SerieScanner: Remove key file fallback, keep data file fallback
- SystemSettings: Add legacy_key_cleanup_completed flag
- initialization_service: Add cleanup task to remove key files from folders with DB entries
- Tests updated to reflect key file removal from legacy path

Key files caused duplicate key errors on folder rename. DB is now sole source of truth.
This commit is contained in:
2026-05-28 22:01:37 +02:00
parent 1ef59c5283
commit 4e6afa31b5
7 changed files with 161 additions and 49 deletions

View File

@@ -618,7 +618,8 @@ class SerieScanner:
1. Query DB by folder name
2. If found, return cached Serie object
3. If not in DB, fall back to provider search via _db_lookup callback
4. (Legacy) If still not found, try reading 'key' file as last resort
4. If still not found, try reading 'data' file for legacy deployments
5. Generate key from folder name as last resort
Args:
folder_name: Filesystem folder name
@@ -627,9 +628,8 @@ class SerieScanner:
Serie object with valid key if found, None otherwise
Note:
DB is the source of truth. File-based lookups (key/data files)
are temporary backward compatibility for deployments with old data.
Will be removed in v3.0.0.
DB is the source of truth. File-based lookups (data files)
are temporary backward compatibility for CLI-only deployments.
"""
# Step 1: Try DB lookup by folder name
try:
@@ -680,25 +680,8 @@ class SerieScanner:
exc
)
# Step 3: Legacy fallback - TEMPORARY (remove in v3.0.0)
# Step 3: Legacy data file fallback (CLI-only deployments)
folder_path = os.path.join(self.directory, folder_name)
key_file = os.path.join(folder_path, 'key')
if os.path.exists(key_file):
logger.warning(
"Using legacy 'key' file for '%s' - this fallback is deprecated "
"and will be removed in v3.0.0",
folder_name
)
with open(key_file, 'r', encoding='utf-8') as file:
key = file.read().strip()
logger.info(
"Key found for folder '%s': %s",
folder_name,
key
)
year_from_folder = self._extract_year_from_folder_name(folder_name)
return Serie(key, "", "aniworld.to", folder_name, dict(), year=year_from_folder)
serie_file = os.path.join(folder_path, 'data')
if os.path.exists(serie_file):
with open(serie_file, "rb") as file: