MCPcopy
hub / github.com/kopia/kopia / getContentFromFullBlob

Method getContentFromFullBlob

internal/cache/content_cache.go:64–95  ·  view source on GitHub ↗
(ctx context.Context, blobID blob.ID, offset, length int64, output *gather.WriteBuffer)

Source from the content-addressed store, hash-verified

62}
63
64func (c *contentCacheImpl) getContentFromFullBlob(ctx context.Context, blobID blob.ID, offset, length int64, output *gather.WriteBuffer) error {
65 c.pc.exclusiveLock(string(blobID))
66 defer c.pc.exclusiveUnlock(string(blobID))
67
68 // check again to see if we perhaps lost the race and the data is now in cache.
69 if c.pc.getPartial(ctx, BlobIDCacheKey(blobID), offset, length, output) {
70 return nil
71 }
72
73 var blobData gather.WriteBuffer
74 defer blobData.Close()
75
76 if err := c.fetchBlobInternal(ctx, blobID, &blobData); err != nil {
77 return err
78 }
79
80 if offset == 0 && length == -1 {
81 _, err := blobData.Bytes().WriteTo(output)
82
83 return errors.Wrap(err, "error copying results")
84 }
85
86 if offset < 0 || offset+length > int64(blobData.Length()) {
87 return errors.Errorf("invalid (offset=%v,length=%v) for blob %q of size %v", offset, length, blobID, blobData.Length())
88 }
89
90 output.Reset()
91
92 impossible.PanicOnError(blobData.AppendSectionTo(output, int(offset), int(length)))
93
94 return nil
95}
96
97func (c *contentCacheImpl) fetchBlobInternal(ctx context.Context, blobID blob.ID, blobData *gather.WriteBuffer) error {
98 // read the entire blob

Callers 1

GetContentMethod · 0.95

Calls 13

CloseMethod · 0.95
fetchBlobInternalMethod · 0.95
BytesMethod · 0.95
LengthMethod · 0.95
AppendSectionToMethod · 0.95
PanicOnErrorFunction · 0.92
BlobIDCacheKeyFunction · 0.85
getPartialMethod · 0.80
ErrorfMethod · 0.80
WriteToMethod · 0.65
ResetMethod · 0.65
exclusiveLockMethod · 0.45

Tested by

no test coverage detected