Skip to content

Commit

Permalink
rename, add safeguard not to delete files outside of workdir
Browse files Browse the repository at this point in the history
  • Loading branch information
junjun-zhang committed Mar 6, 2020
1 parent c518879 commit b45093d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions process/cleanup.nf → process/cleanup-workdir.nf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ params.files_to_delete = 'NO_FILE'
params.container_version = '18.04'


process cleanup {
process cleanupWorkdir {
cpus params.cpus
memory "${params.mem} GB"

Expand All @@ -22,7 +22,16 @@ process cleanup {
IFS=" "
read -a files <<< "${files_to_delete}"
for f in "\${files[@]}"
do rm -fr \$(dirname \$(readlink -f \$f))/* # delete all files and subdirs but not hidden ones
do
dir_to_rm=\$(dirname \$(readlink -f \$f))
if [[ \$dir_to_rm != ${workflow.workDir}/* ]]; then # skip dir not under workdir, like from input file dir
echo "Not delete: \$dir_to_rm/*\"
continue
fi
rm -fr \$dir_to_rm/* # delete all files and subdirs but not hidden ones
echo "Deleted: \$dir_to_rm/*"
done
"""
}

0 comments on commit b45093d

Please sign in to comment.