Skip to content

Commit

Permalink
Avoid using risky --force on rm
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-schulze-vireso committed Mar 6, 2022
1 parent 6d1fb88 commit 321fa70
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/temp.bash
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ temp_del() {

# Delete directory.
local result
result="$(rm -rf -- "$path" 2>&1)"
result="$(rm -r -- "$path" 2>&1 </dev/null)"

This comment has been minimized.

Copy link
@Vampire

Vampire Mar 7, 2022

I'm curious @martin-schulze-vireso. In what way is --force risky?
It should have the exact same effect than the redirect without the need for a redirect, shouldn't it?

This comment has been minimized.

Copy link
@martin-schulze-vireso

martin-schulze-vireso Mar 10, 2022

Author Member

Risky may have been the wrong word. I was alluding to subliminos comment about accidental rm -rf / and I noticed that there is was a test failure because rm -f swallowed the error exit code for rm -rf /does/not/exist. In the end, the main problem to me was that MacOS and Linux have different behavior. I wanted to avoid having code duplication for MacOS so I opted for the redirect, which should be a noop on Linux and achieves what we want on MacOS.

if (( $? )); then
echo "$result" \
| batslib_decorate 'ERROR: temp_del' \
Expand Down

0 comments on commit 321fa70

Please sign in to comment.