fix(maintenance): guard media cache cleanup and annotate exception suppression

- Safely resolve media_cache via getattr in cleanup_expired_files to prevent AttributeError when storage_mgr is unset in cloud/test fixtures
- Only attach 'media_files' in cleanup return dictionary when media cache is active on singleton, preserving exact return contract for cloud maintenance tests
- Add explanatory comments to exception suppression in MediaCache.touch and cleanup loops to address code-quality review findings
This commit is contained in:
BiFangKNT
2026-09-15 20:30:34 +08:00
parent c16cd433e0
commit 7e239f1629
2 changed files with 13 additions and 6 deletions
+4 -1
View File
@@ -120,6 +120,7 @@ class MediaCache:
try:
await asyncio.to_thread(os.utime, full_path, (now, now))
except Exception:
# Failures to update mtime are intentionally ignored because LRU touch is opportunistic.
pass
async def cleanup(
@@ -166,6 +167,7 @@ class MediaCache:
expired_deleted += 1
bytes_freed += stat.st_size
except OSError:
# Best-effort cleanup; file may already be gone or temporarily inaccessible.
pass
else:
remaining.append((entry, stat.st_size, stat.st_mtime))
@@ -184,7 +186,8 @@ class MediaCache:
bytes_freed += size
total_bytes -= size
except OSError:
pass
# Best-effort cleanup; file may already be gone or temporarily inaccessible.
continue
return {
'expired_deleted': expired_deleted,