diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index 93fd2c649..394913004 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -491,6 +491,8 @@ func DoEvent() { } case f := <-timerChan: f() + case b := <-buffer.BackupCompleteChan: + b.RequestedBackup = false case <-sighup: exit(0) case <-util.Sigterm: diff --git a/internal/buffer/backup.go b/internal/buffer/backup.go index 2feff21fb..d8545d329 100644 --- a/internal/buffer/backup.go +++ b/internal/buffer/backup.go @@ -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 } } @@ -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 } @@ -89,7 +95,7 @@ func (b *Buffer) Backup() error { return err } - b.requestedBackup = false + BackupCompleteChan <- b return err } diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index 34e2636a3..89f7c4812 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -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