-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This reverts commit 3cfa228. <!-- markdownlint-disable MD041 --> #### What this PR does / why we need it #### Which issue(s) this PR fixes <!-- Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`. --> --------- Co-authored-by: Jakob Möller <[email protected]>
- Loading branch information
1 parent
ed93e9a
commit c76a2ed
Showing
18 changed files
with
2,414 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package ocireg | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/containerd/containerd/remotes" | ||
"github.com/mandelsoft/goutils/errors" | ||
"github.com/opencontainers/go-digest" | ||
"github.com/sirupsen/logrus" | ||
|
||
"ocm.software/ocm/api/oci/cpi" | ||
"ocm.software/ocm/api/oci/extensions/attrs/cacheattr" | ||
"ocm.software/ocm/api/tech/docker/resolve" | ||
"ocm.software/ocm/api/utils/accessio" | ||
"ocm.software/ocm/api/utils/blobaccess/blobaccess" | ||
) | ||
|
||
type BlobContainer interface { | ||
GetBlobData(digest digest.Digest) (int64, cpi.DataAccess, error) | ||
AddBlob(blob cpi.BlobAccess) (int64, digest.Digest, error) | ||
Unref() error | ||
} | ||
|
||
type blobContainer struct { | ||
accessio.StaticAllocatable | ||
fetcher resolve.Fetcher | ||
pusher resolve.Pusher | ||
mime string | ||
} | ||
|
||
type BlobContainers struct { | ||
lock sync.Mutex | ||
cache accessio.BlobCache | ||
fetcher resolve.Fetcher | ||
pusher resolve.Pusher | ||
mimes map[string]BlobContainer | ||
} | ||
|
||
func NewBlobContainers(ctx cpi.Context, fetcher remotes.Fetcher, pusher resolve.Pusher) *BlobContainers { | ||
return &BlobContainers{ | ||
cache: cacheattr.Get(ctx), | ||
fetcher: fetcher, | ||
pusher: pusher, | ||
mimes: map[string]BlobContainer{}, | ||
} | ||
} | ||
|
||
func (c *BlobContainers) Get(mime string) (BlobContainer, error) { | ||
c.lock.Lock() | ||
defer c.lock.Unlock() | ||
|
||
found := c.mimes[mime] | ||
if found == nil { | ||
container, err := NewBlobContainer(c.cache, mime, c.fetcher, c.pusher) | ||
if err != nil { | ||
return nil, err | ||
} | ||
c.mimes[mime] = container | ||
|
||
return container, nil | ||
} | ||
|
||
return found, nil | ||
} | ||
|
||
func (c *BlobContainers) Release() error { | ||
c.lock.Lock() | ||
defer c.lock.Unlock() | ||
list := errors.ErrListf("releasing mime block caches") | ||
for _, b := range c.mimes { | ||
list.Add(b.Unref()) | ||
} | ||
return list.Result() | ||
} | ||
|
||
func newBlobContainer(mime string, fetcher resolve.Fetcher, pusher resolve.Pusher) *blobContainer { | ||
return &blobContainer{ | ||
mime: mime, | ||
fetcher: fetcher, | ||
pusher: pusher, | ||
} | ||
} | ||
|
||
func NewBlobContainer(cache accessio.BlobCache, mime string, fetcher resolve.Fetcher, pusher resolve.Pusher) (BlobContainer, error) { | ||
c := newBlobContainer(mime, fetcher, pusher) | ||
|
||
if cache == nil { | ||
return c, nil | ||
} | ||
r, err := accessio.CachedAccess(c, c, cache) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return r, nil | ||
} | ||
|
||
func (n *blobContainer) GetBlobData(digest digest.Digest) (int64, cpi.DataAccess, error) { | ||
logrus.Debugf("orig get %s %s\n", n.mime, digest) | ||
acc, err := NewDataAccess(n.fetcher, digest, n.mime, false) | ||
return blobaccess.BLOB_UNKNOWN_SIZE, acc, err | ||
} | ||
|
||
func (n *blobContainer) AddBlob(blob cpi.BlobAccess) (int64, digest.Digest, error) { | ||
err := push(dummyContext, n.pusher, blob) | ||
if err != nil { | ||
return blobaccess.BLOB_UNKNOWN_SIZE, blobaccess.BLOB_UNKNOWN_DIGEST, err | ||
} | ||
return blob.Size(), blob.Digest(), err | ||
} |
Oops, something went wrong.