MCPcopy
hub / github.com/rclone/rclone / TestUpdatingCheck

Function TestUpdatingCheck

backend/local/local_internal_test.go:36–76  ·  view source on GitHub ↗

Test copy with source file that's updating

(t *testing.T)

Source from the content-addressed store, hash-verified

34
35// Test copy with source file that's updating
36func TestUpdatingCheck(t *testing.T) {
37 r := fstest.NewRun(t)
38 filePath := "sub dir/local test"
39 r.WriteFile(filePath, "content", time.Now())
40
41 fd, err := file.Open(path.Join(r.LocalName, filePath))
42 if err != nil {
43 t.Fatalf("failed opening file %q: %v", filePath, err)
44 }
45 defer func() {
46 require.NoError(t, fd.Close())
47 }()
48
49 fi, err := fd.Stat()
50 require.NoError(t, err)
51 o := &Object{size: fi.Size(), modTime: fi.ModTime(), fs: &Fs{}}
52 wrappedFd := readers.NewLimitedReadCloser(fd, -1)
53 hash, err := hash.NewMultiHasherTypes(hash.Supported())
54 require.NoError(t, err)
55 in := localOpenFile{
56 o: o,
57 in: wrappedFd,
58 hash: hash,
59 fd: fd,
60 }
61
62 buf := make([]byte, 1)
63 _, err = in.Read(buf)
64 require.NoError(t, err)
65
66 r.WriteFile(filePath, "content updated", time.Now())
67 _, err = in.Read(buf)
68 require.Errorf(t, err, "can't copy - source file is being updated")
69
70 // turn the checking off and try again
71 in.o.fs.opt.NoCheckUpdated = true
72
73 r.WriteFile(filePath, "content updated", time.Now())
74 _, err = in.Read(buf)
75 require.NoError(t, err)
76}
77
78// Test corrupted on transfer
79// should error due to size/hash mismatch

Callers

nothing calls this directly

Calls 12

WriteFileMethod · 0.95
ReadMethod · 0.95
NewRunFunction · 0.92
OpenFunction · 0.92
NewLimitedReadCloserFunction · 0.92
JoinMethod · 0.80
FatalfMethod · 0.80
CloseMethod · 0.65
StatMethod · 0.65
SizeMethod · 0.65
ModTimeMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…