mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-18 23:05:40 -04:00
backup: Clear the requested backup upon completion notification
Now the main go routine takes care of the backup synchronization.
This commit is contained in:
parent
771aab251c
commit
79ce93fb7d
@ -489,6 +489,8 @@ func DoEvent() {
|
||||
}
|
||||
case f := <-timerChan:
|
||||
f()
|
||||
case b := <-buffer.BackupCompleteChan:
|
||||
b.RequestedBackup = false
|
||||
case <-sighup:
|
||||
exit(0)
|
||||
case <-util.Sigterm:
|
||||
|
@ -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)
|
||||
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
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user