@@ -10,6 +10,7 @@ import (
10
10
"io"
11
11
"net/http"
12
12
"net/url"
13
+ "os"
13
14
"regexp"
14
15
"strconv"
15
16
"strings"
@@ -24,6 +25,7 @@ import (
24
25
container_module "code.gitea.io/gitea/modules/packages/container"
25
26
"code.gitea.io/gitea/modules/packages/container/oci"
26
27
"code.gitea.io/gitea/modules/setting"
28
+ "code.gitea.io/gitea/modules/util"
27
29
"code.gitea.io/gitea/routers/api/packages/helper"
28
30
packages_service "code.gitea.io/gitea/services/packages"
29
31
container_service "code.gitea.io/gitea/services/packages/container"
@@ -193,7 +195,7 @@ func InitiateUploadBlob(ctx *context.Context) {
193
195
mount := ctx .FormTrim ("mount" )
194
196
from := ctx .FormTrim ("from" )
195
197
if mount != "" {
196
- blob , _ := container_model . GetContainerBlob (ctx , & container_model.BlobSearchOptions {
198
+ blob , _ := workaroundGetContainerBlob (ctx , & container_model.BlobSearchOptions {
197
199
Image : from ,
198
200
Digest : mount ,
199
201
})
@@ -406,7 +408,7 @@ func getBlobFromContext(ctx *context.Context) (*packages_model.PackageFileDescri
406
408
return nil , container_model .ErrContainerBlobNotExist
407
409
}
408
410
409
- return container_model . GetContainerBlob (ctx , & container_model.BlobSearchOptions {
411
+ return workaroundGetContainerBlob (ctx , & container_model.BlobSearchOptions {
410
412
OwnerID : ctx .Package .Owner .ID ,
411
413
Image : ctx .Params ("image" ),
412
414
Digest : digest ,
@@ -548,7 +550,7 @@ func getManifestFromContext(ctx *context.Context) (*packages_model.PackageFileDe
548
550
return nil , container_model .ErrContainerBlobNotExist
549
551
}
550
552
551
- return container_model . GetContainerBlob (ctx , opts )
553
+ return workaroundGetContainerBlob (ctx , opts )
552
554
}
553
555
554
556
// 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) {
688
690
Tags : tags ,
689
691
})
690
692
}
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