From 99215e40e9fbe6baa2b0a45212064914136c1203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Thu, 2 Feb 2023 21:20:51 +0100 Subject: [PATCH 01/10] Remove a duplicate word MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit golangci-lint linter: dupword Signed-off-by: Miloslav Trmač --- cmd/skopeo/sync.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/skopeo/sync.go b/cmd/skopeo/sync.go index 1c86acf5..392d7696 100644 --- a/cmd/skopeo/sync.go +++ b/cmd/skopeo/sync.go @@ -132,7 +132,7 @@ See skopeo-sync(1) for details. } // UnmarshalYAML is the implementation of the Unmarshaler interface method -// method for the tlsVerifyConfig type. +// for the tlsVerifyConfig type. // It unmarshals the 'tls-verify' YAML key so that, when they key is not // specified, tls verification is enforced. func (tls *tlsVerifyConfig) UnmarshalYAML(value *yaml.Node) error { From a8b9e4e385046ffb1be42e52f31c35b26a0ab12f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Thu, 2 Feb 2023 21:21:24 +0100 Subject: [PATCH 02/10] Use %w when wrapping errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit golangci-lint linter: errorlint Signed-off-by: Miloslav Trmač --- integration/proxy_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integration/proxy_test.go b/integration/proxy_test.go index 687c6ed4..881ea1d9 100644 --- a/integration/proxy_test.go +++ b/integration/proxy_test.go @@ -81,7 +81,7 @@ func (p *proxy) call(method string, args []any) (rval any, fd *pipefd, err error replybuf := make([]byte, maxMsgSize) n, oobn, _, _, err := p.c.ReadMsgUnix(replybuf, oob) if err != nil { - err = fmt.Errorf("reading reply: %v", err) + err = fmt.Errorf("reading reply: %w", err) return } var reply reply @@ -99,7 +99,7 @@ func (p *proxy) call(method string, args []any) (rval any, fd *pipefd, err error var scms []syscall.SocketControlMessage scms, err = syscall.ParseSocketControlMessage(oob[:oobn]) if err != nil { - err = fmt.Errorf("failed to parse control message: %v", err) + err = fmt.Errorf("failed to parse control message: %w", err) return } if len(scms) != 1 { @@ -109,7 +109,7 @@ func (p *proxy) call(method string, args []any) (rval any, fd *pipefd, err error var fds []int fds, err = syscall.ParseUnixRights(&scms[0]) if err != nil { - err = fmt.Errorf("failed to parse unix rights: %v", err) + err = fmt.Errorf("failed to parse unix rights: %w", err) return } fd = &pipefd{ From efc6e837c6568fa435e0858bb4d970be69c9ff31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Thu, 2 Feb 2023 21:23:10 +0100 Subject: [PATCH 03/10] Reformat import statements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit golangci-lint linter: gci Signed-off-by: Miloslav Trmač --- integration/proxy_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/integration/proxy_test.go b/integration/proxy_test.go index 881ea1d9..aca1f119 100644 --- a/integration/proxy_test.go +++ b/integration/proxy_test.go @@ -11,10 +11,9 @@ import ( "syscall" "time" - "gopkg.in/check.v1" - "github.com/containers/image/v5/manifest" imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1" + "gopkg.in/check.v1" ) // This image is known to be x86_64 only right now From 9137ac5697bb3db308c4176824e412024a8753bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Thu, 2 Feb 2023 21:24:03 +0100 Subject: [PATCH 04/10] Simplify an increment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit golangci-lint linter: gocritic Signed-off-by: Miloslav Trmač --- integration/copy_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/copy_test.go b/integration/copy_test.go index ee530b04..8362201c 100644 --- a/integration/copy_test.go +++ b/integration/copy_test.go @@ -567,7 +567,7 @@ func matchLayerBlobBinaryType(c *check.C, ociImageDirPath string, contentType st c.Assert(err, check.IsNil) if layerContentType == contentType { - foundCount = foundCount + 1 + foundCount++ } } From 70c06b4ac0b9d2d30bd2842308a2b08048c664cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Thu, 2 Feb 2023 21:24:59 +0100 Subject: [PATCH 05/10] Fix, or remove, comments using lint syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit golangci-lint linter: gocritic Signed-off-by: Miloslav Trmač --- integration/check_test.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/integration/check_test.go b/integration/check_test.go index 56f245e4..6b6a9c64 100644 --- a/integration/check_test.go +++ b/integration/check_test.go @@ -39,15 +39,12 @@ func (s *SkopeoSuite) TearDownSuite(c *check.C) { s.regV2.tearDown(c) } if s.regV2WithAuth != nil { - //cmd := exec.Command("docker", "logout", s.regV2WithAuth) - //c.Assert(cmd.Run(), check.IsNil) + // cmd := exec.Command("docker", "logout", s.regV2WithAuth) + // c.Assert(cmd.Run(), check.IsNil) s.regV2WithAuth.tearDown(c) } } -// TODO like dockerCmd but much easier, just out,err -//func skopeoCmd() - func (s *SkopeoSuite) TestVersion(c *check.C) { assertSkopeoSucceeds(c, fmt.Sprintf(".*%s version %s.*", skopeoBinary, version.Version), "--version") From e90c381a02615b7d5bad9e6881a61fd362f53d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Thu, 2 Feb 2023 21:26:11 +0100 Subject: [PATCH 06/10] Add missing comment punctuation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit golangci-lint linter: godot Signed-off-by: Miloslav Trmač --- integration/openshift.go | 2 +- integration/procutils.go | 2 +- integration/utils.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integration/openshift.go b/integration/openshift.go index 635d010d..c822c560 100644 --- a/integration/openshift.go +++ b/integration/openshift.go @@ -44,7 +44,7 @@ func startOpenshiftCluster(c *check.C) *openshiftCluster { return cluster } -// clusterCmd creates an exec.Cmd in cluster.workingDir with current environment modified by environment +// clusterCmd creates an exec.Cmd in cluster.workingDir with current environment modified by environment. func (cluster *openshiftCluster) clusterCmd(env map[string]string, name string, args ...string) *exec.Cmd { cmd := exec.Command(name, args...) cmd.Dir = cluster.workingDir diff --git a/integration/procutils.go b/integration/procutils.go index c6a59f18..e53f94b5 100644 --- a/integration/procutils.go +++ b/integration/procutils.go @@ -7,6 +7,6 @@ import ( "os/exec" ) -// cmdLifecycleToParentIfPossible tries to exit if the parent process exits (only works on Linux) +// cmdLifecycleToParentIfPossible tries to exit if the parent process exits (only works on Linux). func cmdLifecycleToParentIfPossible(c *exec.Cmd) { } diff --git a/integration/utils.go b/integration/utils.go index b1b7f7b9..b1e049c4 100644 --- a/integration/utils.go +++ b/integration/utils.go @@ -42,7 +42,7 @@ func consumeAndLogOutputStream(c *check.C, id string, f io.ReadCloser, err error }() } -// consumeAndLogOutputs causes all output to stdout and stderr from an *exec.Cmd to be logged to c +// consumeAndLogOutputs causes all output to stdout and stderr from an *exec.Cmd to be logged to c. func consumeAndLogOutputs(c *check.C, id string, cmd *exec.Cmd) { stdout, err := cmd.StdoutPipe() consumeAndLogOutputStream(c, id+" stdout", stdout, err) From e7ab33e65f676e949e66a059e4cf67fa1b1c253e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Thu, 2 Feb 2023 21:27:08 +0100 Subject: [PATCH 07/10] Rename a variable to avoid an underscore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit golangci-lint linter: golint Signed-off-by: Miloslav Trmač --- integration/proxy_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/integration/proxy_test.go b/integration/proxy_test.go index aca1f119..7fd794b4 100644 --- a/integration/proxy_test.go +++ b/integration/proxy_test.go @@ -17,7 +17,7 @@ import ( ) // This image is known to be x86_64 only right now -const knownNotManifestListedImage_x8664 = "docker://quay.io/coreos/11bot" +const knownNotManifestListedImageX8664 = "docker://quay.io/coreos/11bot" // knownNotExtantImage would be very surprising if it did exist const knownNotExtantImage = "docker://quay.io/centos/centos:opensusewindowsubuntu" @@ -232,7 +232,7 @@ type byteFetch struct { } func runTestGetManifestAndConfig(p *proxy, img string) error { - v, err := p.callNoFd("OpenImage", []any{knownNotManifestListedImage_x8664}) + v, err := p.callNoFd("OpenImage", []any{knownNotManifestListedImageX8664}) if err != nil { return err } @@ -247,7 +247,7 @@ func runTestGetManifestAndConfig(p *proxy, img string) error { } // Also verify the optional path - v, err = p.callNoFd("OpenImageOptional", []any{knownNotManifestListedImage_x8664}) + v, err = p.callNoFd("OpenImageOptional", []any{knownNotManifestListedImageX8664}) if err != nil { return err } @@ -338,9 +338,9 @@ func (s *ProxySuite) TestProxy(c *check.C) { p, err := newProxy() c.Assert(err, check.IsNil) - err = runTestGetManifestAndConfig(p, knownNotManifestListedImage_x8664) + err = runTestGetManifestAndConfig(p, knownNotManifestListedImageX8664) if err != nil { - err = fmt.Errorf("Testing image %s: %v", knownNotManifestListedImage_x8664, err) + err = fmt.Errorf("Testing image %s: %v", knownNotManifestListedImageX8664, err) } c.Assert(err, check.IsNil) From 2a7b132790826f787f24384fb7e122593c3c15e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Thu, 2 Feb 2023 21:28:10 +0100 Subject: [PATCH 08/10] Simplify a condition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit golangci-lint linter: ifshort Signed-off-by: Miloslav Trmač --- integration/copy_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/integration/copy_test.go b/integration/copy_test.go index 8362201c..39a5cea4 100644 --- a/integration/copy_test.go +++ b/integration/copy_test.go @@ -576,8 +576,7 @@ func matchLayerBlobBinaryType(c *check.C, ociImageDirPath string, contentType st func getFileContentType(out *os.File) (string, error) { buffer := make([]byte, 512) - _, err := out.Read(buffer) - if err != nil { + if _, err := out.Read(buffer); err != nil { return "", err } contentType := http.DetectContentType(buffer) From c1a57ca199596255e8450621180d3cf1097c8a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Thu, 2 Feb 2023 21:34:31 +0100 Subject: [PATCH 09/10] Pre-allocate an array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit golangci-lint linter: prealloc Signed-off-by: Miloslav Trmač --- cmd/skopeo/proxy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/skopeo/proxy.go b/cmd/skopeo/proxy.go index eb819acd..d15f3ee7 100644 --- a/cmd/skopeo/proxy.go +++ b/cmd/skopeo/proxy.go @@ -668,7 +668,7 @@ func (h *proxyHandler) GetLayerInfo(args []any) (replyBuf, error) { layerInfos = img.LayerInfos() } - var layers []convertedLayerInfo + layers := make([]convertedLayerInfo, 0, len(layerInfos)) for _, layer := range layerInfos { layers = append(layers, convertedLayerInfo{layer.Digest, layer.Size, layer.MediaType}) } From 47c7902ea29f7b2a9d066ea978474676e1b8c9ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Thu, 2 Feb 2023 21:34:39 +0100 Subject: [PATCH 10/10] Remove unnecessary blank lines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit golangci-lint linter: whitespace Signed-off-by: Miloslav Trmač --- cmd/skopeo/list_tags_test.go | 2 -- cmd/skopeo/utils_test.go | 1 - 2 files changed, 3 deletions(-) diff --git a/cmd/skopeo/list_tags_test.go b/cmd/skopeo/list_tags_test.go index f0734eb3..2b3cc2d5 100644 --- a/cmd/skopeo/list_tags_test.go +++ b/cmd/skopeo/list_tags_test.go @@ -16,7 +16,6 @@ func TestDockerRepositoryReferenceParser(t *testing.T) { {"docker://somehost.com"}, // Valid default expansion {"docker://nginx"}, // Valid default expansion } { - ref, err := parseDockerRepositoryReference(test[0]) require.NoError(t, err) expected, err := alltransports.ParseImageName(test[0]) @@ -47,7 +46,6 @@ func TestDockerRepositoryReferenceParserDrift(t *testing.T) { {"docker://somehost.com", "docker.io/library/somehost.com"}, // Valid default expansion {"docker://nginx", "docker.io/library/nginx"}, // Valid default expansion } { - ref, err := parseDockerRepositoryReference(test[0]) ref2, err2 := alltransports.ParseImageName(test[0]) diff --git a/cmd/skopeo/utils_test.go b/cmd/skopeo/utils_test.go index f5160b22..150e4ec2 100644 --- a/cmd/skopeo/utils_test.go +++ b/cmd/skopeo/utils_test.go @@ -385,7 +385,6 @@ func TestParseManifestFormat(t *testing.T) { // since there is a shared authfile image option and a non-shared (prefixed) one, make sure the override logic // works correctly. func TestImageOptionsAuthfileOverride(t *testing.T) { - for _, testCase := range []struct { flagPrefix string cmdFlags []string