@@ -10,6 +10,7 @@ import (
1010 "io"
1111 "net/http"
1212 "net/url"
13+ "os"
1314 "regexp"
1415 "strconv"
1516 "strings"
@@ -24,6 +25,7 @@ import (
2425 container_module "code.gitea.io/gitea/modules/packages/container"
2526 "code.gitea.io/gitea/modules/packages/container/oci"
2627 "code.gitea.io/gitea/modules/setting"
28+ "code.gitea.io/gitea/modules/util"
2729 "code.gitea.io/gitea/routers/api/packages/helper"
2830 packages_service "code.gitea.io/gitea/services/packages"
2931 container_service "code.gitea.io/gitea/services/packages/container"
@@ -193,7 +195,7 @@ func InitiateUploadBlob(ctx *context.Context) {
193195 mount := ctx .FormTrim ("mount" )
194196 from := ctx .FormTrim ("from" )
195197 if mount != "" {
196- blob , _ := container_model . GetContainerBlob (ctx , & container_model.BlobSearchOptions {
198+ blob , _ := workaroundGetContainerBlob (ctx , & container_model.BlobSearchOptions {
197199 Image : from ,
198200 Digest : mount ,
199201 })
@@ -406,7 +408,7 @@ func getBlobFromContext(ctx *context.Context) (*packages_model.PackageFileDescri
406408 return nil , container_model .ErrContainerBlobNotExist
407409 }
408410
409- return container_model . GetContainerBlob (ctx , & container_model.BlobSearchOptions {
411+ return workaroundGetContainerBlob (ctx , & container_model.BlobSearchOptions {
410412 OwnerID : ctx .Package .Owner .ID ,
411413 Image : ctx .Params ("image" ),
412414 Digest : digest ,
@@ -548,7 +550,7 @@ func getManifestFromContext(ctx *context.Context) (*packages_model.PackageFileDe
548550 return nil , container_model .ErrContainerBlobNotExist
549551 }
550552
551- return container_model . GetContainerBlob (ctx , opts )
553+ return workaroundGetContainerBlob (ctx , opts )
552554}
553555
554556// https://github.com/opencontainers/distribution-spec/blob/main/spec.md#checking-if-content-exists-in-the-registry
@@ -688,3 +690,23 @@ func GetTagList(ctx *context.Context) {
688690 Tags : tags ,
689691 })
690692}
693+
694+ // FIXME: Workaround to be removed in v1.20
695+ // https://github.com/go-gitea/gitea/issues/19586
696+ func workaroundGetContainerBlob (ctx * context.Context , opts * container_model.BlobSearchOptions ) (* packages_model.PackageFileDescriptor , error ) {
697+ blob , err := container_model .GetContainerBlob (ctx , opts )
698+ if err != nil {
699+ return nil , err
700+ }
701+
702+ err = packages_module .NewContentStore ().Has (packages_module .BlobHash256Key (blob .Blob .HashSHA256 ))
703+ if err != nil {
704+ if errors .Is (err , util .ErrNotExist ) || errors .Is (err , os .ErrNotExist ) {
705+ log .Debug ("Package registry inconsistent: blob %s does not exist on file system" , blob .Blob .HashSHA256 )
706+ return nil , container_model .ErrContainerBlobNotExist
707+ }
708+ return nil , err
709+ }
710+
711+ return blob , nil
712+ }
0 commit comments