From d5017045b73f5c0a5aeb2091ab1a6cd31a39baca Mon Sep 17 00:00:00 2001 From: djairoh Date: Thu, 6 Feb 2025 23:17:38 +0100 Subject: [PATCH] forgor linux allows like \ and ' in filenames --- backerupper.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backerupper.py b/backerupper.py index 786bacc..da906cd 100755 --- a/backerupper.py +++ b/backerupper.py @@ -44,6 +44,7 @@ class ExportService(): re_re: path substitution (if necessary); real folder structure component. """ a = ExportService.get_annotations(db, user_id, re_nav, re_re) + print(f"Fetched {len(a)} annotations from db!") ExportService.write_annotations(a) @@ -112,6 +113,7 @@ class ImportService(): re_re: path substitution (if necessary); real folder structure component. """ a = ImportService.get_annotations(path, re_nav, re_re) + print(f"Read {len(a)} annotations from files!") ImportService.write_annotations(a, db, user_id) @@ -129,6 +131,7 @@ class ImportService(): realpath = os.path.realpath(path) annos = {} + print(f"Reading files (this may take a while)...") for dir,_,files in os.walk(realpath): for mp3_file in files: if mp3_file.endswith('.mp3'): @@ -169,7 +172,8 @@ class ImportService(): conn = sqlite3.connect(db) cursor = conn.cursor() # step 1: fetch path and item_id for existing annotations WHERE path IN annos.paths - cursor.execute(f"""SELECT path,id FROM media_file WHERE path IN ('{"','".join([ re.sub(re_re, re_nav, k) for k in annos.keys()])}')""") + escaped = "','".join([ re.sub(r'\\', r'\\\\', re.sub("'", "''", re.sub(re_re, re_nav, k))) for k in annos.keys()]) + cursor.execute(f"""SELECT path,id FROM media_file WHERE path IN ('{escaped}')""") # step 2: create list with item_ids items = []