From 3fe5615ffe423a4ae11314c67f67c9e9915b4e85 Mon Sep 17 00:00:00 2001 From: veg Date: Mon, 21 Sep 2026 15:03:34 +0000 Subject: [PATCH] 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. --- party | 6 +++++- tests/85-clean.bats | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/party b/party index 9a494d1..4e790ce 100755 --- a/party +++ b/party @@ -943,7 +943,11 @@ rescue_transcript() { sleep 1 done 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; } return 0 } diff --git a/tests/85-clean.bats b/tests/85-clean.bats index d326843..a474db4 100644 --- a/tests/85-clean.bats +++ b/tests/85-clean.bats @@ -34,6 +34,22 @@ teardown() { teardown_party_sandbox; } 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)" { mkdir "$PARTY_SOCKET_DIR/party-$USER:stillborn.d" run "$PARTY_BIN" clean