MCPcopy
hub / github.com/rclone/rclone / verifyObjectHash

Method verifyObjectHash

backend/compress/compress.go:537–552  ·  view source on GitHub ↗

verifyObjectHash verifies the Objects hash

(ctx context.Context, o fs.Object, hasher *hash.MultiHasher, ht hash.Type)

Source from the content-addressed store, hash-verified

535
536// verifyObjectHash verifies the Objects hash
537func (f *Fs) verifyObjectHash(ctx context.Context, o fs.Object, hasher *hash.MultiHasher, ht hash.Type) error {
538 srcHash := hasher.Sums()[ht]
539 dstHash, err := o.Hash(ctx, ht)
540 if err != nil {
541 return fmt.Errorf("failed to read destination hash: %w", err)
542 }
543 if srcHash != "" && dstHash != "" && srcHash != dstHash {
544 // remove object
545 err = o.Remove(ctx)
546 if err != nil {
547 fs.Errorf(o, "Failed to remove corrupted object: %v", err)
548 }
549 return fmt.Errorf("corrupted on transfer: %v compressed hashes differ src(%s) %q vs dst(%s) %q", ht, f.Fs, srcHash, o.Fs(), dstHash)
550 }
551 return nil
552}
553
554type putFn func(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error)
555

Callers 3

putUncompressMethod · 0.95
putCompressMethod · 0.80
putCompressMethod · 0.80

Calls 6

ErrorfFunction · 0.92
SumsMethod · 0.80
HashMethod · 0.65
RemoveMethod · 0.65
FsMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected