From a154aa1b670018ed73c9762044c4b82ec5a6dd17 Mon Sep 17 00:00:00 2001 From: zhouhao Date: Mon, 21 Aug 2017 09:57:16 +0800 Subject: [PATCH] validate: Increase ref content repeat detection Signed-off-by: zhouhao --- cmd/oci-image-tool/create.go | 8 ++++++++ cmd/oci-image-tool/unpack.go | 8 ++++++++ cmd/oci-image-tool/validate.go | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/cmd/oci-image-tool/create.go b/cmd/oci-image-tool/create.go index a37d912..7be454b 100644 --- a/cmd/oci-image-tool/create.go +++ b/cmd/oci-image-tool/create.go @@ -52,6 +52,14 @@ func createAction(context *cli.Context) error { return fmt.Errorf("ref must be provided") } + for index, ref := range v.refs { + for i := index + 1; i < len(v.refs); i++ { + if ref == v.refs[i] { + fmt.Printf("WARNING: refs contains duplicate reference %q.\n", v.refs[i]) + } + } + } + if v.typ == "" { typ, err := image.Autodetect(context.Args()[0]) if err != nil { diff --git a/cmd/oci-image-tool/unpack.go b/cmd/oci-image-tool/unpack.go index 1256d08..7e0c64a 100644 --- a/cmd/oci-image-tool/unpack.go +++ b/cmd/oci-image-tool/unpack.go @@ -50,6 +50,14 @@ func unpackAction(context *cli.Context) error { return fmt.Errorf("ref must be provided") } + for index, ref := range v.refs { + for i := index + 1; i < len(v.refs); i++ { + if ref == v.refs[i] { + fmt.Printf("WARNING: refs contains duplicate reference %q.\n", v.refs[i]) + } + } + } + if v.typ == "" { typ, err := image.Autodetect(context.Args()[0]) if err != nil { diff --git a/cmd/oci-image-tool/validate.go b/cmd/oci-image-tool/validate.go index 6072d7d..64a8958 100644 --- a/cmd/oci-image-tool/validate.go +++ b/cmd/oci-image-tool/validate.go @@ -54,6 +54,14 @@ func validateAction(context *cli.Context) error { refs: context.StringSlice("ref"), } + for index, ref := range v.refs { + for i := index + 1; i < len(v.refs); i++ { + if ref == v.refs[i] { + fmt.Printf("WARNING: refs contains duplicate reference %q.\n", v.refs[i]) + } + } + } + var errs []string for _, arg := range context.Args() { err := validatePath(arg)