summary refs log tree commit diff
path: root/pkgs/build-support/fetchcvs
diff options
context:
space:
mode:
authorErik Arvstedt <erik.arvstedt@gmail.com>2022-07-02 12:51:12 +0200
committerErik Arvstedt <erik.arvstedt@gmail.com>2022-07-02 16:13:12 +0200
commit3f54dfa4755613dbd3098814a9ab07cb977ca347 (patch)
treede3dc05086dc36c9c190403ae7e817f105914d65 /pkgs/build-support/fetchcvs
parentbb7867f1e5080de1dfff80e2f7d5a4be49889e23 (diff)
downloadnixpkgs-3f54dfa4755613dbd3098814a9ab07cb977ca347.tar
nixpkgs-3f54dfa4755613dbd3098814a9ab07cb977ca347.tar.gz
nixpkgs-3f54dfa4755613dbd3098814a9ab07cb977ca347.tar.bz2
nixpkgs-3f54dfa4755613dbd3098814a9ab07cb977ca347.tar.lz
nixpkgs-3f54dfa4755613dbd3098814a9ab07cb977ca347.tar.xz
nixpkgs-3f54dfa4755613dbd3098814a9ab07cb977ca347.tar.zst
nixpkgs-3f54dfa4755613dbd3098814a9ab07cb977ca347.zip
treewide: fix bash exit handlers
Transform exit handlers of the form
trap cleanup EXIT [INT] [TERM] [QUIT] [HUP] [ERR]
  (where cleanup is idempotent)
to
trap cleanup EXIT

This fixes a common bash antipattern.

Each of the above signals causes the script to exit. For each signal,
bash first handles the signal by running `cleanup` and then runs
`cleanup` again when handling EXIT.
(Exception:  `vscode/*` prevents the second run of `cleanup` by removing
the trap in cleanup`).

Simplify the cleanup logic by just trapping exit, which is always run
when the script exits due to any of the above signals.

Note: In case of borgbackup, the exit handler is not idempotent, but just
trapping EXIT guarantees that it's only run once.
Diffstat (limited to 'pkgs/build-support/fetchcvs')
-rwxr-xr-xpkgs/build-support/fetchcvs/nix-prefetch-cvs6
1 files changed, 2 insertions, 4 deletions
diff --git a/pkgs/build-support/fetchcvs/nix-prefetch-cvs b/pkgs/build-support/fetchcvs/nix-prefetch-cvs
index f9ed8ffa066..b6a169f8b53 100755
--- a/pkgs/build-support/fetchcvs/nix-prefetch-cvs
+++ b/pkgs/build-support/fetchcvs/nix-prefetch-cvs
@@ -21,13 +21,11 @@ fi
 
 mkTempDir() {
     tmpPath="$(mktemp -d "${TMPDIR:-/tmp}/nix-prefetch-cvs-XXXXXXXX")"
-    trap removeTempDir EXIT SIGINT SIGQUIT
+    trap removeTempDir EXIT
 }
 
 removeTempDir() {
-    if test -n "$tmpPath"; then
-        rm -rf "$tmpPath" || true
-    fi
+    rm -rf "$tmpPath"
 }