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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"path"
|
||||
|
||||
@ -27,11 +28,13 @@ func NewContentStore() *ContentStore {
|
||||
|
||||
// Get gets a package blob
|
||||
func (s *ContentStore) Get(key BlobHash256Key) (storage.Object, error) {
|
||||
fmt.Println("Get from ContentStore: ", key)
|
||||
return s.store.Open(KeyToRelativePath(key))
|
||||
}
|
||||
|
||||
// Save stores a package blob
|
||||
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)
|
||||
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
|
||||
func HeadBlob(ctx *context.Context) {
|
||||
blob, err := getBlobFromContext(ctx)
|
||||
fmt.Println("HeadBlob: ", blob.File.CompositeKey)
|
||||
if err != nil {
|
||||
fmt.Println("getBlobFromContext err: ", err.Error())
|
||||
if err == container_model.ErrContainerBlobNotExist {
|
||||
apiErrorDefined(ctx, errBlobUnknown)
|
||||
} else {
|
||||
@ -379,7 +381,31 @@ func HeadBlob(ctx *context.Context) {
|
||||
}
|
||||
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{
|
||||
ContentDigest: blob.Properties.GetByName(container_module.PropertyDigest),
|
||||
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) {
|
||||
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))
|
||||
if err != nil {
|
||||
log.Error("Error inserting package blob: %v", err)
|
||||
|
Loading…
Reference in New Issue
Block a user