aboutsummaryrefslogtreecommitdiff
path: root/tests/normalize-notify/fake-ffmpeg
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-20 15:56:26 -0500
committerCraig Jennings <c@cjennings.net>2026-07-20 15:56:26 -0500
commitb74875295f7ae31e565879e8e83cbe77597813cc (patch)
tree72fb0a30c5c9207ebfc395b7886c223e0038da47 /tests/normalize-notify/fake-ffmpeg
parent86bf4d94333f582e10e5d129f578d29c871cbbd6 (diff)
downloadarchsetup-b74875295f7ae31e565879e8e83cbe77597813cc.tar.gz
archsetup-b74875295f7ae31e565879e8e83cbe77597813cc.zip
fix(sounds): make normalize-notify-sounds write atomically and clean up
The script re-encoded each notify sound with `cat "$tmp" > "$f"`, which truncates the target first -- a short or empty encode left a corrupt, repo-tracked sound file. The mktemp also had no trap, so an interrupted encode leaked a temp. Now it resolves the real target with `readlink -f` (SOUND_DIR is usually the stow-symlinked ~/.local copy), stages the temp beside it, guards on a non-empty encode, and moves it into place. The mv is atomic on one filesystem and replaces the real file, so the stow symlink still points at it. An EXIT trap removes the in-flight temp when a failed encode aborts the run.
Diffstat (limited to 'tests/normalize-notify/fake-ffmpeg')
-rw-r--r--tests/normalize-notify/fake-ffmpeg25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/normalize-notify/fake-ffmpeg b/tests/normalize-notify/fake-ffmpeg
new file mode 100644
index 0000000..cdfcb6f
--- /dev/null
+++ b/tests/normalize-notify/fake-ffmpeg
@@ -0,0 +1,25 @@
+#!/bin/bash
+# Fake ffmpeg for the normalize-notify-sounds tests. Two modes:
+# measure (args include the `volumedetect` filter): print a mean_volume line
+# to stderr, driven by FAKE_MEAN (default -20.0).
+# encode (otherwise): write to the output file (the last argument), driven
+# by FAKE_FFMPEG_EMPTY (1 -> zero-byte output) and FAKE_FFMPEG_FAIL
+# (1 -> exit non-zero without writing).
+set -uo pipefail
+
+for a in "$@"; do
+ if [ "$a" = "volumedetect" ]; then
+ echo "mean_volume: ${FAKE_MEAN:--20.0} dB" >&2
+ exit 0
+ fi
+done
+
+out="${*: -1}"
+if [ "${FAKE_FFMPEG_FAIL:-0}" = 1 ]; then
+ exit 1
+fi
+if [ "${FAKE_FFMPEG_EMPTY:-0}" = 1 ]; then
+ : > "$out"
+else
+ echo ENCODED > "$out"
+fi