file_manager: set a metadata version to force re-processing
When an entry is removed from metadata also remove associated thumbnails. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
05b8c4eaef
commit
ca2bd380cf
|
@ -622,6 +622,7 @@ class FileManager:
|
|||
|
||||
METADATA_PRUNE_TIME = 600000
|
||||
METADATA_NAMESPACE = "gcode_metadata"
|
||||
METADATA_VERSION = 2
|
||||
|
||||
class MetadataStorage:
|
||||
def __init__(self, server, gc_path, database):
|
||||
|
@ -629,6 +630,14 @@ class MetadataStorage:
|
|||
database.register_local_namespace(METADATA_NAMESPACE)
|
||||
self.mddb = database.wrap_namespace(
|
||||
METADATA_NAMESPACE, parse_keys=False)
|
||||
version = database.get_item(
|
||||
"moonraker", "file_manager.metadata_version", 0)
|
||||
if version != METADATA_VERSION:
|
||||
# Clear existing metadata when version is bumped
|
||||
self.mddb.clear()
|
||||
database.insert_item(
|
||||
"moonraker", "file_manager.metadata_version",
|
||||
METADATA_VERSION)
|
||||
self.pending_requests = {}
|
||||
self.events = {}
|
||||
self.busy = False
|
||||
|
@ -657,7 +666,7 @@ class MetadataStorage:
|
|||
for fname in list(self.mddb.keys()):
|
||||
fpath = os.path.join(self.gc_path, fname)
|
||||
if not os.path.exists(fpath):
|
||||
del self.mddb[fname]
|
||||
self.remove_file(fname)
|
||||
logging.info(f"Pruned file: {fname}")
|
||||
continue
|
||||
|
||||
|
@ -666,10 +675,21 @@ class MetadataStorage:
|
|||
return mdata['size'] == fsize and mdata['modified'] == modified
|
||||
|
||||
def remove_file(self, fname):
|
||||
metadata = self.mddb.pop(fname, None)
|
||||
if metadata is None:
|
||||
return
|
||||
# Delete associated thumbnails
|
||||
fdir = os.path.dirname(os.path.join(self.gc_path, fname))
|
||||
if "thumbnails" in metadata:
|
||||
for thumb in metadata["thumbnails"]:
|
||||
path = thumb.get("relative_path", None)
|
||||
if path is None:
|
||||
continue
|
||||
thumb_path = os.path.join(fdir, path)
|
||||
try:
|
||||
del self.mddb[fname]
|
||||
os.remove(thumb_path)
|
||||
except Exception:
|
||||
pass
|
||||
logging.debug(f"Error removing thumb at {thumb_path}")
|
||||
|
||||
def parse_metadata(self, fname, fsize, modified, notify=False):
|
||||
evt = Event()
|
||||
|
|
Loading…
Reference in New Issue