Skip to content

Commit 2fe2843

Browse files
committed
fix(slurm): escape glob metacharacters in the mount prune patterns
find treats -path's argument as a glob, so a mount point containing *, ? or [ matched more than itself and pruned directories that were never mounted. Those directories were then skipped, leaving behind exactly the files the epilog is meant to remove. Checked against real find with a mount point named a*b next to axb and ayb: the unescaped pattern pruned all three and left 0 files, the escaped one pruned only a*b and left 2. Backslashes are doubled first so the escapes added afterwards are not doubled again. printf -v drops the command substitution as well, so the value no longer loses trailing newlines to $( ). Both changes are dholt's review suggestions on #1408.
1 parent 031fce1 commit 2fe2843

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎roles/slurm/templates/etc/slurm/epilog.d/42-lastuserjob-cleanup‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,15 @@ if [[ -n "$SLURM_JOB_USER" && "$SLURM_JOB_USER" != "root" ]]; then
9191
mounts=()
9292
prune=()
9393
while IFS= read -r field; do
94-
mount_point=$(printf '%b' "$field")
94+
printf -v mount_point '%b' "$field"
9595
case "$mount_point" in
9696
"$dir"/*)
9797
mounts+=( "$mount_point" )
98-
prune+=( -path "$mount_point" -prune -o )
98+
pattern=${mount_point//\\/\\\\}
99+
pattern=${pattern//\*/\\*}
100+
pattern=${pattern//\?/\\?}
101+
pattern=${pattern//\[/\\[}
102+
prune+=( -path "$pattern" -prune -o )
99103
;;
100104
esac
101105
done <"$mountlist"

0 commit comments

Comments
 (0)