]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
In cases where a temporary file is created or used, copy the original file stats...
authorTrenton H <797416+stumpylog@users.noreply.github.com>
Fri, 26 May 2023 20:50:41 +0000 (13:50 -0700)
committerTrenton H <797416+stumpylog@users.noreply.github.com>
Wed, 7 Jun 2023 16:02:19 +0000 (09:02 -0700)
src/documents/barcodes.py
src/documents/consumer.py

index 79fa2746fba180839c413ca980443803e5a46c65..dfeac545b2244580f64be0b473a24417fd357b6d 100644 (file)
@@ -180,6 +180,9 @@ class BarcodeReader:
         with scratch_image.open("rb") as img_file, self.pdf_file.open("wb") as pdf_file:
             pdf_file.write(img2pdf.convert(img_file))
 
+        # Copy what file stat is possible
+        shutil.copystat(self.file, self.pdf_file)
+
     def detect(self) -> None:
         """
         Scan all pages of the PDF as images, updating barcodes and the pages
@@ -292,6 +295,9 @@ class BarcodeReader:
                 savepath = Path(self.temp_dir.name) / output_filename
                 with open(savepath, "wb") as out:
                     dst.save(out)
+
+                shutil.copystat(self.file, savepath)
+
                 document_paths.append(savepath)
 
             return document_paths
index d6d3513ec7527b4c0300c57f1334047905bd74e4..f2da2ff42a2103c47fa5d70882b56ccd91c921fd 100644 (file)
@@ -326,7 +326,7 @@ class Consumer(LoggingMixin):
             dir=settings.SCRATCH_DIR,
         )
         self.path = Path(tempdir.name) / Path(self.filename)
-        shutil.copy(self.original_path, self.path)
+        shutil.copy2(self.original_path, self.path)
 
         # Determine the parser class.
 
@@ -582,6 +582,7 @@ class Consumer(LoggingMixin):
     def _write(self, storage_type, source, target):
         with open(source, "rb") as read_file, open(target, "wb") as write_file:
             write_file.write(read_file.read())
+        shutil.copystat(source, target)
 
     def _log_script_outputs(self, completed_process: CompletedProcess):
         """