writer: append to song_detail_last instead of in-place rewrite
Browse files at this commit6d78fe1f44c13cfd51c2e757fc688b6b1cdf63c5Parent: 2c50a6c1 changed file +10 -2
.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; do | 92 | while true; do |
| 85 | if ! command -v playerctl &>/dev/null; then | 93 | if ! command -v playerctl &>/dev/null; then |
| 86 | emit "" | 94 | emit "" |