Skip to content

Commit bb7b937

Browse files
author
Zhou Hao
authored
Merge pull request #173 from q384566678/validate-ref-fix
validate: Increase ref content repeat detection
2 parents 974de27 + a154aa1 commit bb7b937

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

cmd/oci-image-tool/create.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ func createAction(context *cli.Context) error {
5252
return fmt.Errorf("ref must be provided")
5353
}
5454

55+
for index, ref := range v.refs {
56+
for i := index + 1; i < len(v.refs); i++ {
57+
if ref == v.refs[i] {
58+
fmt.Printf("WARNING: refs contains duplicate reference %q.\n", v.refs[i])
59+
}
60+
}
61+
}
62+
5563
if v.typ == "" {
5664
typ, err := image.Autodetect(context.Args()[0])
5765
if err != nil {

cmd/oci-image-tool/unpack.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ func unpackAction(context *cli.Context) error {
5050
return fmt.Errorf("ref must be provided")
5151
}
5252

53+
for index, ref := range v.refs {
54+
for i := index + 1; i < len(v.refs); i++ {
55+
if ref == v.refs[i] {
56+
fmt.Printf("WARNING: refs contains duplicate reference %q.\n", v.refs[i])
57+
}
58+
}
59+
}
60+
5361
if v.typ == "" {
5462
typ, err := image.Autodetect(context.Args()[0])
5563
if err != nil {

cmd/oci-image-tool/validate.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ func validateAction(context *cli.Context) error {
5454
refs: context.StringSlice("ref"),
5555
}
5656

57+
for index, ref := range v.refs {
58+
for i := index + 1; i < len(v.refs); i++ {
59+
if ref == v.refs[i] {
60+
fmt.Printf("WARNING: refs contains duplicate reference %q.\n", v.refs[i])
61+
}
62+
}
63+
}
64+
5765
var errs []string
5866
for _, arg := range context.Args() {
5967
err := validatePath(arg)

0 commit comments

Comments
 (0)