From d38e5c9f3caa508fd25748d3757103bb376a543f Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Fri, 29 Oct 2021 15:07:56 +0100 Subject: [PATCH] Truncate file when directly sharing Fixes bug where recipient instance would have a bit of the previous track data on the end of the output if the previous track data was longer, which effectively froze the output on waybar as it was no longer valid JSON. --- main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 8e7768f..7f546c9 100644 --- a/main.go +++ b/main.go @@ -540,12 +540,14 @@ type emptyEveryWrite struct { } func (w emptyEveryWrite) Write(p []byte) (n int, err error) { + n = len(p) + // Set new size in case previous data was longer and would leave garbage at the end of the file. + w.file.Truncate(int64(n)) offset, err := w.file.Seek(0, 0) if err != nil { return 0, err } _, err = w.file.WriteAt(p, offset) - n = len(p) return }