Skip to content

Commit

Permalink
app: rework submission deletion method for new folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
redshiftzero committed Mar 12, 2020
1 parent 6d8a674 commit bcf12ad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion securedrop_client/api_jobs/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _download(self,
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 ~/QubesIncoming.
Note: On Qubes OS, files are downloaded to /home/user/QubesIncoming/sd-proxy
'''
try:
etag, download_path = self.call_download_api(api, db_object)
Expand Down
28 changes: 16 additions & 12 deletions securedrop_client/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"""
from datetime import datetime
import logging
import glob
import os
import shutil
from dateutil.parser import parse
Expand Down Expand Up @@ -541,21 +540,26 @@ def delete_source_collection(journalist_filename: str, data_dir: str) -> None:
def delete_single_submission_or_reply_on_disk(obj_db: Union[File, Message, Reply],
data_dir: str) -> None:
"""
Delete on disk a single submission or reply.
Delete on disk any files associated with a single submission or reply.
"""
files_to_delete = []
filename_without_extensions = obj_db.filename.split('.')[0]
file_glob_pattern = os.path.join(
data_dir,
'{}*'.format(filename_without_extensions)
)
files_to_delete.extend(glob.glob(file_glob_pattern))

for file_to_delete in files_to_delete:
try:
os.remove(obj_db.location(data_dir))
except FileNotFoundError:
logging.info('Object %s already deleted, skipping', obj_db.location(data_dir))

if isinstance(obj_db, File):
# When a file is being processed (e.g. its filename is being extracted), it
# is stored in an intermediate state in a folder in the source data dir.
# We should also delete this entire directory.
in_progress_folder = os.path.join(
data_dir, obj_db.source.journalist_filename,
'{}-{}-doc'.format(obj_db.file_counter, obj_db.source.journalist_filename))

try:
os.remove(file_to_delete)
shutil.rmtree(in_progress_folder)
except FileNotFoundError:
logging.info('File %s already deleted, skipping', file_to_delete)
pass


def source_exists(session: Session, source_uuid: str) -> bool:
Expand Down

0 comments on commit bcf12ad

Please sign in to comment.