alittle splitted mstorectl code; etc

This commit is contained in:
2026-03-05 12:26:14 +02:00
parent 80d6a244cf
commit 223ae2e96e
24 changed files with 631 additions and 104 deletions
+69
View File
@@ -0,0 +1,69 @@
/*
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
*
* This work is published and licensed under a Creative Commons
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
*
* Distribution of this work is permitted, but commercial use and
* modifications are strictly prohibited.
*/
package imageoper
import (
"context"
"fmt"
"net/http"
"strconv"
)
type BlobExistsParams struct {
Name string
Digest string
}
type BlobExistsResult struct {
DockerContentDigest string
ContentLength string
ContentType string
//Exists bool
}
func (oper *Operator) BlobExists(ctx context.Context, operatorID string, params *BlobExistsParams) (*BlobExistsResult, int, error) {
var err error
res := &BlobExistsResult{}
if params.Digest == "" {
err = fmt.Errorf("Empty reference")
return res, http.StatusBadRequest, err
}
if params.Name == "" {
err = fmt.Errorf("Empty name")
return res, http.StatusBadRequest, err
}
resName := params.Name
oper.iLock.WaitAndLock(resName)
defer oper.iLock.Done(resName)
// Check blob descriptor
descrExists, blobDescr, err := oper.mdb.GetBlobByNameDigest(ctx, params.Digest, params.Digest)
if err != nil {
return res, http.StatusInternalServerError, err
}
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 = blobDescr.Digest
res.ContentType = blobDescr.MediaType
return res, http.StatusOK, err
}