Skip to content

Commit bea6eca

Browse files
imsodincalmh
authored andcommitted
lib/scanner, lib/model: Actually assign version when un-ignoring (fixes syncthing#4841) (syncthing#4842)
This fixes a mistake introduced in syncthing#4750 and syncthing#4776 and is relevant to v0.14.46-rc1
1 parent 470ef87 commit bea6eca

File tree

4 files changed

+96
-4
lines changed

4 files changed

+96
-4
lines changed

lib/model/model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2072,7 +2072,7 @@ func (m *Model) internalScanFolderSubdirs(ctx context.Context, folder string, su
20722072
// other existing versions, which will be resolved
20732073
// by the normal pulling mechanisms.
20742074
if f.IsInvalid() {
2075-
nf.Version.DropOthers(m.shortID)
2075+
nf.Version = nf.Version.DropOthers(m.shortID)
20762076
}
20772077

20782078
batch = append(batch, nf)

lib/model/requests_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,45 @@ func pullInvalidIgnored(t *testing.T, ft config.FolderType) {
425425
}
426426
}
427427

428+
func TestIssue4841(t *testing.T) {
429+
m, fc, tmpDir := setupModelWithConnection()
430+
defer m.Stop()
431+
defer os.RemoveAll(tmpDir)
432+
433+
received := make(chan protocol.FileInfo)
434+
fc.mut.Lock()
435+
fc.indexFn = func(folder string, fs []protocol.FileInfo) {
436+
if len(fs) != 1 {
437+
t.Fatalf("Sent index with %d files, should be 1", len(fs))
438+
}
439+
if fs[0].Name != "foo" {
440+
t.Fatalf(`Sent index with file %v, should be "foo"`, fs[0].Name)
441+
}
442+
received <- fs[0]
443+
return
444+
}
445+
fc.mut.Unlock()
446+
447+
// Setup file from remote that was ignored locally
448+
m.updateLocals(defaultFolderConfig.ID, []protocol.FileInfo{{
449+
Name: "foo",
450+
Type: protocol.FileInfoTypeFile,
451+
Invalid: true,
452+
Version: protocol.Vector{}.Update(device2.Short()),
453+
}})
454+
<-received
455+
456+
// Scan without ignore patterns with "foo" not existing locally
457+
if err := m.ScanFolder("default"); err != nil {
458+
t.Fatal("Failed scanning:", err)
459+
}
460+
461+
f := <-received
462+
if expected := (protocol.Vector{}.Update(device1.Short())); !f.Version.Equal(expected) {
463+
t.Errorf("Got Version == %v, expected %v", f.Version, expected)
464+
}
465+
}
466+
428467
func setupModelWithConnection() (*Model, *fakeConnection, string) {
429468
tmpDir := createTmpDir()
430469
cfg := defaultConfig.RawCopy()

lib/scanner/walk.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func (w *walker) walkRegular(ctx context.Context, relPath string, info fs.FileIn
308308
// currently have. Keeping only our local counter makes sure we are in
309309
// conflict with any other existing versions, which will be resolved by
310310
// the normal pulling mechanisms.
311-
f.Version.DropOthers(w.ShortID)
311+
f.Version = f.Version.DropOthers(w.ShortID)
312312
}
313313
l.Debugln("rescan:", cf, info.ModTime().Unix(), info.Mode()&fs.ModePerm)
314314
}
@@ -347,7 +347,7 @@ func (w *walker) walkDir(ctx context.Context, relPath string, info fs.FileInfo,
347347
// currently have. Keeping only our local counter makes sure we are in
348348
// conflict with any other existing versions, which will be resolved by
349349
// the normal pulling mechanisms.
350-
f.Version.DropOthers(w.ShortID)
350+
f.Version = f.Version.DropOthers(w.ShortID)
351351
}
352352
}
353353

@@ -402,7 +402,7 @@ func (w *walker) walkSymlink(ctx context.Context, relPath string, dchan chan pro
402402
// currently have. Keeping only our local counter makes sure we are in
403403
// conflict with any other existing versions, which will be resolved by
404404
// the normal pulling mechanisms.
405-
f.Version.DropOthers(w.ShortID)
405+
f.Version = f.Version.DropOthers(w.ShortID)
406406
}
407407
}
408408

lib/scanner/walk_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,52 @@ func TestIssue4799(t *testing.T) {
522522
}
523523
}
524524

525+
func TestIssue4841(t *testing.T) {
526+
tmp, err := ioutil.TempDir("", "")
527+
if err != nil {
528+
t.Fatal(err)
529+
}
530+
defer os.RemoveAll(tmp)
531+
532+
fs := fs.NewFilesystem(fs.FilesystemTypeBasic, tmp)
533+
534+
fd, err := fs.Create("foo")
535+
if err != nil {
536+
panic(err)
537+
}
538+
fd.Close()
539+
540+
fchan := Walk(context.TODO(), Config{
541+
Filesystem: fs,
542+
Subs: nil,
543+
BlockSize: 128 * 1024,
544+
AutoNormalize: true,
545+
Hashers: 2,
546+
CurrentFiler: fakeCurrentFiler{
547+
"foo": {
548+
Name: "foo",
549+
Type: protocol.FileInfoTypeFile,
550+
Invalid: true,
551+
Version: protocol.Vector{}.Update(1),
552+
},
553+
},
554+
ShortID: protocol.LocalDeviceID.Short(),
555+
})
556+
557+
var files []protocol.FileInfo
558+
for f := range fchan {
559+
files = append(files, f)
560+
}
561+
sort.Sort(fileList(files))
562+
563+
if len(files) != 1 {
564+
t.Fatalf("Expected 1 file, got %d: %v", len(files), files)
565+
}
566+
if expected := (protocol.Vector{}.Update(protocol.LocalDeviceID.Short())); !files[0].Version.Equal(expected) {
567+
t.Fatalf("Expected Version == %v, got %v", expected, files[0].Version)
568+
}
569+
}
570+
525571
// Verify returns nil or an error describing the mismatch between the block
526572
// list and actual reader contents
527573
func verify(r io.Reader, blocksize int, blocks []protocol.BlockInfo) error {
@@ -553,3 +599,10 @@ func verify(r io.Reader, blocksize int, blocks []protocol.BlockInfo) error {
553599

554600
return nil
555601
}
602+
603+
type fakeCurrentFiler map[string]protocol.FileInfo
604+
605+
func (fcf fakeCurrentFiler) CurrentFile(name string) (protocol.FileInfo, bool) {
606+
f, ok := fcf[name]
607+
return f, ok
608+
}

0 commit comments

Comments
 (0)