lib/model: Allow limiting number of concurrent scans (fixes #2760) (#4888)

This commit is contained in:
Audrius Butkevicius
2018-12-05 07:40:05 +00:00
committed by Jakob Borg
parent 0fe4c01a28
commit ff2cde469e
8 changed files with 154 additions and 6 deletions

View File

@@ -28,6 +28,9 @@ import (
"github.com/syncthing/syncthing/lib/watchaggregator"
)
// scanLimiter limits the number of concurrent scans. A limit of zero means no limit.
var scanLimiter = newByteSemaphore(0)
var errWatchNotStarted = errors.New("not started")
type folder struct {
@@ -284,6 +287,10 @@ func (f *folder) scanSubdirs(subDirs []string) error {
f.model.fmut.RUnlock()
mtimefs := fset.MtimeFS()
f.setState(FolderScanWaiting)
scanLimiter.take(1)
defer scanLimiter.give(1)
for i := range subDirs {
sub := osutil.NativeFilename(subDirs[i])