Spaces:
Running
Running
fix: protect retained canonical assets from cleanup
Browse files- app/services/cleanup.py +3 -2
app/services/cleanup.py
CHANGED
|
@@ -129,16 +129,17 @@ class CleanupService:
|
|
| 129 |
raise NotFoundError("Output file not found")
|
| 130 |
return candidate
|
| 131 |
|
| 132 |
-
async def cleanup_expired(self) -> int:
|
| 133 |
cutoff = time.time() - self.settings.cleanup_minutes * 60
|
| 134 |
async with self._lock:
|
| 135 |
active = self._active.copy()
|
| 136 |
removed = 0
|
|
|
|
| 137 |
for base in (self.settings.temp_dir, self.settings.output_dir):
|
| 138 |
if not base.exists():
|
| 139 |
continue
|
| 140 |
for path in list(base.iterdir()):
|
| 141 |
-
if not path.is_dir() or path.name in active:
|
| 142 |
continue
|
| 143 |
try:
|
| 144 |
if path.stat().st_mtime < cutoff:
|
|
|
|
| 129 |
raise NotFoundError("Output file not found")
|
| 130 |
return candidate
|
| 131 |
|
| 132 |
+
async def cleanup_expired(self, protected_request_ids: set[str] | None = None) -> int:
|
| 133 |
cutoff = time.time() - self.settings.cleanup_minutes * 60
|
| 134 |
async with self._lock:
|
| 135 |
active = self._active.copy()
|
| 136 |
removed = 0
|
| 137 |
+
protected = protected_request_ids or set()
|
| 138 |
for base in (self.settings.temp_dir, self.settings.output_dir):
|
| 139 |
if not base.exists():
|
| 140 |
continue
|
| 141 |
for path in list(base.iterdir()):
|
| 142 |
+
if not path.is_dir() or path.name in active or path.name in protected:
|
| 143 |
continue
|
| 144 |
try:
|
| 145 |
if path.stat().st_mtime < cutoff:
|