File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -76,8 +76,13 @@ require_root "$color"
7676
7777failed=0
7878staged=" "
79+ # Bash 5.3 makes the EXIT trap's last command decide the script's exit status,
80+ # so this handler must not end on a false test. Every successful run clears
81+ # staged, and a trailing `[[ -n $staged ]] && ...` would report that as failure.
7982cleanup () {
80- [[ -n $staged ]] && rm -f " $staged "
83+ if [[ -n $staged ]]; then
84+ rm -f " $staged "
85+ fi
8186}
8287trap cleanup EXIT
8388
Original file line number Diff line number Diff line change @@ -279,6 +279,21 @@ grep -F 'exit "$failed"' "$ROOT/bin/omarchy-theme-set-browser" >/dev/null ||
279279 fail " omarchy-theme-set-browser exits non-zero when a policy write fails"
280280pass " omarchy-theme-set-browser exits non-zero when a policy write fails"
281281
282+ # Bash 5.3 adopts the EXIT trap's last status as the script's exit status, so a
283+ # handler ending on a false test turns a clean run into a failure and aborts the
284+ # migration that calls this through omarchy-theme-set-browser.
285+ policy_cleanup= $( sed -n ' /^cleanup() {/,/^}/p' " $ROOT /bin/omarchy-theme-set-browser-policy" )
286+ [[ -n $policy_cleanup ]] || fail " omarchy-theme-set-browser-policy defines an EXIT cleanup handler"
287+ eval " $policy_cleanup "
288+ staged= " "
289+ cleanup || fail " omarchy-theme-set-browser-policy's EXIT trap succeeds with nothing staged"
290+ staged= $test_tmp /staged-policy
291+ : > " $staged "
292+ cleanup || fail " omarchy-theme-set-browser-policy's EXIT trap succeeds with a staged file"
293+ [[ ! -e $staged ]] || fail " omarchy-theme-set-browser-policy's EXIT trap removes the staged file"
294+ unset -f cleanup
295+ pass " omarchy-theme-set-browser-policy's EXIT trap never leaks a failure status"
296+
282297policy_files= (
283298 " $ROOT /bin/omarchy-install-browser"
284299 " $ROOT /bin/omarchy-provision-owner"
You can’t perform that action at this time.
0 commit comments