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

Method Hash

backend/hasher/object.go:70–115  ·  view source on GitHub ↗

Hash returns the selected checksum of the file or "" if unavailable.

(ctx context.Context, hashType hash.Type)

Source from the content-addressed store, hash-verified

68
69// Hash returns the selected checksum of the file or "" if unavailable.
70func (o *Object) Hash(ctx context.Context, hashType hash.Type) (hashVal string, err error) {
71 f := o.f
72 if f.passHashes.Contains(hashType) {
73 fs.Debugf(o, "pass %s", hashType)
74 hashVal, err = o.Object.Hash(ctx, hashType)
75 if hashVal != "" {
76 return hashVal, err
77 }
78 if err != nil {
79 fs.Debugf(o, "error passing %s: %v", hashType, err)
80 }
81 fs.Debugf(o, "passed %s is blank -- trying other methods", hashType)
82 }
83 if !f.suppHashes.Contains(hashType) {
84 fs.Debugf(o, "unsupp %s", hashType)
85 return "", hash.ErrUnsupported
86 }
87 if hashVal, err = o.getHash(ctx, hashType); err != nil {
88 fs.Debugf(o, "getHash: %v", err)
89 err = nil
90 hashVal = ""
91 }
92 if hashVal != "" {
93 fs.Debugf(o, "cached %s = %q", hashType, hashVal)
94 return hashVal, nil
95 }
96 if f.slowHashes.Contains(hashType) {
97 fs.Debugf(o, "slow %s", hashType)
98 hashVal, err = o.Object.Hash(ctx, hashType)
99 if err == nil && hashVal != "" && f.keepHashes.Contains(hashType) {
100 if err = o.putHashes(ctx, hashMap{hashType: hashVal}); err != nil {
101 fs.Debugf(o, "putHashes: %v", err)
102 err = nil
103 }
104 }
105 return hashVal, err
106 }
107 if f.autoHashes.Contains(hashType) && o.Size() < int64(f.opt.AutoSize) {
108 _ = o.updateHashes(ctx)
109 if hashVal, err = o.getHash(ctx, hashType); err != nil {
110 fs.Debugf(o, "auto %s = %q (%v)", hashType, hashVal, err)
111 err = nil
112 }
113 }
114 return hashVal, err
115}
116
117// updateHashes performs implicit "rclone hashsum --download" and updates cache.
118func (o *Object) updateHashes(ctx context.Context) error {

Callers

nothing calls this directly

Calls 7

getHashMethod · 0.95
putHashesMethod · 0.95
SizeMethod · 0.95
updateHashesMethod · 0.95
DebugfFunction · 0.92
ContainsMethod · 0.80
HashMethod · 0.65

Tested by

no test coverage detected