MCPcopy
hub / github.com/rclone/rclone / CryptCheckFn

Method CryptCheckFn

cmd/bisync/checkfn.go:93–119  ·  view source on GitHub ↗

CryptCheckFn is a slightly modified version of CryptCheck

(ctx context.Context, dst, src fs.Object)

Source from the content-addressed store, hash-verified

91
92// CryptCheckFn is a slightly modified version of CryptCheck
93func (b *bisyncRun) CryptCheckFn(ctx context.Context, dst, src fs.Object) (differ bool, noHash bool, err error) {
94 cryptDst := dst.(*crypt.Object)
95 underlyingDst := cryptDst.UnWrap()
96 underlyingHash, err := underlyingDst.Hash(ctx, b.check.hashType)
97 if err != nil {
98 return true, false, fmt.Errorf("error reading hash from underlying %v: %w", underlyingDst, err)
99 }
100 if underlyingHash == "" {
101 return false, true, nil
102 }
103 cryptHash, err := b.check.fcrypt.ComputeHash(ctx, cryptDst, src, b.check.hashType)
104 if err != nil {
105 return true, false, fmt.Errorf("error computing hash: %w", err)
106 }
107 if cryptHash == "" {
108 return false, true, nil
109 }
110 if cryptHash != underlyingHash {
111 err = fmt.Errorf("hashes differ (%s:%s) %q vs (%s:%s) %q", b.check.fdst.Name(), b.check.fdst.Root(), cryptHash, b.check.fsrc.Name(), b.check.fsrc.Root(), underlyingHash)
112 fs.Debugf(src, "%s", err.Error())
113 // using same error msg as CheckFn so integration tests match
114 err = fmt.Errorf("%v differ", b.check.hashType)
115 fs.Errorf(src, "%s", err.Error())
116 return true, false, nil
117 }
118 return false, false, nil
119}
120
121// ReverseCryptCheckFn is like CryptCheckFn except src and dst are switched
122// result: src is crypt, dst is non-crypt

Callers 1

ReverseCryptCheckFnMethod · 0.95

Calls 9

DebugfFunction · 0.92
ErrorfFunction · 0.92
ComputeHashMethod · 0.80
UnWrapMethod · 0.65
HashMethod · 0.65
NameMethod · 0.65
RootMethod · 0.65
ErrorMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected