Allow deleting unused library files with profile guards

This commit is contained in:
Mikei386
2026-09-30 10:21:07 +02:00
parent 459150975b
commit ef80b2a0ca
5 changed files with 64 additions and 3 deletions
+17
View File
@@ -140,6 +140,23 @@ class Catalog:
path=self.root/ident/('model'+PurePosixPath(entry['file']).suffix)
if not path.is_file() or path.stat().st_size!=entry['size']:raise ValueError('Modelldatei fehlt oder ist unvollständig.')
return entry
def delete(self,ident,profiles,active_model_id=None):
if not isinstance(ident,str) or not re.fullmatch(r'[a-f0-9]{64}',ident):raise ValueError('Ungültige Modelldatei-ID.')
# Profile writes and deletions use the same lock order: profiles, catalog.
with profiles.lock,self.lock:
users=profiles.references(ident)
if users:raise ValueError('Datei wird noch verwendet von: '+', '.join(x['name'] for x in users)+'. Bitte zuerst diese Profile löschen.')
if ident==active_model_id:raise ValueError('Datei ist noch in der Deck-Laufzeit geladen. Modell zuerst entladen.')
if any(x.get('entry_id')==ident and x['state'] in ('queued','downloading') for x in self.history):raise ValueError('Laufenden oder vorgemerkten Download zuerst abbrechen.')
entry=self.entry(ident)
target=self.root/ident
if target.is_symlink() or not target.is_dir():raise ValueError('Ungültiges Bibliotheksverzeichnis.')
shutil.rmtree(target)
for job in self.history:
if job.get('entry_id')==ident or job.get('id')=='import-'+ident:job['dismissed']=True
if self.job and self.job.get('entry_id')==ident:self.job=None
self._save_history()
return {'deleted':ident,'bytes_freed':entry['size']}
def search(self,q,kind,sort="downloads",base_only=False,purpose="model"):
if purpose not in ('model','projector'):raise ValueError('Ungültiger Suchzweck.')
if kind not in KINDS or not isinstance(q,str) or len(q)>120:raise ValueError('Ungültige Suche.')