diff --git a/dangerzone/document.py b/dangerzone/document.py index 955f6f2..aa78de3 100644 --- a/dangerzone/document.py +++ b/dangerzone/document.py @@ -77,6 +77,11 @@ class Document: # in unwriteable directory raise errors.UnwriteableOutputDirException() + def validate_default_archive_dir(self) -> None: + """Checks if archive dir can be created""" + if not os.access(self.default_archive_dir.parent, os.W_OK): + raise errors.UnwriteableArchiveDirException() + @property def input_filename(self) -> str: if self._input_filename is None: @@ -125,6 +130,7 @@ class Document: @archive_after_conversion.setter def archive_after_conversion(self, enabled: bool) -> None: if enabled: + self.validate_default_archive_dir() self._archive = True else: self._archive = False diff --git a/dangerzone/errors.py b/dangerzone/errors.py index 0c2d3dd..f3b50e3 100644 --- a/dangerzone/errors.py +++ b/dangerzone/errors.py @@ -71,6 +71,15 @@ class OutputDirIsNotDirException(DocumentFilenameException): super().__init__("Specified output directory is actually not a directory") +class UnwriteableArchiveDirException(DocumentFilenameException): + """Exception for when the archive directory cannot be created.""" + + def __init__(self) -> None: + super().__init__( + "Archive directory for storing unsafe documents cannot be created." + ) + + class SuffixNotApplicableException(DocumentFilenameException): """Exception for when the suffix cannot be applied to the output filename."""