Read bytes from the object - see io.Reader
(p []byte)
| 1279 | |
| 1280 | // Read bytes from the object - see io.Reader |
| 1281 | func (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 |
| 1309 | func (file *localOpenFile) Close() (err error) { |