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:
|
case f := <-timerChan:
|
||||||
f()
|
f()
|
||||||
|
case b := <-buffer.BackupCompleteChan:
|
||||||
|
b.RequestedBackup = false
|
||||||
case <-sighup:
|
case <-sighup:
|
||||||
exit(0)
|
exit(0)
|
||||||
case <-util.Sigterm:
|
case <-util.Sigterm:
|
||||||
|
@ -34,14 +34,20 @@ Options: [r]ecover, [i]gnore, [a]bort: `
|
|||||||
|
|
||||||
const backupSeconds = 8
|
const backupSeconds = 8
|
||||||
|
|
||||||
|
var BackupCompleteChan chan *Buffer
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
BackupCompleteChan = make(chan *Buffer, 10)
|
||||||
|
}
|
||||||
|
|
||||||
func (b *Buffer) RequestBackup() {
|
func (b *Buffer) RequestBackup() {
|
||||||
if !b.requestedBackup {
|
if !b.RequestedBackup {
|
||||||
select {
|
select {
|
||||||
case backupRequestChan <- b:
|
case backupRequestChan <- b:
|
||||||
default:
|
default:
|
||||||
// channel is full
|
// 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) {
|
if _, err := os.Stat(name); errors.Is(err, fs.ErrNotExist) {
|
||||||
_, err = b.overwriteFile(name)
|
_, err = b.overwriteFile(name)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
b.requestedBackup = false
|
BackupCompleteChan <- b
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -89,7 +95,7 @@ func (b *Buffer) Backup() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
b.requestedBackup = false
|
BackupCompleteChan <- b
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ type SharedBuffer struct {
|
|||||||
diffLock sync.RWMutex
|
diffLock sync.RWMutex
|
||||||
diff map[int]DiffStatus
|
diff map[int]DiffStatus
|
||||||
|
|
||||||
requestedBackup bool
|
RequestedBackup bool
|
||||||
forceKeepBackup bool
|
forceKeepBackup bool
|
||||||
|
|
||||||
// ReloadDisabled allows the user to disable reloads if they
|
// ReloadDisabled allows the user to disable reloads if they
|
||||||
|
Loading…
Reference in New Issue
Block a user