Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

fixed the decryption code, but its still untested.

Jonas Winkler2a4fe4dceb35
diff --git a/src/documents/management/commands/decrypt_documents.py b/src/documents/management/commands/decrypt_documents.py
index e4d607fa8..f9b4edcdc 100644
--- a/src/documents/management/commands/decrypt_documents.py
+++ b/src/documents/management/commands/decrypt_documents.py
@@ -61,18 +61,28 @@ class Command(BaseCommand):
document).encode('utf-8'), "green"))
old_paths = [document.source_path, document.thumbnail_path]
+
raw_document = GnuPG.decrypted(document.source_file, passphrase)
raw_thumb = GnuPG.decrypted(document.thumbnail_file, passphrase)
document.storage_type = Document.STORAGE_TYPE_UNENCRYPTED
+ ext = os.path.splitext(document.filename)[1]
+
+ if not ext == '.gpg':
+ raise CommandError(
+ f"Abort: encrypted file {document.source_path} does not "
+ f"end with .gpg")
+
+ document.filename = os.path.splitext(document.source_path)[0]
+
with open(document.source_path, "wb") as f:
f.write(raw_document)
with open(document.thumbnail_path, "wb") as f:
f.write(raw_thumb)
- document.save(update_fields=("storage_type",))
+ document.save(update_fields=("storage_type", "filename"))
for path in old_paths:
os.unlink(path)