MCPcopy
hub / github.com/rclone/rclone / download

Method download

backend/cache/handle.go:432–491  ·  view source on GitHub ↗
(chunkStart, chunkEnd int64, retry int)

Source from the content-addressed store, hash-verified

430}
431
432func (w *worker) download(chunkStart, chunkEnd int64, retry int) {
433 var err error
434 var data []byte
435
436 // stop retries
437 if retry >= w.r.cacheFs().opt.ReadRetries {
438 return
439 }
440 // back-off between retries
441 if retry > 0 {
442 time.Sleep(time.Second * time.Duration(retry))
443 }
444
445 closeOpen := false
446 if retry > 0 {
447 closeOpen = true
448 }
449 w.rc, err = w.reader(chunkStart, chunkEnd, closeOpen)
450 // we seem to be getting only errors so we abort
451 if err != nil {
452 fs.Errorf(w, "object open failed %v: %v", chunkStart, err)
453 err = w.r.cachedObject.refreshFromSource(w.r.ctx, true)
454 if err != nil {
455 fs.Errorf(w, "%v", err)
456 }
457 w.download(chunkStart, chunkEnd, retry+1)
458 return
459 }
460
461 data = make([]byte, chunkEnd-chunkStart)
462 var sourceRead int
463 sourceRead, err = io.ReadFull(w.rc, data)
464 if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF {
465 fs.Errorf(w, "failed to read chunk %v: %v", chunkStart, err)
466 err = w.r.cachedObject.refreshFromSource(w.r.ctx, true)
467 if err != nil {
468 fs.Errorf(w, "%v", err)
469 }
470 w.download(chunkStart, chunkEnd, retry+1)
471 return
472 }
473 data = data[:sourceRead] // reslice to remove extra garbage
474 if err == io.ErrUnexpectedEOF {
475 fs.Debugf(w, "partial downloaded chunk %v", fs.SizeSuffix(chunkStart))
476 } else {
477 fs.Debugf(w, "downloaded chunk %v", chunkStart)
478 }
479
480 if w.r.UseMemory {
481 err = w.r.memory.AddChunk(w.r.cachedObject.abs(), data, chunkStart)
482 if err != nil {
483 fs.Errorf(w, "failed caching chunk in ram %v: %v", chunkStart, err)
484 }
485 }
486
487 err = w.r.storage().AddChunk(w.r.cachedObject.abs(), data, chunkStart)
488 if err != nil {
489 fs.Errorf(w, "failed caching chunk in storage %v: %v", chunkStart, err)

Callers 1

runMethod · 0.95

Calls 9

readerMethod · 0.95
ErrorfFunction · 0.92
DebugfFunction · 0.92
SizeSuffixTypeAlias · 0.92
cacheFsMethod · 0.80
refreshFromSourceMethod · 0.80
storageMethod · 0.80
AddChunkMethod · 0.45
absMethod · 0.45

Tested by

no test coverage detected