Skip to content

Commit

Permalink
backup: Clear the requested backup upon completion notification
Browse files Browse the repository at this point in the history
Now the main go routine takes care of the backup synchronization.
  • Loading branch information
JoeKar committed Oct 31, 2024
1 parent cdc239b commit d34c62a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions cmd/micro/micro.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ func DoEvent() {
}
case f := <-timerChan:
f()
case b := <-buffer.BackupCompleteChan:
b.RequestedBackup = false
case <-sighup:
exit(0)
case <-util.Sigterm:
Expand Down
14 changes: 10 additions & 4 deletions internal/buffer/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@ Options: [r]ecover, [i]gnore, [a]bort: `

const backupSeconds = 8

var BackupCompleteChan chan *Buffer

func init() {
BackupCompleteChan = make(chan *Buffer, 10)
}

func (b *Buffer) RequestBackup() {
if !b.requestedBackup {
if !b.RequestedBackup {
select {
case backupRequestChan <- b:
default:
// channel is full
}
b.requestedBackup = true
b.RequestedBackup = true
}
}

Expand Down Expand Up @@ -72,7 +78,7 @@ func (b *Buffer) Backup() error {
if _, err := os.Stat(name); errors.Is(err, fs.ErrNotExist) {
err = b.overwriteFile(name, true, false)
if err == nil {
b.requestedBackup = false
BackupCompleteChan <- b
}
return err
}
Expand All @@ -89,7 +95,7 @@ func (b *Buffer) Backup() error {
return err
}

b.requestedBackup = false
BackupCompleteChan <- b

return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/buffer/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type SharedBuffer struct {
diffLock sync.RWMutex
diff map[int]DiffStatus

requestedBackup bool
RequestedBackup bool
forceKeepBackup bool

// ReloadDisabled allows the user to disable reloads if they
Expand Down

0 comments on commit d34c62a

Please sign in to comment.