Skip to content

Commit

Permalink
fix buffer write
Browse files Browse the repository at this point in the history
  • Loading branch information
Son Roy Almerol committed Dec 9, 2024
1 parent 9a973ed commit b4f1ef6
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions internal/backend/backup/jobrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,22 @@ func RunBackup(job *store.Job, storeInstance *store.Store, waitChan chan struct{

writer := bufio.NewWriter(f)
for {
line, err := buffer.ReadString('\n')
if err != nil {
continue
}

if strings.HasPrefix(line, "Error: upload failed:") {
clientErrChan <- strings.TrimSuffix(line, "\n")
}

select {
case <-logCtx.Done():
writer.Flush()
return
default:
_, _ = writer.WriteString(line + "\n")
bufferContent := buffer.String()

if strings.Contains(bufferContent, "upload failed:") {
clientErrChan <- strings.TrimSuffix(bufferContent, "\n")
}

if _, err := writer.WriteString(bufferContent); err != nil {
log.Println("Write error:", err)
return
}

buffer.Reset()
}
}
Expand Down

0 comments on commit b4f1ef6

Please sign in to comment.