lib/db: Remove need for the right dev removing globals (fixes #7036) (#7044)

This commit is contained in:
Simon Frei 2020-10-21 08:26:10 +02:00 committed by GitHub
parent 86b040f595
commit 27c91c57d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 1 deletions

View File

@ -859,7 +859,7 @@ func (t readWriteTransaction) removeFromGlobal(gk, keyBuf, folder, device, file
continue
}
if fv, have := fl.Get(dev[:]); Need(removedFV, have, fv.Version) {
meta.removeNeeded(deviceID, f)
meta.removeNeeded(dev, f)
}
}

View File

@ -4142,6 +4142,46 @@ func TestCompletionEmptyGlobal(t *testing.T) {
}
}
func TestNeedMetaAfterIndexReset(t *testing.T) {
w, fcfg := tmpDefaultWrapper()
waiter, _ := w.SetDevice(config.NewDeviceConfiguration(device2, "device2"))
waiter.Wait()
fcfg.Devices = append(fcfg.Devices, config.FolderDeviceConfiguration{DeviceID: device2})
waiter, _ = w.SetFolder(fcfg)
waiter.Wait()
m := setupModel(w)
defer cleanupModelAndRemoveDir(m, fcfg.Path)
var seq int64 = 1
files := []protocol.FileInfo{{Name: "foo", Size: 10, Version: protocol.Vector{}.Update(device1.Short()), Sequence: seq}}
// Start with two remotes having one file, then both deleting it, then
// only one adding it again.
m.Index(device1, fcfg.ID, files)
m.Index(device2, fcfg.ID, files)
seq++
files[0].SetDeleted(device2.Short())
files[0].Sequence = seq
m.IndexUpdate(device2, fcfg.ID, files)
m.IndexUpdate(device1, fcfg.ID, files)
seq++
files[0].Deleted = false
files[0].Size = 20
files[0].Version = files[0].Version.Update(device1.Short())
files[0].Sequence = seq
m.IndexUpdate(device1, fcfg.ID, files)
if comp := m.Completion(device2, fcfg.ID); comp.NeedItems != 1 {
t.Error("Expected one needed item for device2, got", comp.NeedItems)
}
// Pretend we had an index reset on device 1
m.Index(device1, fcfg.ID, files)
if comp := m.Completion(device2, fcfg.ID); comp.NeedItems != 1 {
t.Error("Expected one needed item for device2, got", comp.NeedItems)
}
}
func equalStringsInAnyOrder(a, b []string) bool {
if len(a) != len(b) {
return false