mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-10 15:20:56 +00:00
Makes the logic a bit clearer and safer. This also sneakily redefines the 0 interval to also mean disabled, whereas it previously meant ... sometimes default to 1s, sometimes just spin.
This commit is contained in:
parent
ddd26f5c42
commit
d62a0cf692
@ -197,27 +197,30 @@ func (t *ProgressEmitter) VerifyConfiguration(from, to config.Configuration) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CommitConfiguration implements the config.Committer interface
|
// CommitConfiguration implements the config.Committer interface
|
||||||
func (t *ProgressEmitter) CommitConfiguration(from, to config.Configuration) bool {
|
func (t *ProgressEmitter) CommitConfiguration(_, to config.Configuration) bool {
|
||||||
t.mut.Lock()
|
t.mut.Lock()
|
||||||
defer t.mut.Unlock()
|
defer t.mut.Unlock()
|
||||||
|
|
||||||
switch {
|
newInterval := time.Duration(to.Options.ProgressUpdateIntervalS) * time.Second
|
||||||
case t.disabled && to.Options.ProgressUpdateIntervalS >= 0:
|
if newInterval > 0 {
|
||||||
|
if t.disabled {
|
||||||
t.disabled = false
|
t.disabled = false
|
||||||
l.Debugln("progress emitter: enabled")
|
l.Debugln("progress emitter: enabled")
|
||||||
fallthrough
|
|
||||||
case !t.disabled && from.Options.ProgressUpdateIntervalS != to.Options.ProgressUpdateIntervalS:
|
|
||||||
t.interval = time.Duration(to.Options.ProgressUpdateIntervalS) * time.Second
|
|
||||||
if t.interval < time.Second {
|
|
||||||
t.interval = time.Second
|
|
||||||
}
|
}
|
||||||
|
if t.interval != newInterval {
|
||||||
|
t.interval = newInterval
|
||||||
l.Debugln("progress emitter: updated interval", t.interval)
|
l.Debugln("progress emitter: updated interval", t.interval)
|
||||||
case !t.disabled && to.Options.ProgressUpdateIntervalS < 0:
|
}
|
||||||
|
} else if !t.disabled {
|
||||||
t.clearLocked()
|
t.clearLocked()
|
||||||
t.disabled = true
|
t.disabled = true
|
||||||
l.Debugln("progress emitter: disabled")
|
l.Debugln("progress emitter: disabled")
|
||||||
}
|
}
|
||||||
t.minBlocks = to.Options.TempIndexMinBlocks
|
t.minBlocks = to.Options.TempIndexMinBlocks
|
||||||
|
if t.interval < time.Second {
|
||||||
|
// can't happen when we're not disabled, but better safe than sorry.
|
||||||
|
t.interval = time.Second
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ func TestProgressEmitter(t *testing.T) {
|
|||||||
c := createTmpWrapper(config.Configuration{})
|
c := createTmpWrapper(config.Configuration{})
|
||||||
defer os.Remove(c.ConfigPath())
|
defer os.Remove(c.ConfigPath())
|
||||||
c.SetOptions(config.OptionsConfiguration{
|
c.SetOptions(config.OptionsConfiguration{
|
||||||
ProgressUpdateIntervalS: 0,
|
ProgressUpdateIntervalS: 60, // irrelevant, but must be positive
|
||||||
})
|
})
|
||||||
|
|
||||||
p := NewProgressEmitter(c, evLogger)
|
p := NewProgressEmitter(c, evLogger)
|
||||||
@ -112,7 +112,7 @@ func TestSendDownloadProgressMessages(t *testing.T) {
|
|||||||
c := createTmpWrapper(config.Configuration{})
|
c := createTmpWrapper(config.Configuration{})
|
||||||
defer os.Remove(c.ConfigPath())
|
defer os.Remove(c.ConfigPath())
|
||||||
c.SetOptions(config.OptionsConfiguration{
|
c.SetOptions(config.OptionsConfiguration{
|
||||||
ProgressUpdateIntervalS: 0,
|
ProgressUpdateIntervalS: 60, // irrelevant, but must be positive
|
||||||
TempIndexMinBlocks: 10,
|
TempIndexMinBlocks: 10,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user