Test copy with source file that's updating
(t *testing.T)
| 34 | |
| 35 | // Test copy with source file that's updating |
| 36 | func 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…