MCPcopy
hub / github.com/rclone/rclone / Hash

Method Hash

backend/cache/object.go:319–345  ·  view source on GitHub ↗

Hash requests a hash of the object and stores in the cache since it might or might not be called, this is lazy loaded

(ctx context.Context, ht hash.Type)

Source from the content-addressed store, hash-verified

317// Hash requests a hash of the object and stores in the cache
318// since it might or might not be called, this is lazy loaded
319func (o *Object) Hash(ctx context.Context, ht hash.Type) (string, error) {
320 _ = o.refresh(ctx)
321 o.cacheHashesMu.Lock()
322 if o.CacheHashes == nil {
323 o.CacheHashes = make(map[hash.Type]string)
324 }
325 cachedHash, found := o.CacheHashes[ht]
326 o.cacheHashesMu.Unlock()
327 if found {
328 return cachedHash, nil
329 }
330 if err := o.refreshFromSource(ctx, false); err != nil {
331 return "", err
332 }
333 liveHash, err := o.Object.Hash(ctx, ht)
334 if err != nil {
335 return "", err
336 }
337 o.cacheHashesMu.Lock()
338 o.CacheHashes[ht] = liveHash
339 o.cacheHashesMu.Unlock()
340
341 o.persist()
342 fs.Debugf(o, "object hash cached: %v", liveHash)
343
344 return liveHash, nil
345}
346
347// persist adds this object to the persistent cache
348func (o *Object) persist() *Object {

Callers

nothing calls this directly

Calls 7

refreshMethod · 0.95
refreshFromSourceMethod · 0.95
persistMethod · 0.95
DebugfFunction · 0.92
LockMethod · 0.65
UnlockMethod · 0.65
HashMethod · 0.65

Tested by

no test coverage detected