Skip to content

Commit 5925929

Browse files
committed
Stop the browser policy EXIT trap from reporting a clean run as failed
1 parent 7d58bb9 commit 5925929

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

bin/omarchy-theme-set-browser-policy

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,13 @@ require_root "$color"
7676

7777
failed=0
7878
staged=""
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.
7982
cleanup() {
80-
[[ -n $staged ]] && rm -f "$staged"
83+
if [[ -n $staged ]]; then
84+
rm -f "$staged"
85+
fi
8186
}
8287
trap cleanup EXIT
8388

test/shell.d/browser-policy-dir-test.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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"
280280
pass "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+
282297
policy_files=(
283298
"$ROOT/bin/omarchy-install-browser"
284299
"$ROOT/bin/omarchy-provision-owner"

0 commit comments

Comments
 (0)