MCPcopy Index your code
hub / github.com/rclone/rclone / tryDownloadHash

Method tryDownloadHash

cmd/bisync/compare.go:278–310  ·  view source on GitHub ↗
(ctx context.Context, o fs.DirEntry, hashVal string)

Source from the content-addressed store, hash-verified

276}
277
278func (b *bisyncRun) tryDownloadHash(ctx context.Context, o fs.DirEntry, hashVal string) (string, error) {
279 if hashVal != "" || !b.downloadHashOpt.downloadHash {
280 return hashVal, nil
281 }
282 obj, ok := o.(fs.Object)
283 if !ok {
284 fs.Infof(o, "failed to download hash -- not an fs.Object")
285 return hashVal, fs.ErrorObjectNotFound
286 }
287 if o.Size() < 0 {
288 b.downloadHashOpt.downloadHashWarn.Do(func() {
289 fs.Log(o, Color(terminal.YellowFg, "Skipping hash download as checksum not reliable with files of unknown length."))
290 })
291 fs.Debugf(o, "Skipping hash download as checksum not reliable with files of unknown length.")
292 return hashVal, hash.ErrUnsupported
293 }
294
295 b.downloadHashOpt.firstDownloadHash.Do(func() {
296 fs.Infoc(obj.Fs().Name(), Color(terminal.Dim, "Downloading hashes..."))
297 })
298 tr := accounting.Stats(ctx).NewCheckingTransfer(o, "computing hash with --download-hash")
299 defer func() {
300 tr.Done(ctx, nil)
301 }()
302
303 sum, err := operations.HashSum(ctx, hash.MD5, false, true, obj)
304 if err != nil {
305 fs.Infof(o, "DownloadHash -- hash: %v, err: %v", sum, err)
306 } else {
307 fs.Debugf(o, "DownloadHash -- hash: %v", sum)
308 }
309 return sum, err
310}

Callers 4

recheckMethod · 0.95
EqualFnMethod · 0.95
WriteResultsMethod · 0.95
ForObjectMethod · 0.95

Calls 13

InfofFunction · 0.92
LogFunction · 0.92
DebugfFunction · 0.92
InfocFunction · 0.92
StatsFunction · 0.92
HashSumFunction · 0.92
ColorFunction · 0.85
NewCheckingTransferMethod · 0.80
SizeMethod · 0.65
DoMethod · 0.65
NameMethod · 0.65
FsMethod · 0.65

Tested by

no test coverage detected