aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarvey Tindall <hrfee@protonmail.ch>2021-10-29 15:07:56 +0100
committerHarvey Tindall <hrfee@protonmail.ch>2021-10-29 15:10:53 +0100
commit4b71fa248ad07e23a62d1d5811e163113e1baab1 (patch)
treece791022a267f9ae1dafe208a8da80e017dd95ab
parentc26c13e984b8835d216a83cef666d7da875cfb4e (diff)
downloadwaybar-mpris-4b71fa248ad07e23a62d1d5811e163113e1baab1.tar.gz
waybar-mpris-4b71fa248ad07e23a62d1d5811e163113e1baab1.zip
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.
-rw-r--r--main.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/main.go b/main.go
index 8e7768f..3d3fabb 100644
--- a/main.go
+++ b/main.go
@@ -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
}