working commit

This commit is contained in:
2026-02-06 09:27:45 +02:00
parent 4f01100473
commit 88bfe00d61
11 changed files with 246 additions and 302 deletions
+30 -30
View File
@@ -17,7 +17,8 @@ type BlobExistsParams struct {
type BlobExistsResult struct {
DockerContentDigest string
ContentLength string
Exists bool
ContentType string
//Exists bool
}
func (oper *Operator) BlobExists(ctx context.Context, params *BlobExistsParams) (*BlobExistsResult, int, error) {
@@ -32,37 +33,30 @@ func (oper *Operator) BlobExists(ctx context.Context, params *BlobExistsParams)
err = fmt.Errorf("Empty name")
return res, http.StatusBadRequest, err
}
exists, blobDescr, err := oper.mdb.GetBlobByDigest(ctx, params.Digest)
// Check blob descriptor
descrExists, blobDescr, err := oper.mdb.GetBlobByNameDigest(ctx, params.Digest, params.Digest)
if err != nil {
return res, http.StatusInternalServerError, err
}
if !exists {
if !descrExists {
return res, http.StatusNotFound, err
}
// Check blob file
blobExists, _, err := oper.store.BlobExists(params.Digest)
if err != nil {
return res, http.StatusInternalServerError, err
}
if !blobExists {
return res, http.StatusNotFound, err
}
res.ContentLength = strconv.FormatInt(blobDescr.Size, 10)
res.DockerContentDigest = params.Digest
res.Exists = exists
res.DockerContentDigest = blobDescr.Digest
res.ContentType = blobDescr.MediaType
return res, http.StatusOK, err
}
// https://github.com/opencontainers/distribution-spec/blob/v1.1.1/spec.md
//
// PostUpload
//
// POST then PUT
//
// To push a blob monolithically by using a POST request followed by a PUT request, there are two steps:
//
// - Obtain a session id (upload URL)
// - Upload the blob to said URL
//
// A chunked blob upload is accomplished in three phases:
//
// - Obtain a session ID (upload URL) (POST)
// - Upload the chunks (PATCH)
// Close the session (PUT)
type PostUploadParams struct {
Name string
Digest string
@@ -106,11 +100,6 @@ type PatchUploadResult struct {
Range string
}
// The response for each successful chunk upload MUST be 202 Accepted, and MUST have the following headers:
//
// Location: <location>
// Range: 0-<end-of-range>
func (oper *Operator) PatchUpload(ctx context.Context, params *PatchUploadParams) (*PatchUploadResult, int, error) {
var err error
res := &PatchUploadResult{}
@@ -250,7 +239,11 @@ func (oper *Operator) GetBlob(ctx context.Context, params *GetBlobParams) (*GetB
if err != nil {
return res, http.StatusInternalServerError, err
}
if !blobExists {
descrExist, blobDescr, err := oper.mdb.GetBlobByNameDigest(ctx, params.Name, params.Digest)
if err != nil {
return res, http.StatusInternalServerError, err
}
if !blobExists || !descrExist {
return res, http.StatusNotFound, err
}
@@ -259,6 +252,7 @@ func (oper *Operator) GetBlob(ctx context.Context, params *GetBlobParams) (*GetB
return res, http.StatusInternalServerError, err
}
res.ContentType = blobDescr.MediaType
res.ContentLength = strconv.FormatInt(blobSize, 10)
res.DockerContentDigest = params.Digest
res.ReadCloser = readCloser
@@ -284,19 +278,25 @@ func (oper *Operator) DeleteBlob(ctx context.Context, params *DeleteBlobParams)
return res, http.StatusBadRequest, err
}
// Check namespace record
exists, _, err := oper.mdb.GetBlobByNameDigest(ctx, params.Name, params.Digest)
descrExists, _, err := oper.mdb.GetBlobByNameDigest(ctx, params.Name, params.Digest)
if err != nil {
return res, http.StatusInternalServerError, err
}
if !exists {
oper.logg.Debugf("Blob %s:%s descr exists %v", params.Name, params.Digest, descrExists)
if !descrExists {
return res, http.StatusNotFound, err
}
err = oper.mdb.DeleteBlobByNameDigest(ctx, params.Name, params.Digest)
if err != nil {
return res, http.StatusInternalServerError, err
}
// Removing blob file if usage == 0
blobUsage, err := oper.mdb.GetBlobUsage(ctx, params.Digest)
oper.logg.Debugf("Blob %s have usage %d", params.Digest, blobUsage)
if err != nil {
return res, http.StatusInternalServerError, err
}