mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	Use relatives paths instead of absolutes paths for document export/import
This commit is contained in:
		@@ -62,17 +62,20 @@ class Command(Renderable, BaseCommand):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            document = document_map[document_dict["pk"]]
 | 
					            document = document_map[document_dict["pk"]]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            target = os.path.join(self.target, document.file_name)
 | 
					            file_target = os.path.join(self.target, document.file_name)
 | 
				
			||||||
            thumbnail_target = target + "-tumbnail.png"
 | 
					 | 
				
			||||||
            document_dict[EXPORTER_FILE_NAME] = target
 | 
					 | 
				
			||||||
            document_dict[EXPORTER_THUMBNAIL_NAME] = thumbnail_target
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            print("Exporting: {}".format(target))
 | 
					            thumbnail_name = document.file_name + "-tumbnail.png"
 | 
				
			||||||
 | 
					            thumbnail_target = os.path.join(self.target, thumbnail_name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            document_dict[EXPORTER_FILE_NAME] = document.file_name
 | 
				
			||||||
 | 
					            document_dict[EXPORTER_THUMBNAIL_NAME] = thumbnail_name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            print("Exporting: {}".format(file_target))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            t = int(time.mktime(document.created.timetuple()))
 | 
					            t = int(time.mktime(document.created.timetuple()))
 | 
				
			||||||
            with open(target, "wb") as f:
 | 
					            with open(file_target, "wb") as f:
 | 
				
			||||||
                f.write(GnuPG.decrypted(document.source_file))
 | 
					                f.write(GnuPG.decrypted(document.source_file))
 | 
				
			||||||
                os.utime(target, times=(t, t))
 | 
					                os.utime(file_target, times=(t, t))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            with open(thumbnail_target, "wb") as f:
 | 
					            with open(thumbnail_target, "wb") as f:
 | 
				
			||||||
                f.write(GnuPG.decrypted(document.thumbnail_file))
 | 
					                f.write(GnuPG.decrypted(document.thumbnail_file))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -79,7 +79,7 @@ class Command(Renderable, BaseCommand):
 | 
				
			|||||||
                )
 | 
					                )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            doc_file = record[EXPORTER_FILE_NAME]
 | 
					            doc_file = record[EXPORTER_FILE_NAME]
 | 
				
			||||||
            if not os.path.exists(doc_file):
 | 
					            if not os.path.exists(os.path.join(self.source, doc_file)):
 | 
				
			||||||
                raise CommandError(
 | 
					                raise CommandError(
 | 
				
			||||||
                    'The manifest file refers to "{}" which does not '
 | 
					                    'The manifest file refers to "{}" which does not '
 | 
				
			||||||
                    'appear to be in the source directory.'.format(doc_file)
 | 
					                    'appear to be in the source directory.'.format(doc_file)
 | 
				
			||||||
@@ -96,13 +96,16 @@ class Command(Renderable, BaseCommand):
 | 
				
			|||||||
            thumb_file = record[EXPORTER_THUMBNAIL_NAME]
 | 
					            thumb_file = record[EXPORTER_THUMBNAIL_NAME]
 | 
				
			||||||
            document = Document.objects.get(pk=record["pk"])
 | 
					            document = Document.objects.get(pk=record["pk"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            with open(doc_file, "rb") as unencrypted:
 | 
					            document_path = os.path.join(self.source, doc_file)
 | 
				
			||||||
 | 
					            thumbnail_path = os.path.join(self.source, thumb_file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            with open(document_path, "rb") as unencrypted:
 | 
				
			||||||
                with open(document.source_path, "wb") as encrypted:
 | 
					                with open(document.source_path, "wb") as encrypted:
 | 
				
			||||||
                    print("Encrypting {} and saving it to {}".format(
 | 
					                    print("Encrypting {} and saving it to {}".format(
 | 
				
			||||||
                        doc_file, document.source_path))
 | 
					                        doc_file, document.source_path))
 | 
				
			||||||
                    encrypted.write(GnuPG.encrypted(unencrypted))
 | 
					                    encrypted.write(GnuPG.encrypted(unencrypted))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            with open(thumb_file, "rb") as unencrypted:
 | 
					            with open(thumbnail_path, "rb") as unencrypted:
 | 
				
			||||||
                with open(document.thumbnail_path, "wb") as encrypted:
 | 
					                with open(document.thumbnail_path, "wb") as encrypted:
 | 
				
			||||||
                    print("Encrypting {} and saving it to {}".format(
 | 
					                    print("Encrypting {} and saving it to {}".format(
 | 
				
			||||||
                        thumb_file, document.thumbnail_path))
 | 
					                        thumb_file, document.thumbnail_path))
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user