diff --git a/routers/api/packages/container/blob.go b/routers/api/packages/container/blob.go index 8a9cbd4a1..ab29541d7 100644 --- a/routers/api/packages/container/blob.go +++ b/routers/api/packages/container/blob.go @@ -23,7 +23,7 @@ import ( // The uploaded blob gets stored in a special upload version to link them to the package/image func saveAsPackageBlob(hsr packages_module.HashedSizeReader, pi *packages_service.PackageInfo) (*packages_model.PackageBlob, error) { pb := packages_service.NewPackageBlob(hsr) - + fmt.Println("saveAsPackageBlob: ", pb.HashSHA256) exists := false contentStore := packages_module.NewContentStore() @@ -45,7 +45,7 @@ func saveAsPackageBlob(hsr packages_module.HashedSizeReader, pi *packages_servic return err } } - + fmt.Println("CREATED!!!") if created { if _, err := packages_model.InsertProperty(ctx, packages_model.PropertyTypePackage, p.ID, container_module.PropertyRepository, strings.ToLower(pi.Owner.LowerName+"/"+pi.Name)); err != nil { log.Error("Error setting package property: %v", err) @@ -73,6 +73,16 @@ func saveAsPackageBlob(hsr packages_module.HashedSizeReader, pi *packages_servic log.Error("Error inserting package blob: %v", err) return err } + if exists { + _, err := contentStore.Get(packages_module.BlobHash256Key(pb.HashSHA256)) + if err != nil { + log.Info("BLOB MODEL and ERR in ContentStore. Resaving Blob to content store ", err.Error()) + if err := contentStore.Save(packages_module.BlobHash256Key(pb.HashSHA256), hsr, hsr.Size()); err != nil { + log.Error("Error saving package blob in content store during FIXITUP: %v", err) + return err + } + } + } if !exists { if err := contentStore.Save(packages_module.BlobHash256Key(pb.HashSHA256), hsr, hsr.Size()); err != nil { log.Error("Error saving package blob in content store: %v", err) diff --git a/routers/api/packages/container/container.go b/routers/api/packages/container/container.go index b961cd4af..d4e982f2e 100644 --- a/routers/api/packages/container/container.go +++ b/routers/api/packages/container/container.go @@ -379,7 +379,23 @@ 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 { + log.Warn("ContentStore Get Error while HEAD for Blob: ", blob.Blob.HashSHA256, err.Error()) + digest := ctx.Params("digest") + + if err := deleteBlob(ctx.Package.Owner.ID, ctx.Params("image"), digest); err != nil { + log.Warn("Error while deleteBlob in HEAD: ", err.Error()) + } + apiErrorDefined(ctx, errBlobUnknown) + return + } + defer configReader.Close() setResponseHeaders(ctx.Resp, &containerHeaders{ ContentDigest: blob.Properties.GetByName(container_module.PropertyDigest), ContentLength: blob.Blob.Size, diff --git a/services/packages/packages.go b/services/packages/packages.go index 985d06a1b..3ab3c187b 100644 --- a/services/packages/packages.go +++ b/services/packages/packages.go @@ -224,7 +224,6 @@ 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) - pb, exists, err := packages_model.GetOrInsertBlob(ctx, NewPackageBlob(pfci.Data)) if err != nil { log.Error("Error inserting package blob: %v", err)