in client/securedrop_client/api_jobs/downloads.py [0:0]
def _download(self, api: API, db_object: File | Message | Reply, session: Session) -> str:
"""
Download the encrypted file. Check file integrity and move it to the data directory before
marking it as downloaded.
Note: On Qubes OS, files are downloaded to /home/user/Downloads
"""
try:
etag, download_path = self.call_download_api(api, db_object)
if not self._check_file_integrity(etag, download_path):
download_error = (
session.query(DownloadError)
.filter_by(name=DownloadErrorCodes.CHECKSUM_ERROR.name)
.one()
)
db_object.download_error = download_error
session.commit()
exception = DownloadChecksumMismatchException(
"Downloaded file had an invalid checksum.", type(db_object), db_object.uuid
)
raise exception
destination = db_object.location(self.data_dir)
safe_move(download_path, destination, self.data_dir)
db_object.download_error = None
mark_as_downloaded(type(db_object), db_object.uuid, session)
logger.info(f"File downloaded to {destination}")
return destination
except (ValueError, FileNotFoundError, RuntimeError, BaseError) as e:
logger.error("Download failed")
logger.debug(f"Download failed: {e}")
raise DownloadDecryptionException(
f"Failed to download {db_object.uuid}", type(db_object), db_object.uuid
) from e