]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
only move unaffected files, regenerate affected files
authorjonaswinkler <jonas.winkler@jpwinkler.de>
Mon, 8 Feb 2021 22:54:07 +0000 (23:54 +0100)
committerjonaswinkler <jonas.winkler@jpwinkler.de>
Mon, 8 Feb 2021 22:54:07 +0000 (23:54 +0100)
src/documents/migrations/1012_fix_archive_files.py

index 98794aad08f6514902645e4d8b6d35f70a8ba50f..ab7e88a6a1ce9e4e36b22d05e0e9b32c95ca3246 100644 (file)
@@ -102,11 +102,17 @@ def move_old_to_new_locations(apps, schema_editor):
         old_path = archive_path_old(doc)
         new_path = archive_path_new(doc)
 
-        if old_path != new_path and not os.path.isfile(new_path):
-            logger.debug(
-                f"Moving {old_path} to {new_path}"
-            )
-            shutil.move(old_path, new_path)
+        if doc.id in affected_document_ids:
+            # remove affected archive versions
+            if os.path.isfile(old_path):
+                os.unlink(old_path)
+        else:
+            # move unaffected archive versions
+            if old_path != new_path and os.path.isfile(old_path) and not os.path.isfile(new_path):
+                logger.debug(
+                    f"Moving {old_path} to {new_path}"
+                )
+                shutil.move(old_path, new_path)
 
     # regenerate archive documents
     for doc_id in affected_document_ids: