Files
mstore/pkg/repocli/delblob.go
T
2026-03-11 19:47:40 +02:00

48 lines
1.1 KiB
Go

/*
* 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 repocli
import (
"context"
"fmt"
"net/http"
)
func (cli *Client) DeleteBlob(ctx context.Context, rawrepo, digest string) (bool, error) {
var err error
var exist bool
ref, err := NewReferer(rawrepo)
if err != nil {
return exist, err
}
uri := ref.BlobEP(digest)
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, uri, nil)
if err != nil {
return exist, err
}
req.Header.Set("User-Agent", cli.userAgent)
req.Header.Set("Accept", "*/*")
resp, err := cli.httpClient.Do(req)
if err != nil {
return exist, err
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusNotFound {
return exist, err
}
if resp.StatusCode != http.StatusOK {
err := fmt.Errorf("Unxected response code %s", resp.Status)
return exist, err
}
exist = true
return exist, err
}