Truncate file when directly sharing
All checks were successful
continuous-integration/drone/push Build is passing

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.
This commit is contained in:
Harvey Tindall 2021-10-29 15:07:56 +01:00
parent c26c13e984
commit 4b71fa248a
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2

View File

@ -540,12 +540,17 @@ 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.
err = w.file.Truncate(int64(n))
if err != nil {
return 0, err
}
offset, err := w.file.Seek(0, 0)
if err != nil {
return 0, err
}
_, err = w.file.WriteAt(p, offset)
n = len(p)
return
}