lib/model: Use right db snap when scanning recvonly folder (#6769)

This commit is contained in:
Simon Frei
2020-06-21 09:28:29 +02:00
committed by GitHub
parent 3fcf22ed5d
commit f66e57947b
+30 -29
View File
@@ -418,38 +418,39 @@ func (f *folder) scanSubdirs(subDirs []string) error {
EventLogger: f.evLogger, EventLogger: f.evLogger,
}) })
batchFn := func(fs []protocol.FileInfo) error { batch := newFileInfoBatch(func(fs []protocol.FileInfo) error {
if err := f.getHealthErrorWithoutIgnores(); err != nil { if err := f.getHealthErrorWithoutIgnores(); err != nil {
l.Debugf("Stopping scan of folder %s due to: %s", f.Description(), err) l.Debugf("Stopping scan of folder %s due to: %s", f.Description(), err)
return err return err
} }
f.updateLocalsFromScanning(fs) f.updateLocalsFromScanning(fs)
return nil return nil
} })
var batchAppend func(protocol.FileInfo, *db.Snapshot)
// Resolve items which are identical with the global state. // Resolve items which are identical with the global state.
if f.localFlags&protocol.FlagLocalReceiveOnly != 0 { if f.localFlags&protocol.FlagLocalReceiveOnly == 0 {
oldBatchFn := batchFn // can't reference batchFn directly (recursion) batchAppend = func(fi protocol.FileInfo, _ *db.Snapshot) {
batchFn = func(fs []protocol.FileInfo) error { batch.append(fi)
for i := range fs { }
switch gf, ok := snap.GetGlobal(fs[i].Name); { } else {
case !ok: batchAppend = func(fi protocol.FileInfo, snap *db.Snapshot) {
continue switch gf, ok := snap.GetGlobal(fi.Name); {
case gf.IsEquivalentOptional(fs[i], f.ModTimeWindow(), false, false, protocol.FlagLocalReceiveOnly): case !ok:
// What we have locally is equivalent to the global file. case gf.IsEquivalentOptional(fi, f.ModTimeWindow(), false, false, protocol.FlagLocalReceiveOnly):
fs[i].Version = fs[i].Version.Merge(gf.Version) // What we have locally is equivalent to the global file.
fallthrough fi.Version = fi.Version.Merge(gf.Version)
case fs[i].IsDeleted() && gf.IsReceiveOnlyChanged(): fallthrough
// Our item is deleted and the global item is our own case fi.IsDeleted() && gf.IsReceiveOnlyChanged():
// receive only file. We can't delete file infos, so // Our item is deleted and the global item is our own
// we just pretend it is a normal deleted file (nobody // receive only file. We can't delete file infos, so
// cares about that). // we just pretend it is a normal deleted file (nobody
fs[i].LocalFlags &^= protocol.FlagLocalReceiveOnly // cares about that).
} fi.LocalFlags &^= protocol.FlagLocalReceiveOnly
} }
return oldBatchFn(fs) batch.append(fi)
} }
} }
batch := newFileInfoBatch(batchFn)
// Schedule a pull after scanning, but only if we actually detected any // Schedule a pull after scanning, but only if we actually detected any
// changes. // changes.
@@ -472,12 +473,12 @@ func (f *folder) scanSubdirs(subDirs []string) error {
return err return err
} }
batch.append(res.File) batchAppend(res.File, snap)
changes++ changes++
if f.localFlags&protocol.FlagLocalReceiveOnly == 0 { if f.localFlags&protocol.FlagLocalReceiveOnly == 0 {
if nf, ok := f.findRename(snap, mtimefs, res.File, alreadyUsed); ok { if nf, ok := f.findRename(snap, mtimefs, res.File, alreadyUsed); ok {
batch.append(nf) batchAppend(nf, snap)
changes++ changes++
} }
} }
@@ -523,7 +524,7 @@ func (f *folder) scanSubdirs(subDirs []string) error {
for _, file := range toIgnore { for _, file := range toIgnore {
l.Debugln("marking file as ignored", file) l.Debugln("marking file as ignored", file)
nf := file.ConvertToIgnoredFileInfo(f.shortID) nf := file.ConvertToIgnoredFileInfo(f.shortID)
batch.append(nf) batchAppend(nf, snap)
changes++ changes++
if err := batch.flushIfFull(); err != nil { if err := batch.flushIfFull(); err != nil {
iterError = err iterError = err
@@ -550,7 +551,7 @@ func (f *folder) scanSubdirs(subDirs []string) error {
l.Debugln("marking file as ignored", file) l.Debugln("marking file as ignored", file)
nf := file.ConvertToIgnoredFileInfo(f.shortID) nf := file.ConvertToIgnoredFileInfo(f.shortID)
batch.append(nf) batchAppend(nf, snap)
changes++ changes++
case file.IsIgnored() && !ignored: case file.IsIgnored() && !ignored:
@@ -579,7 +580,7 @@ func (f *folder) scanSubdirs(subDirs []string) error {
nf.Version = protocol.Vector{} nf.Version = protocol.Vector{}
} }
batch.append(nf) batchAppend(nf, snap)
changes++ changes++
} }
@@ -593,7 +594,7 @@ func (f *folder) scanSubdirs(subDirs []string) error {
nf := fi.(db.FileInfoTruncated).ConvertDeletedToFileInfo() nf := fi.(db.FileInfoTruncated).ConvertDeletedToFileInfo()
nf.LocalFlags = 0 nf.LocalFlags = 0
nf.Version = protocol.Vector{} nf.Version = protocol.Vector{}
batch.append(nf) batchAppend(nf, snap)
changes++ changes++
return true return true
@@ -609,7 +610,7 @@ func (f *folder) scanSubdirs(subDirs []string) error {
for _, file := range toIgnore { for _, file := range toIgnore {
l.Debugln("marking file as ignored", f) l.Debugln("marking file as ignored", f)
nf := file.ConvertToIgnoredFileInfo(f.shortID) nf := file.ConvertToIgnoredFileInfo(f.shortID)
batch.append(nf) batchAppend(nf, snap)
changes++ changes++
if iterError = batch.flushIfFull(); iterError != nil { if iterError = batch.flushIfFull(); iterError != nil {
break break