fix: a transcript rescue never replaces an earlier one

The destination name has one-second granularity and mv overwrites.
Closing, re-hosting and closing the same party name within a second
would lose the first transcript while reporting success. Fall back to
a PID-suffixed name when the destination already exists.
This commit is contained in:
veg 2026-09-21 15:03:34 +00:00
parent 471ee5875c
commit 3fe5615ffe
2 changed files with 21 additions and 1 deletions

6
party
View file

@ -943,7 +943,11 @@ rescue_transcript() {
sleep 1 sleep 1
done done
fi fi
_rt_dest="$HOME/party-$_rt_name-$(date -u '+%Y%m%d-%H%M%S').log" _rt_dest="$HOME/party-$_rt_name-$(date -u '+%Y%m%d-%H%M%S')"
# Same name rescued twice within a second (close, re-host, close):
# mv would replace the earlier transcript without a word.
[ ! -e "$_rt_dest.log" ] || _rt_dest="$_rt_dest-$$"
_rt_dest="$_rt_dest.log"
mv "$_rt_dir/log" "$_rt_dest" 2>/dev/null || { _rt_dest=''; return 1; } mv "$_rt_dir/log" "$_rt_dest" 2>/dev/null || { _rt_dest=''; return 1; }
return 0 return 0
} }

View file

@ -34,6 +34,22 @@ teardown() { teardown_party_sandbox; }
grep -q "the night" "$HOME"/party-crashed-*.log grep -q "the night" "$HOME"/party-crashed-*.log
} }
@test "a rescue never replaces an earlier transcript of the same second" {
export HOME="$PARTY_TMP/home"
mkdir -p "$HOME" "$PARTY_TMP/bin"
# Freeze the clock so both rescues compute the same destination.
printf '#!/bin/sh\necho 20260101-000000\n' > "$PARTY_TMP/bin/date"
chmod +x "$PARTY_TMP/bin/date"
printf 'earlier\n' > "$HOME/party-crashed-20260101-000000.log"
ensure_party_dir "$USER" crashed
printf 'later\n' > "$PARTY_SOCKET_DIR/party-$USER:crashed.d/log"
PATH="$PARTY_TMP/bin:$PATH" run "$PARTY_BIN" clean
[ "$status" -eq 0 ]
grep -q earlier "$HOME/party-crashed-20260101-000000.log"
grep -lq later "$HOME"/party-crashed-20260101-000000-*.log
}
@test "clean removes a crash-before-bind dir (no sock at all)" { @test "clean removes a crash-before-bind dir (no sock at all)" {
mkdir "$PARTY_SOCKET_DIR/party-$USER:stillborn.d" mkdir "$PARTY_SOCKET_DIR/party-$USER:stillborn.d"
run "$PARTY_BIN" clean run "$PARTY_BIN" clean