HEAD check for container blobs deletes blob if content store cannot find
This commit is contained in:
parent
3c07ed0911
commit
31d9079c7c
@ -5,6 +5,7 @@
|
|||||||
package packages
|
package packages
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
@ -27,11 +28,13 @@ func NewContentStore() *ContentStore {
|
|||||||
|
|
||||||
// Get gets a package blob
|
// Get gets a package blob
|
||||||
func (s *ContentStore) Get(key BlobHash256Key) (storage.Object, error) {
|
func (s *ContentStore) Get(key BlobHash256Key) (storage.Object, error) {
|
||||||
|
fmt.Println("Get from ContentStore: ", key)
|
||||||
return s.store.Open(KeyToRelativePath(key))
|
return s.store.Open(KeyToRelativePath(key))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save stores a package blob
|
// Save stores a package blob
|
||||||
func (s *ContentStore) Save(key BlobHash256Key, r io.Reader, size int64) error {
|
func (s *ContentStore) Save(key BlobHash256Key, r io.Reader, size int64) error {
|
||||||
|
fmt.Println("Save to ContentStore: ", key)
|
||||||
_, err := s.store.Save(KeyToRelativePath(key), r, size)
|
_, err := s.store.Save(KeyToRelativePath(key), r, size)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -371,7 +371,9 @@ func getBlobFromContext(ctx *context.Context) (*packages_model.PackageFileDescri
|
|||||||
// https://github.com/opencontainers/distribution-spec/blob/main/spec.md#checking-if-content-exists-in-the-registry
|
// https://github.com/opencontainers/distribution-spec/blob/main/spec.md#checking-if-content-exists-in-the-registry
|
||||||
func HeadBlob(ctx *context.Context) {
|
func HeadBlob(ctx *context.Context) {
|
||||||
blob, err := getBlobFromContext(ctx)
|
blob, err := getBlobFromContext(ctx)
|
||||||
|
fmt.Println("HeadBlob: ", blob.File.CompositeKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("getBlobFromContext err: ", err.Error())
|
||||||
if err == container_model.ErrContainerBlobNotExist {
|
if err == container_model.ErrContainerBlobNotExist {
|
||||||
apiErrorDefined(ctx, errBlobUnknown)
|
apiErrorDefined(ctx, errBlobUnknown)
|
||||||
} else {
|
} else {
|
||||||
@ -379,7 +381,31 @@ func HeadBlob(ctx *context.Context) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//check if actually in ContentStore
|
||||||
|
//if not, delete Blob and return 404
|
||||||
|
//content_store.Get()
|
||||||
|
cStore := packages_module.NewContentStore()
|
||||||
|
configReader, err := cStore.Get(packages_module.BlobHash256Key(blob.Blob.HashSHA256))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("ContentStore Get Error: ", blob.Blob.HashSHA256, err.Error())
|
||||||
|
|
||||||
|
digest := ctx.Params("digest")
|
||||||
|
|
||||||
|
if !oci.Digest(digest).Validate() {
|
||||||
|
fmt.Println("digest Validate false: ", digest)
|
||||||
|
//apiErrorDefined(ctx, errBlobUnknown)
|
||||||
|
//return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := deleteBlob(ctx.Package.Owner.ID, ctx.Params("image"), digest); err != nil {
|
||||||
|
fmt.Println("Error while deleteBlob: ", err.Error())
|
||||||
|
//apiError(ctx, http.StatusInternalServerError, err)
|
||||||
|
//return
|
||||||
|
}
|
||||||
|
apiErrorDefined(ctx, errBlobUnknown)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer configReader.Close()
|
||||||
setResponseHeaders(ctx.Resp, &containerHeaders{
|
setResponseHeaders(ctx.Resp, &containerHeaders{
|
||||||
ContentDigest: blob.Properties.GetByName(container_module.PropertyDigest),
|
ContentDigest: blob.Properties.GetByName(container_module.PropertyDigest),
|
||||||
ContentLength: blob.Blob.Size,
|
ContentLength: blob.Blob.Size,
|
||||||
|
@ -224,7 +224,7 @@ func NewPackageBlob(hsr packages_module.HashedSizeReader) *packages_model.Packag
|
|||||||
|
|
||||||
func addFileToPackageVersion(ctx context.Context, pv *packages_model.PackageVersion, pfci *PackageFileCreationInfo) (*packages_model.PackageFile, *packages_model.PackageBlob, bool, error) {
|
func addFileToPackageVersion(ctx context.Context, pv *packages_model.PackageVersion, pfci *PackageFileCreationInfo) (*packages_model.PackageFile, *packages_model.PackageBlob, bool, error) {
|
||||||
log.Trace("Adding package file: %v, %s", pv.ID, pfci.Filename)
|
log.Trace("Adding package file: %v, %s", pv.ID, pfci.Filename)
|
||||||
|
fmt.Println("AddFileToPackageVersion: ", pfci.Filename)
|
||||||
pb, exists, err := packages_model.GetOrInsertBlob(ctx, NewPackageBlob(pfci.Data))
|
pb, exists, err := packages_model.GetOrInsertBlob(ctx, NewPackageBlob(pfci.Data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error inserting package blob: %v", err)
|
log.Error("Error inserting package blob: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user