Skip to content

Commit

Permalink
add logs to delete_file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
dchhabda committed Oct 17, 2024
1 parent f220e42 commit 23912ab
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions pybossa/repositories/task_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ def _delete_zip_files_from_store(self, project):
json_taskruns_filename = json_exporter.download_name(project, 'task_run')
csv_taskruns_filename = csv_exporter.download_name(project, 'task_run')
container = "user_%s" % project.owner_id
current_app.logger.info("delete_zip_files_from_store. project %d container %s. delete files %s, %s, %s, %s", project.id, container, json_tasks_filename, csv_tasks_filename, json_taskruns_filename, csv_taskruns_filename)
uploader.delete_file(json_tasks_filename, container)
uploader.delete_file(csv_tasks_filename, container)
uploader.delete_file(json_taskruns_filename, container)
Expand Down
2 changes: 2 additions & 0 deletions pybossa/uploader/cloud_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def _upload_file(self, file, container): # pragma: no cover

def delete_file(self, name, container): # pragma: no cover
try:
from flask import current_app
key = self.key_name(container, name)
current_app.logger.info("delete_file cloud_store delete. container %s, name %s, key %s", container, name, key)
self.bucket.delete_key(key)
return True
except Exception:
Expand Down
2 changes: 2 additions & 0 deletions pybossa/uploader/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def _upload_file(self, file, container):
def delete_file(self, filename, container):
"""Delete file from filesystem."""
try:
from flask import current_app
path = self.get_file_path(container, filename)
current_app.logger.info("delete_file local delete. container %s, filename %s, path %s", container, filename, path)
os.remove(path)
return True
except Exception:
Expand Down
3 changes: 2 additions & 1 deletion test/test_uploader/test_local_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import os
import tempfile
from test import Test
from test import Test, with_context
from pybossa.uploader.local import LocalUploader
from unittest.mock import patch
from werkzeug.datastructures import FileStorage
Expand Down Expand Up @@ -130,6 +130,7 @@ def test_local_folder_is_created(self, mock):
err_msg = "This local path should exist: %s" % path
assert os.path.isdir(path) is True, err_msg

@with_context
@patch('os.remove', return_value=None)
def test_local_folder_delete(self, mock):
"""Test LOCAL UPLOADER delete works."""
Expand Down

0 comments on commit 23912ab

Please sign in to comment.