@@ -50,6 +50,15 @@ func globalList(s *db.FileSet) []protocol.FileInfo {
|
||||
})
|
||||
return fs
|
||||
}
|
||||
func globalListPrefixed(s *db.FileSet, prefix string) []db.FileInfoTruncated {
|
||||
var fs []db.FileInfoTruncated
|
||||
s.WithPrefixedGlobalTruncated(prefix, func(fi db.FileIntf) bool {
|
||||
f := fi.(db.FileInfoTruncated)
|
||||
fs = append(fs, f)
|
||||
return true
|
||||
})
|
||||
return fs
|
||||
}
|
||||
|
||||
func haveList(s *db.FileSet, n protocol.DeviceID) []protocol.FileInfo {
|
||||
var fs []protocol.FileInfo
|
||||
@@ -61,6 +70,16 @@ func haveList(s *db.FileSet, n protocol.DeviceID) []protocol.FileInfo {
|
||||
return fs
|
||||
}
|
||||
|
||||
func haveListPrefixed(s *db.FileSet, n protocol.DeviceID, prefix string) []db.FileInfoTruncated {
|
||||
var fs []db.FileInfoTruncated
|
||||
s.WithPrefixedHaveTruncated(n, prefix, func(fi db.FileIntf) bool {
|
||||
f := fi.(db.FileInfoTruncated)
|
||||
fs = append(fs, f)
|
||||
return true
|
||||
})
|
||||
return fs
|
||||
}
|
||||
|
||||
func needList(s *db.FileSet, n protocol.DeviceID) []protocol.FileInfo {
|
||||
var fs []protocol.FileInfo
|
||||
s.WithNeed(n, func(fi db.FileIntf) bool {
|
||||
@@ -892,6 +911,32 @@ func TestWithHaveSequence(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestIssue4925(t *testing.T) {
|
||||
ldb := db.OpenMemory()
|
||||
|
||||
folder := "test)"
|
||||
s := db.NewFileSet(folder, fs.NewFilesystem(fs.FilesystemTypeBasic, "."), ldb)
|
||||
|
||||
localHave := fileList{
|
||||
protocol.FileInfo{Name: "dir"},
|
||||
protocol.FileInfo{Name: "dir.file"},
|
||||
protocol.FileInfo{Name: "dir/file"},
|
||||
}
|
||||
|
||||
replace(s, protocol.LocalDeviceID, localHave)
|
||||
|
||||
for _, prefix := range []string{"dir", "dir/"} {
|
||||
pl := haveListPrefixed(s, protocol.LocalDeviceID, prefix)
|
||||
if l := len(pl); l != 2 {
|
||||
t.Errorf("Expected 2, got %v local items below %v", l, prefix)
|
||||
}
|
||||
pl = globalListPrefixed(s, prefix)
|
||||
if l := len(pl); l != 2 {
|
||||
t.Errorf("Expected 2, got %v global items below %v", l, prefix)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func replace(fs *db.FileSet, device protocol.DeviceID, files []protocol.FileInfo) {
|
||||
fs.Drop(device)
|
||||
fs.Update(device, files)
|
||||
|
||||
Reference in New Issue
Block a user