From 6ec4771cdca0a059923f9a0d97ff3fe6198fe6b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Sat, 12 Oct 2024 16:35:47 +0200 Subject: [PATCH] backup: Clear the requested backup upon completion notification Now the main go routine takes care of the backup synchronization. --- cmd/micro/micro.go | 2 ++ internal/buffer/backup.go | 14 ++++++++++---- internal/buffer/buffer.go | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index a5a03d297..735030303 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -489,6 +489,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 2a2b62ea3..1241bf4f9 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, 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