Skip to content

Commit a87c190

Browse files
authored
fix: check tag or digest before remove the manifest (#116)
Signed-off-by: chlins <[email protected]>
1 parent b639231 commit a87c190

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/minio/sha256-simd v1.0.1
1313
github.com/opencontainers/go-digest v1.0.0
1414
github.com/opencontainers/image-spec v1.1.0
15+
github.com/sirupsen/logrus v1.9.3
1516
github.com/spf13/cobra v1.9.1
1617
github.com/spf13/viper v1.19.0
1718
github.com/stretchr/testify v1.10.0
@@ -56,7 +57,6 @@ require (
5657
github.com/rivo/uniseg v0.4.7 // indirect
5758
github.com/sagikazarmark/locafero v0.6.0 // indirect
5859
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
59-
github.com/sirupsen/logrus v1.9.3 // indirect
6060
github.com/sourcegraph/conc v0.3.0 // indirect
6161
github.com/spf13/afero v1.11.0 // indirect
6262
github.com/spf13/cast v1.7.0 // indirect

pkg/backend/rm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func (b *backend) Remove(ctx context.Context, target string) (string, error) {
3636
reference = ref.Digest()
3737
}
3838

39+
if reference == "" {
40+
return "", fmt.Errorf("invalid reference, tag or digest must be provided")
41+
}
42+
3943
if err := b.store.DeleteManifest(ctx, repo, reference); err != nil {
4044
return "", fmt.Errorf("failed to delete manifest %s: %w", reference, err)
4145
}

pkg/storage/distribution/distribution.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
sha256 "github.com/minio/sha256-simd"
3131
godigest "github.com/opencontainers/go-digest"
3232
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
33+
"github.com/sirupsen/logrus"
3334
)
3435

3536
func init() {
@@ -55,6 +56,9 @@ type storage struct {
5556
}
5657

5758
func NewStorage(rootDir string) (*storage, error) {
59+
// Mute the logging from distribution.
60+
logrus.SetOutput(io.Discard)
61+
5862
fsDriver := filesystem.New(filesystem.DriverParameters{
5963
RootDirectory: rootDir,
6064
MaxThreads: defaultMaxThreads,

0 commit comments

Comments
 (0)