fix(db): skip invalid files as remote need when local is deleted

This commit is contained in:
Jakob Borg
2025-04-09 16:24:17 +02:00
parent 95b39a791d
commit 7cfa871d58
3 changed files with 33 additions and 7 deletions
+27 -1
View File
@@ -268,7 +268,7 @@ func TestDontNeedIgnored(t *testing.T) {
}
}
func TestRemoveDontNeedLocalIgnored(t *testing.T) {
func TestRemoteDontNeedLocalIgnored(t *testing.T) {
t.Parallel()
db, err := OpenTemp()
@@ -392,6 +392,32 @@ func TestRemoteDontNeedDeletedMissing(t *testing.T) {
t.Log(names)
t.Error("need no files")
}
// Another remote has announced it, but has set the invalid bit,
// presumably it's being ignored.
file = genFile("test1", 1, 103)
file.SetIgnored()
err = db.Update(folderID, protocol.DeviceID{43}, []protocol.FileInfo{file})
if err != nil {
t.Fatal(err)
}
// They don't need it, either
s, err = db.CountNeed(folderID, protocol.DeviceID{43})
if err != nil {
t.Fatal(err)
}
if s.Bytes != 0 || s.Files != 0 || s.Deleted != 0 {
t.Log(s)
t.Error("bad need")
}
// It shouldn't show up in their need list
names = mustCollect[protocol.FileInfo](t)(db.AllNeededGlobalFiles(folderID, protocol.DeviceID{42}, config.PullOrderAlphabetic, 0, 0))
if len(names) != 0 {
t.Log(names)
t.Error("need no files")
}
}
func TestNeedRemoteSymlinkAndDir(t *testing.T) {
+1 -1
View File
@@ -97,7 +97,7 @@ func (s *folderDB) needSizeRemote(device protocol.DeviceID) (db.Counts, error) {
WHERE g.local_flags & {{.FlagLocalGlobal}} != 0 AND g.deleted AND NOT g.invalid AND EXISTS (
SELECT 1 FROM FILES f
INNER JOIN devices d ON d.idx = f.device_idx
WHERE f.name = g.name AND d.device_id = ? AND NOT f.deleted
WHERE f.name = g.name AND d.device_id = ? AND NOT f.deleted AND NOT f.invalid
)
GROUP BY g.type, g.local_flags, g.deleted
`).Select(&res, device.String(),
+5 -5
View File
@@ -148,11 +148,11 @@ func (s *folderDB) neededGlobalFilesLocal(selectOpts string) (iter.Seq[protocol.
func (s *folderDB) neededGlobalFilesRemote(device protocol.DeviceID, selectOpts string) (iter.Seq[protocol.FileInfo], func() error) {
// Select:
//
// - all the valid, non-deleted global files that don't have a corresponding
// remote file with the same version.
// - all the valid, non-deleted global files that don't have a
// corresponding remote file with the same version.
//
// - all the valid, deleted global files that have a corresponding non-deleted
// remote file (of any version)
// - all the valid, deleted global files that have a corresponding
// non-deleted and valid remote file (of any version)
it, errFn := iterStructs[indirectFI](s.stmt(`
SELECT fi.fiprotobuf, bl.blprotobuf, g.name, g.size, g.modified FROM fileinfos fi
@@ -172,7 +172,7 @@ func (s *folderDB) neededGlobalFilesRemote(device protocol.DeviceID, selectOpts
WHERE g.local_flags & {{.FlagLocalGlobal}} != 0 AND g.deleted AND NOT g.invalid AND EXISTS (
SELECT 1 FROM FILES f
INNER JOIN devices d ON d.idx = f.device_idx
WHERE f.name = g.name AND d.device_id = ? AND NOT f.deleted
WHERE f.name = g.name AND d.device_id = ? AND NOT f.deleted AND NOT f.invalid
)
`+selectOpts).Queryx(
device.String(),