Skip to content

Fix #3222 #3241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Changes based on feedback
  • Loading branch information
charles-cowart committed Jan 29, 2023
commit ef6e36a6c8e720f7a8ae85d82e8e45a14654c799
7 changes: 1 addition & 6 deletions qiita_db/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,18 +618,13 @@ def delete(cls, artifact_id):
WHERE artifact_id IN %s"""
qdb.sql_connection.TRN.add(sql, [all_ids])

# do not move these files back to upload folder.
dnm = ['qtp-sequencing-validate-data.csv', 'feature-table.qza']

# If the first artifact to be deleted, instance, doesn't have
# parents and study is not None (None means is an analysis), we
# move the files to the uploads folder. We also need
# to nullify the column in the prep template table
if not instance.parents and study is not None:
qdb.util.move_filepaths_to_upload_folder(study.id,
filepaths,
do_not_move=dnm)

filepaths)
# there are cases that an artifact would not be linked to a
# study
pt_ids = [tuple([pt.id]) for a in all_artifacts
Expand Down
16 changes: 7 additions & 9 deletions qiita_db/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ def empty_trash_upload_folder(delete_files=True):
qdb.sql_connection.TRN.execute()


def move_filepaths_to_upload_folder(study_id, filepaths, do_not_move=None):
def move_filepaths_to_upload_folder(study_id, filepaths):
r"""Goes over the filepaths list and moves all the filepaths that are not
used in any place to the upload folder of the study

Expand All @@ -950,8 +950,6 @@ def move_filepaths_to_upload_folder(study_id, filepaths, do_not_move=None):
The study id to where the files should be returned to
filepaths : list
List of filepaths to move to the upload folder
do_not_move : list
List of filenames to delete rather than move to upload folder
"""
with qdb.sql_connection.TRN:
uploads_fp = join(get_mountpoint("uploads")[0][1], str(study_id))
Expand All @@ -960,20 +958,20 @@ def move_filepaths_to_upload_folder(study_id, filepaths, do_not_move=None):

path_builder = partial(join, uploads_fp)

# do not move these files back to upload folder.
do_not_move = ['qtp-sequencing-validate-data.csv', 'feature-table.qza']

# We can now go over and remove all the filepaths
sql = """DELETE FROM qiita.filepath WHERE filepath_id = %s"""
for x in filepaths:
qdb.sql_connection.TRN.add(sql, [x['fp_id']])

if x['fp_type'] in ('html_summary', 'html_summary_dir'):
if (x['fp_type'] in ('html_summary',
'html_summary_dir') or
basename(x['fp']) in do_not_move):
_rm_files(qdb.sql_connection.TRN, x['fp'])
continue

if do_not_move:
if basename(x['fp']) in do_not_move:
_rm_files(qdb.sql_connection.TRN, x['fp'])
continue

# if files were not removed, then they should be moved.
destination = path_builder(basename(x['fp']))
qdb.sql_connection.TRN.add_post_rollback_func(move,
Expand Down