mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 18:22:37 +02:00
Ensure archive directory can be created
Verifies that the archive directory can be created as soon as the document is set to be archived.
This commit is contained in:
parent
bbd0d98f50
commit
f54446f2fd
2 changed files with 15 additions and 0 deletions
|
@ -77,6 +77,11 @@ class Document:
|
||||||
# in unwriteable directory
|
# in unwriteable directory
|
||||||
raise errors.UnwriteableOutputDirException()
|
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
|
@property
|
||||||
def input_filename(self) -> str:
|
def input_filename(self) -> str:
|
||||||
if self._input_filename is None:
|
if self._input_filename is None:
|
||||||
|
@ -125,6 +130,7 @@ class Document:
|
||||||
@archive_after_conversion.setter
|
@archive_after_conversion.setter
|
||||||
def archive_after_conversion(self, enabled: bool) -> None:
|
def archive_after_conversion(self, enabled: bool) -> None:
|
||||||
if enabled:
|
if enabled:
|
||||||
|
self.validate_default_archive_dir()
|
||||||
self._archive = True
|
self._archive = True
|
||||||
else:
|
else:
|
||||||
self._archive = False
|
self._archive = False
|
||||||
|
|
|
@ -71,6 +71,15 @@ class OutputDirIsNotDirException(DocumentFilenameException):
|
||||||
super().__init__("Specified output directory is actually not a directory")
|
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):
|
class SuffixNotApplicableException(DocumentFilenameException):
|
||||||
"""Exception for when the suffix cannot be applied to the output filename."""
|
"""Exception for when the suffix cannot be applied to the output filename."""
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue