From 3d1a629970b1eea1ff46593ae287501b5b7be952 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 13 Jan 2019 00:16:47 +0530 Subject: [PATCH] also remove duplicates if they show up first --- oml/item/scan.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/oml/item/scan.py b/oml/item/scan.py index 6c966b6..ca8856f 100644 --- a/oml/item/scan.py +++ b/oml/item/scan.py @@ -144,6 +144,15 @@ def run_scan(): if os.path.exists(f): id = media.get_id(f) file = File.get(id) + if file: + f1 = file.fullpath() + f2 = os.path.join(prefix, f) + if f1 != f2 and os.path.exists(f1) and os.path.exists(f2): + logger.debug('file exists in multiple locations %s', id) + logger.debug('"%s" vs "%s"', f1, f2) + os.chmod(f2, stat.S_IWRITE) + os.unlink(f2) + continue if id in ids: logger.debug('file exists in multiple locations %s', id) if file: @@ -182,7 +191,9 @@ def run_scan(): logger.debug('cleaning up %s deleted records', len(gone)) for id in gone: i = Item.get(id) - i.remove_file() + if not i.file or not os.path.exists(i.file.fullpath()): + logger.debug('cleaning orphaned record %s %s', i, i.file.fullpath() if i.file else '') + i.remove_file() missing = ids - library_items if missing: logger.debug('%s items in library without a record', len(missing))