diff --git a/internal/db/sqlite/db_global_test.go b/internal/db/sqlite/db_global_test.go index 44130ac77..3a3bae606 100644 --- a/internal/db/sqlite/db_global_test.go +++ b/internal/db/sqlite/db_global_test.go @@ -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) { diff --git a/internal/db/sqlite/folderdb_counts.go b/internal/db/sqlite/folderdb_counts.go index 0e019f15a..1c6dfd56f 100644 --- a/internal/db/sqlite/folderdb_counts.go +++ b/internal/db/sqlite/folderdb_counts.go @@ -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(), diff --git a/internal/db/sqlite/folderdb_global.go b/internal/db/sqlite/folderdb_global.go index 3fc71d53c..5dd6c42a3 100644 --- a/internal/db/sqlite/folderdb_global.go +++ b/internal/db/sqlite/folderdb_global.go @@ -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(),