MCPcopy
hub / github.com/syncthing/syncthing / TestRenameSameFile

Function TestRenameSameFile

lib/model/model_test.go:3302–3343  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3300}
3301
3302func TestRenameSameFile(t *testing.T) {
3303 wcfg, fcfg := newDefaultCfgWrapper(t)
3304 m := setupModel(t, wcfg)
3305 defer cleanupModel(m)
3306
3307 ffs := fcfg.Filesystem()
3308 writeFile(t, ffs, "file", []byte("file"))
3309
3310 m.ScanFolders()
3311
3312 count := countIterator[protocol.FileInfo](t)(m.LocalFiles("default", protocol.LocalDeviceID))
3313 if count != 1 {
3314 t.Errorf("Unexpected count: %d != %d", count, 1)
3315 }
3316
3317 must(t, ffs.Rename("file", "file1"))
3318 must(t, osutil.Copy(fs.CopyRangeMethodStandard, ffs, ffs, "file1", "file0"))
3319 must(t, osutil.Copy(fs.CopyRangeMethodStandard, ffs, ffs, "file1", "file2"))
3320 must(t, osutil.Copy(fs.CopyRangeMethodStandard, ffs, ffs, "file1", "file3"))
3321 must(t, osutil.Copy(fs.CopyRangeMethodStandard, ffs, ffs, "file1", "file4"))
3322
3323 m.ScanFolders()
3324
3325 prevSeq := int64(0)
3326 seen := false
3327 it, errFn := m.LocalFilesSequenced("default", protocol.LocalDeviceID, 0)
3328 for i := range it {
3329 if i.SequenceNo() <= prevSeq {
3330 t.Fatalf("non-increasing sequences: %d <= %d", i.SequenceNo(), prevSeq)
3331 }
3332 if i.FileName() == "file" {
3333 if seen {
3334 t.Fatal("already seen file")
3335 }
3336 seen = true
3337 }
3338 prevSeq = i.SequenceNo()
3339 }
3340 if err := errFn(); err != nil {
3341 t.Fatal(err)
3342 }
3343}
3344
3345// TestRenameBatchFlush verifies that rename detection works correctly when
3346// a batch flush happens mid-scan. With enough files to exceed

Callers

nothing calls this directly

Calls 14

CopyFunction · 0.92
newDefaultCfgWrapperFunction · 0.85
setupModelFunction · 0.85
cleanupModelFunction · 0.85
mustFunction · 0.85
FilesystemMethod · 0.80
SequenceNoMethod · 0.80
FileNameMethod · 0.80
FatalMethod · 0.80
writeFileFunction · 0.70
ScanFoldersMethod · 0.65
LocalFilesMethod · 0.65

Tested by

no test coverage detected