Hash returns the selected checksum of the file or "" if unavailable.
(ctx context.Context, hashType hash.Type)
| 68 | |
| 69 | // Hash returns the selected checksum of the file or "" if unavailable. |
| 70 | func (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. |
| 118 | func (o *Object) updateHashes(ctx context.Context) error { |