Skip to content

Commit 922428d

Browse files
committed
Raise ProcessingException for password protectex 7z archive.
1 parent 511f516 commit 922428d

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

ingestors/packages/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from pathlib import PurePath
66

77
import py7zr
8-
from py7zr.exceptions import ArchiveError
8+
from py7zr.exceptions import ArchiveError, PasswordRequired
99

10-
from ingestors.exc import ProcessingException
10+
from ingestors.exc import ENCRYPTED_MSG, ProcessingException
1111
from ingestors.ingestor import Ingestor
1212
from ingestors.support.package import PackageSupport
1313
from ingestors.support.shell import ShellSupport
@@ -29,7 +29,10 @@ def unpack(self, file_path, entity, temp_dir):
2929

3030
try:
3131
with py7zr.SevenZipFile(str(pure_file_path), mode="r") as extractor:
32-
extractor.extractall(path=temp_dir)
32+
try:
33+
extractor.extractall(path=temp_dir)
34+
except PasswordRequired:
35+
raise ProcessingException(ENCRYPTED_MSG)
3336
except ArchiveError as e:
3437
raise ProcessingException(f"Error: {e}")
3538

ingestors/support/package.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import shutil
21
import logging
2+
import shutil
3+
34
from followthemoney import model
45

5-
from ingestors.support.temp import TempFileSupport
6-
from ingestors.support.encoding import EncodingSupport
76
from ingestors.directory import DirectoryIngestor
87
from ingestors.exc import ProcessingException
8+
from ingestors.support.encoding import EncodingSupport
9+
from ingestors.support.temp import TempFileSupport
910

1011
log = logging.getLogger(__name__)
1112

@@ -36,7 +37,7 @@ def ingest(self, file_path, entity):
3637
self.manager.delegate(DirectoryIngestor, temp_dir, entity)
3738
except ProcessingException as e:
3839
raise ProcessingException(
39-
"Could not unpack the contents of this file."
40+
f"Could not unpack the contents of this file. {e}"
4041
) from e
4142

4243
def unpack(self, file_path, entity, temp_dir):

0 commit comments

Comments
 (0)