forge
Explore
Log in

Don't you dare go Hollow

writer: append to song_detail_last instead of in-place rewrite

Browse files at this commit

6d78fe1f44c13cfd51c2e757fc688b6b1cdf63c5Ahmet Kaan GümüşParent: 2c50a6c
tail -F is offset-based: an in-place rewrite with same byte length
(icon flip, position tick) leaves offset == size, so tail emits
nothing and waybar shows a stale line until a longer line happens.
Append-only keeps the inode and delivers every state change; trim
to the last line at startup once the log passes 1 MiB.
.config/scripts/shared/song_detail_writer.shmodified+10 -2
@@ -46,9 +46,12 @@ atomic_write() {
46 printf '%s\n' "$content" > "$tmp" && mv -f "$tmp" "$target"46 printf '%s\n' "$content" > "$tmp" && mv -f "$tmp" "$target"
47 }47 }
48 48
49-# Same inode so `tail -F` does not observe a replace/unlink.49+# Append-only stream. tail -F is offset-based: an in-place rewrite whose new
50+# content is the SAME BYTE LENGTH as the old (icon flip, position tick) is
51+# invisible to it — the bar goes stale until some longer line happens by.
52+# Appending keeps the inode put and delivers every state change.
50 write_output() {53 write_output() {
51- printf '%s\n' "$1" > "$OUTPUT_FILE"54+ printf '%s\n' "$1" >> "$OUTPUT_FILE"
52 }55 }
53 56
54 last_emit="__init__"57 last_emit="__init__"
@@ -81,6 +84,11 @@ pango_escape() {
81 # File must exist so `tail -F` can attach; do not wipe a live line.84 # File must exist so `tail -F` can attach; do not wipe a live line.
82 [[ -e "$OUTPUT_FILE" ]] || : > "$OUTPUT_FILE"85 [[ -e "$OUTPUT_FILE" ]] || : > "$OUTPUT_FILE"
83 86
87+# Append-mode log grows with every emitted line; keep only the newest once large.
88+if [[ -f "$OUTPUT_FILE" ]] && (( $(stat -c %s "$OUTPUT_FILE" 2>/dev/null || echo 0) > 1048576 )); then
89+ tail -n 1 "$OUTPUT_FILE" > "$OUTPUT_FILE.trim" && mv -f "$OUTPUT_FILE.trim" "$OUTPUT_FILE"
90+fi
91+
84 while true; do92 while true; do
85 if ! command -v playerctl &>/dev/null; then93 if ! command -v playerctl &>/dev/null; then
86 emit ""94 emit ""