MCPcopy
hub / github.com/rclone/rclone / Read

Method Read

backend/local/local.go:1281–1306  ·  view source on GitHub ↗

Read bytes from the object - see io.Reader

(p []byte)

Source from the content-addressed store, hash-verified

1279
1280// Read bytes from the object - see io.Reader
1281func (file *localOpenFile) Read(p []byte) (n int, err error) {
1282 if !file.o.fs.opt.NoCheckUpdated {
1283 // Check if file has the same size and modTime
1284 fi, err := file.fd.Stat()
1285 if err != nil {
1286 return 0, fmt.Errorf("can't read status of source file while transferring: %w", err)
1287 }
1288 file.o.fs.objectMetaMu.RLock()
1289 oldtime := file.o.modTime
1290 oldsize := file.o.size
1291 file.o.fs.objectMetaMu.RUnlock()
1292 if oldsize != fi.Size() {
1293 return 0, fserrors.NoLowLevelRetryError(fmt.Errorf("can't copy - source file is being updated (size changed from %d to %d)", oldsize, fi.Size()))
1294 }
1295 if !oldtime.Equal(readTime(file.o.fs.opt.TimeType, fi)) {
1296 return 0, fserrors.NoLowLevelRetryError(fmt.Errorf("can't copy - source file is being updated (mod time changed from %v to %v)", oldtime, fi.ModTime()))
1297 }
1298 }
1299
1300 n, err = file.in.Read(p)
1301 if n > 0 {
1302 // Hash routines never return an error
1303 _, _ = file.hash.Write(p[:n])
1304 }
1305 return
1306}
1307
1308// Close the object and update the hashes
1309func (file *localOpenFile) Close() (err error) {

Callers 1

TestUpdatingCheckFunction · 0.95

Calls 9

NoLowLevelRetryErrorFunction · 0.92
readTimeFunction · 0.70
StatMethod · 0.65
SizeMethod · 0.65
ModTimeMethod · 0.65
ReadMethod · 0.65
WriteMethod · 0.65
ErrorfMethod · 0.45
EqualMethod · 0.45

Tested by 1

TestUpdatingCheckFunction · 0.76