lib/db, lib/model: Resolve identical recv only items (fixes #5130) (#5230)

This commit is contained in:
Simon Frei
2018-10-10 12:43:07 +02:00
committed by Jakob Borg
parent caa2356409
commit d10773c311
5 changed files with 173 additions and 14 deletions

View File

@@ -2058,14 +2058,38 @@ func (m *Model) internalScanFolderSubdirs(ctx context.Context, folder string, su
return err
}
batch := newFileInfoBatch(func(fs []protocol.FileInfo) error {
batchFn := func(fs []protocol.FileInfo) error {
if err := runner.CheckHealth(); err != nil {
l.Debugf("Stopping scan of folder %s due to: %s", folderCfg.Description(), err)
return err
}
m.updateLocalsFromScanning(folder, fs)
return nil
})
}
// Resolve items which are identical with the global state.
if localFlags&protocol.FlagLocalReceiveOnly != 0 {
oldBatchFn := batchFn // can't reference batchFn directly (recursion)
batchFn = func(fs []protocol.FileInfo) error {
for i := range fs {
switch gf, ok := fset.GetGlobal(fs[i].Name); {
case !ok:
continue
case gf.IsEquivalentOptional(fs[i], false, false, protocol.FlagLocalReceiveOnly):
// What we have locally is equivalent to the global file.
fs[i].Version = fs[i].Version.Merge(gf.Version)
fallthrough
case fs[i].IsDeleted() && gf.IsReceiveOnlyChanged():
// Our item is deleted and the global item is our own
// receive only file. We can't delete file infos, so
// we just pretend it is a normal deleted file (nobody
// cares about that).
fs[i].LocalFlags &^= protocol.FlagLocalReceiveOnly
}
}
return oldBatchFn(fs)
}
}
batch := newFileInfoBatch(batchFn)
// Schedule a pull after scanning, but only if we actually detected any
// changes.