lib/model: Deduplicate folder loops
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4352 LGTM: AudriusButkevicius, calmh
This commit is contained in:
parent
4d3e0de4ba
commit
f7d2c58783
@ -71,3 +71,20 @@ func (f *folder) scanSubdirs(subDirs []string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *folder) scanTimerFired() {
|
||||||
|
err := f.scanSubdirs(nil)
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-f.initialScanFinished:
|
||||||
|
default:
|
||||||
|
status := "Completed"
|
||||||
|
if err != nil {
|
||||||
|
status = "Failed"
|
||||||
|
}
|
||||||
|
l.Infoln(status, "initial scan of", f.Type.String(), "folder", f.Description())
|
||||||
|
close(f.initialScanFinished)
|
||||||
|
}
|
||||||
|
|
||||||
|
f.scan.Reschedule()
|
||||||
|
}
|
||||||
|
|||||||
@ -57,7 +57,3 @@ func (f *folderScanner) Scan(subdirs []string) error {
|
|||||||
func (f *folderScanner) Delay(next time.Duration) {
|
func (f *folderScanner) Delay(next time.Duration) {
|
||||||
f.delay <- next
|
f.delay <- next
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *folderScanner) HasNoInterval() bool {
|
|
||||||
return f.interval == 0
|
|
||||||
}
|
|
||||||
|
|||||||
@ -41,24 +41,7 @@ func (f *sendOnlyFolder) Serve() {
|
|||||||
|
|
||||||
case <-f.scan.timer.C:
|
case <-f.scan.timer.C:
|
||||||
l.Debugln(f, "Scanning subdirectories")
|
l.Debugln(f, "Scanning subdirectories")
|
||||||
err := f.scanSubdirs(nil)
|
f.scanTimerFired()
|
||||||
|
|
||||||
select {
|
|
||||||
case <-f.initialScanFinished:
|
|
||||||
default:
|
|
||||||
status := "Completed"
|
|
||||||
if err != nil {
|
|
||||||
status = "Failed"
|
|
||||||
}
|
|
||||||
l.Infoln(status, "initial scan (ro) of", f.Description())
|
|
||||||
close(f.initialScanFinished)
|
|
||||||
}
|
|
||||||
|
|
||||||
if f.scan.HasNoInterval() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
f.scan.Reschedule()
|
|
||||||
|
|
||||||
case req := <-f.scan.now:
|
case req := <-f.scan.now:
|
||||||
req.err <- f.scanSubdirs(req.subdirs)
|
req.err <- f.scanSubdirs(req.subdirs)
|
||||||
|
|||||||
@ -268,18 +268,7 @@ func (f *sendReceiveFolder) Serve() {
|
|||||||
// same time.
|
// same time.
|
||||||
case <-f.scan.timer.C:
|
case <-f.scan.timer.C:
|
||||||
l.Debugln(f, "Scanning subdirectories")
|
l.Debugln(f, "Scanning subdirectories")
|
||||||
err := f.scanSubdirs(nil)
|
f.scanTimerFired()
|
||||||
f.scan.Reschedule()
|
|
||||||
select {
|
|
||||||
case <-f.initialScanFinished:
|
|
||||||
default:
|
|
||||||
close(f.initialScanFinished)
|
|
||||||
status := "Completed"
|
|
||||||
if err != nil {
|
|
||||||
status = "Failed"
|
|
||||||
}
|
|
||||||
l.Infoln(status, "initial scan (rw) of", f.Description())
|
|
||||||
}
|
|
||||||
|
|
||||||
case req := <-f.scan.now:
|
case req := <-f.scan.now:
|
||||||
req.err <- f.scanSubdirs(req.subdirs)
|
req.err <- f.scanSubdirs(req.subdirs)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user