lib/model: Don't pull if ignores failed to load and cleanup (#5418)

This commit is contained in:
Simon Frei 2019-01-01 10:17:14 +01:00 committed by Jakob Borg
parent 48dab8f201
commit 47e08797cb
3 changed files with 26 additions and 20 deletions

View File

@ -197,7 +197,7 @@ func (f *folder) DelayScan(next time.Duration) {
f.Delay(next) f.Delay(next)
} }
func (f *folder) IgnoresUpdated() { func (f *folder) ignoresUpdated() {
if f.FSWatcherEnabled { if f.FSWatcherEnabled {
f.scheduleWatchRestart() f.scheduleWatchRestart()
} }
@ -310,8 +310,9 @@ func (f *folder) scanSubdirs(subDirs []string) error {
oldHash := ignores.Hash() oldHash := ignores.Hash()
defer func() { defer func() {
if ignores.Hash() != oldHash { if ignores.Hash() != oldHash {
l.Debugln("Folder", f.ID, "ignore patterns changed; triggering puller") l.Debugln("Folder", f.Description(), "ignore patterns change detected while scanning; triggering puller")
f.IgnoresUpdated() f.ignoresUpdated()
f.SchedulePull()
} }
}() }()

View File

@ -95,9 +95,8 @@ type dbUpdateJob struct {
type sendReceiveFolder struct { type sendReceiveFolder struct {
folder folder
prevIgnoreHash string fs fs.Filesystem
fs fs.Filesystem versioner versioner.Versioner
versioner versioner.Versioner
queue *jobQueue queue *jobQueue
@ -132,6 +131,8 @@ func newSendReceiveFolder(model *Model, cfg config.FolderConfiguration, ver vers
return f return f
} }
// pull returns true if it manages to get all needed items from peers, i.e. get
// the device in sync with the global state.
func (f *sendReceiveFolder) pull() bool { func (f *sendReceiveFolder) pull() bool {
select { select {
case <-f.initialScanFinished: case <-f.initialScanFinished:
@ -141,7 +142,7 @@ func (f *sendReceiveFolder) pull() bool {
} }
f.model.fmut.RLock() f.model.fmut.RLock()
curIgnores := f.model.folderIgnores[f.folderID] ignores := f.model.folderIgnores[f.folderID]
folderFiles := f.model.folderFiles[f.folderID] folderFiles := f.model.folderFiles[f.folderID]
f.model.fmut.RUnlock() f.model.fmut.RUnlock()
@ -157,13 +158,23 @@ func (f *sendReceiveFolder) pull() bool {
if err := f.CheckHealth(); err != nil { if err := f.CheckHealth(); err != nil {
l.Debugln("Skipping pull of", f.Description(), "due to folder error:", err) l.Debugln("Skipping pull of", f.Description(), "due to folder error:", err)
return true return false
} }
curIgnoreHash := curIgnores.Hash() // Check if the ignore patterns changed.
ignoresChanged := curIgnoreHash != f.prevIgnoreHash oldHash := ignores.Hash()
defer func() {
if ignores.Hash() != oldHash {
f.ignoresUpdated()
}
}()
if err := ignores.Load(".stignore"); err != nil && !fs.IsNotExist(err) {
err = fmt.Errorf("loading ignores: %v", err)
f.setError(err)
return false
}
l.Debugf("%v pulling (ignoresChanged=%v)", f, ignoresChanged) l.Debugf("%v pulling", f)
f.setState(FolderSyncing) f.setState(FolderSyncing)
f.clearPullErrors() f.clearPullErrors()
@ -182,7 +193,7 @@ func (f *sendReceiveFolder) pull() bool {
for { for {
tries++ tries++
changed = f.pullerIteration(curIgnores, folderFiles, ignoresChanged, scanChan) changed = f.pullerIteration(ignores, folderFiles, scanChan)
select { select {
case <-f.ctx.Done(): case <-f.ctx.Done():
@ -213,19 +224,14 @@ func (f *sendReceiveFolder) pull() bool {
} }
} }
if changed == 0 { return changed == 0
f.prevIgnoreHash = curIgnoreHash
return true
}
return false
} }
// pullerIteration runs a single puller iteration for the given folder and // pullerIteration runs a single puller iteration for the given folder and
// returns the number items that should have been synced (even those that // returns the number items that should have been synced (even those that
// might have failed). One puller iteration handles all files currently // might have failed). One puller iteration handles all files currently
// flagged as needed in the folder. // flagged as needed in the folder.
func (f *sendReceiveFolder) pullerIteration(ignores *ignore.Matcher, folderFiles *db.FileSet, ignoresChanged bool, scanChan chan<- string) int { func (f *sendReceiveFolder) pullerIteration(ignores *ignore.Matcher, folderFiles *db.FileSet, scanChan chan<- string) int {
pullChan := make(chan pullBlockState) pullChan := make(chan pullBlockState)
copyChan := make(chan copyBlocksState) copyChan := make(chan copyBlocksState)
finisherChan := make(chan *sharedPullerState) finisherChan := make(chan *sharedPullerState)

View File

@ -58,7 +58,6 @@ type service interface {
Override(*db.FileSet, func([]protocol.FileInfo)) Override(*db.FileSet, func([]protocol.FileInfo))
Revert(*db.FileSet, func([]protocol.FileInfo)) Revert(*db.FileSet, func([]protocol.FileInfo))
DelayScan(d time.Duration) DelayScan(d time.Duration)
IgnoresUpdated() // ignore matcher was updated notification
SchedulePull() // something relevant changed, we should try a pull SchedulePull() // something relevant changed, we should try a pull
Jobs() ([]string, []string) // In progress, Queued Jobs() ([]string, []string) // In progress, Queued
Scan(subs []string) error Scan(subs []string) error