mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 10:28:49 -07:00
lib/db: Do not modify underlying array of argument
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4685
This commit is contained in:
parent
3af4164c8b
commit
fae2ca8458
@ -124,6 +124,10 @@ func (s *FileSet) Drop(device protocol.DeviceID) {
|
||||
|
||||
func (s *FileSet) Update(device protocol.DeviceID, fs []protocol.FileInfo) {
|
||||
l.Debugf("%s Update(%v, [%d])", s.folder, device, len(fs))
|
||||
|
||||
// do not modify fs in place, it is still used in outer scope
|
||||
fs = append([]protocol.FileInfo(nil), fs...)
|
||||
|
||||
normalizeFilenames(fs)
|
||||
|
||||
s.updateMutex.Lock()
|
||||
|
@ -447,10 +447,10 @@ func TestGlobalReset(t *testing.T) {
|
||||
m := db.NewFileSet("test)", fs.NewFilesystem(fs.FilesystemTypeBasic, "."), ldb)
|
||||
|
||||
local := []protocol.FileInfo{
|
||||
{Name: "a", Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}}},
|
||||
{Name: "b", Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}}},
|
||||
{Name: "c", Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}}},
|
||||
{Name: "d", Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}}},
|
||||
{Name: "a", Sequence: 1, Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}}},
|
||||
{Name: "b", Sequence: 2, Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}}},
|
||||
{Name: "c", Sequence: 3, Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}}},
|
||||
{Name: "d", Sequence: 4, Version: protocol.Vector{Counters: []protocol.Counter{{ID: myID, Value: 1000}}}},
|
||||
}
|
||||
|
||||
remote := []protocol.FileInfo{
|
||||
@ -464,8 +464,8 @@ func TestGlobalReset(t *testing.T) {
|
||||
g := globalList(m)
|
||||
sort.Sort(fileList(g))
|
||||
|
||||
if fmt.Sprint(g) != fmt.Sprint(local) {
|
||||
t.Errorf("Global incorrect;\n%v !=\n%v", g, local)
|
||||
if diff, equal := messagediff.PrettyDiff(local, g); !equal {
|
||||
t.Errorf("Global incorrect;\nglobal: %v\n!=\nlocal: %v\ndiff:\n%s", g, local, diff)
|
||||
}
|
||||
|
||||
replace(m, remoteDevice0, remote)
|
||||
@ -474,8 +474,8 @@ func TestGlobalReset(t *testing.T) {
|
||||
g = globalList(m)
|
||||
sort.Sort(fileList(g))
|
||||
|
||||
if fmt.Sprint(g) != fmt.Sprint(local) {
|
||||
t.Errorf("Global incorrect;\n%v !=\n%v", g, local)
|
||||
if diff, equal := messagediff.PrettyDiff(local, g); !equal {
|
||||
t.Errorf("Global incorrect;\nglobal: %v\n!=\nlocal: %v\ndiff:\n%s", g, local, diff)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user