mirror of
https://github.com/project-zot/zot.git
synced 2026-06-15 20:07:55 +08:00
api: use blob cache path while making hard link
previously mount blob will look for blob that is provided in http request and try to hard link that path but ideally we should look for path from our cache and do the hard link of that particular path. this commit does the same.
This commit is contained in:
committed by
Ramkumar Chinchani
parent
3a59b9f487
commit
af30c06aff
+7
-33
@@ -1024,40 +1024,8 @@ func (is *ImageStore) BlobPath(repo string, digest godigest.Digest) string {
|
||||
return path.Join(is.rootDir, repo, "blobs", digest.Algorithm().String(), digest.Encoded())
|
||||
}
|
||||
|
||||
func (is *ImageStore) MountBlob(repo string, mountRepo string, digest string) error {
|
||||
d, err := godigest.Parse(digest)
|
||||
if err != nil {
|
||||
is.log.Error().Err(err).Str("digest", digest).Msg("failed to parse digest")
|
||||
|
||||
return errors.ErrBadBlobDigest
|
||||
}
|
||||
|
||||
mountBlobPath := is.BlobPath(mountRepo, d)
|
||||
is.log.Debug().Str("mount path", mountBlobPath)
|
||||
|
||||
blobPath := is.BlobPath(repo, d)
|
||||
is.log.Debug().Str("repo path", blobPath)
|
||||
|
||||
_, err = os.Stat(mountBlobPath)
|
||||
if err != nil {
|
||||
is.log.Error().Err(err).Msg("mount: blob path not found")
|
||||
|
||||
return errors.ErrBlobNotFound
|
||||
}
|
||||
|
||||
_, err = is.copyBlob(repo, blobPath, mountBlobPath)
|
||||
if err != nil {
|
||||
is.log.Error().Err(err).Msg("cache: error copying blobs from cache location")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckBlob verifies a blob and returns true if the blob is correct.
|
||||
func (is *ImageStore) CheckBlob(repo string, digest string,
|
||||
mediaType string) (bool, int64, error) {
|
||||
func (is *ImageStore) CheckBlob(repo string, digest string) (bool, int64, error) {
|
||||
d, err := godigest.Parse(digest)
|
||||
if err != nil {
|
||||
is.log.Error().Err(err).Str("digest", digest).Msg("failed to parse digest")
|
||||
@@ -1097,6 +1065,12 @@ func (is *ImageStore) CheckBlob(repo string, digest string,
|
||||
return false, -1, errors.ErrBlobNotFound
|
||||
}
|
||||
|
||||
if err := is.cache.PutBlob(digest, blobPath); err != nil {
|
||||
is.log.Error().Err(err).Str("blobPath", blobPath).Msg("dedupe: unable to insert blob record")
|
||||
|
||||
return false, -1, err
|
||||
}
|
||||
|
||||
return true, blobSize, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ func TestAPIs(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
So(b, ShouldEqual, l)
|
||||
|
||||
_, _, err = il.CheckBlob("test", d.String(), "application/vnd.oci.image.layer.v1.tar+gzip")
|
||||
_, _, err = il.CheckBlob("test", d.String())
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
_, _, err = il.GetBlob("test", d.String(), "application/vnd.oci.image.layer.v1.tar+gzip")
|
||||
@@ -201,7 +201,7 @@ func TestAPIs(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
So(b, ShouldEqual, l)
|
||||
|
||||
_, _, err = il.CheckBlob("test", d.String(), "application/vnd.oci.image.layer.v1.tar+gzip")
|
||||
_, _, err = il.CheckBlob("test", d.String())
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
_, _, err = il.GetBlob("test", d.String(), "application/vnd.oci.image.layer.v1.tar+gzip")
|
||||
@@ -363,7 +363,7 @@ func TestAPIs(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
So(b, ShouldEqual, l)
|
||||
|
||||
_, _, err = il.CheckBlob("dedupe1", d.String(), "application/vnd.oci.image.layer.v1.tar+gzip")
|
||||
_, _, err = il.CheckBlob("dedupe1", d.String())
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
_, _, err = il.GetBlob("dedupe1", d.String(), "application/vnd.oci.image.layer.v1.tar+gzip")
|
||||
@@ -412,7 +412,7 @@ func TestAPIs(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
So(b, ShouldEqual, l)
|
||||
|
||||
_, _, err = il.CheckBlob("dedupe2", d.String(), "application/vnd.oci.image.layer.v1.tar+gzip")
|
||||
_, _, err = il.CheckBlob("dedupe2", d.String())
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
_, _, err = il.GetBlob("dedupe2", d.String(), "application/vnd.oci.image.layer.v1.tar+gzip")
|
||||
|
||||
Reference in New Issue
Block a user