Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions qiita_client/qiita_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,10 +897,13 @@ def push_file_to_central(self, filepath):
def delete_file_from_central(self, filepath):
"""Deletes a file in Qiita's central BASE_DATA_DIR directory.

I currently (2025-09-25) assess this operation to be too dangerous for
I currently (2025-11-12) assess this operation to be too dangerous for
protocols other than "filesystem", i.e. on "https" the files are NOT
deleted.
However, this might change in the future and since I don't want to
However, in plugin tests, this function is needed and I therefore
implemented an API endpoint which is only activated when Qiita main
instance is operated in test mode.
This might change in the future and since I don't want to
touch every plugin's code again, I am adding this function here already
and use it in according plugin code locations, e.g. function _gzip_file
in qtp-sequencing.
Expand All @@ -916,8 +919,15 @@ def delete_file_from_central(self, filepath):
The given filepath - to be transparent in plugin code.
"""
if self._plugincoupling == 'filesystem':
os.remove(filepath)
if os.path.isdir(filepath):
shutil.rmtree(filepath)
else:
os.remove(filepath)
elif self._plugincoupling == 'https':
pass
# will return in internal server error, when qiita is in productive
# mode
self.get(
'/cloud/delete_file_from_central/' + filepath,
rettype='object')

return filepath
18 changes: 4 additions & 14 deletions qiita_client/tests/test_qiita_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,20 +511,10 @@ def test_delete_file_from_central(self):

# delete file and test if it is gone
fp_deleted = self.qclient.delete_file_from_central(fp_test)
if protocol == 'filesystem':
# all three fp should point to the same filepath
self.assertFalse(exists(fp_obs))
self.assertFalse(exists(fp_test))
self.assertFalse(exists(fp_deleted))
elif protocol == 'https':
# as of 2025-09-26, I don't allow deletion of qiita main files
# through API endpoints. Thus, the file is NOT deleted!
# local version of the file
self.assertTrue(exists(fp_test))
# qiita main filepath
self.assertTrue(exists(fp_obs))
# qiita main filepath, returned by delete_file_from_central
self.assertTrue(exists(fp_deleted))
# all three fp should point to the same filepath
self.assertFalse(exists(fp_obs))
self.assertFalse(exists(fp_test))
self.assertFalse(exists(fp_deleted))

def test_fetch_directory(self):
# a bit hacky, but should work as long as test database does not change
Expand Down
Loading