Skip to content

Commit 79ce93f

Browse files
committed
backup: Clear the requested backup upon completion notification
Now the main go routine takes care of the backup synchronization.
1 parent 771aab2 commit 79ce93f

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

cmd/micro/micro.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ func DoEvent() {
489489
}
490490
case f := <-timerChan:
491491
f()
492+
case b := <-buffer.BackupCompleteChan:
493+
b.RequestedBackup = false
492494
case <-sighup:
493495
exit(0)
494496
case <-util.Sigterm:

internal/buffer/backup.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,20 @@ Options: [r]ecover, [i]gnore, [a]bort: `
3434

3535
const backupSeconds = 8
3636

37+
var BackupCompleteChan chan *Buffer
38+
39+
func init() {
40+
BackupCompleteChan = make(chan *Buffer, 10)
41+
}
42+
3743
func (b *Buffer) RequestBackup() {
38-
if !b.requestedBackup {
44+
if !b.RequestedBackup {
3945
select {
4046
case backupRequestChan <- b:
4147
default:
4248
// channel is full
4349
}
44-
b.requestedBackup = true
50+
b.RequestedBackup = true
4551
}
4652
}
4753

@@ -72,7 +78,7 @@ func (b *Buffer) Backup() error {
7278
if _, err := os.Stat(name); errors.Is(err, fs.ErrNotExist) {
7379
_, err = b.overwriteFile(name)
7480
if err == nil {
75-
b.requestedBackup = false
81+
BackupCompleteChan <- b
7682
}
7783
return err
7884
}
@@ -89,7 +95,7 @@ func (b *Buffer) Backup() error {
8995
return err
9096
}
9197

92-
b.requestedBackup = false
98+
BackupCompleteChan <- b
9399

94100
return err
95101
}

internal/buffer/buffer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ type SharedBuffer struct {
9999
diffLock sync.RWMutex
100100
diff map[int]DiffStatus
101101

102-
requestedBackup bool
102+
RequestedBackup bool
103103
forceKeepBackup bool
104104

105105
// ReloadDisabled allows the user to disable reloads if they

0 commit comments

Comments
 (0)