Skip to content

Commit bf3c932

Browse files
fuweidcrosbymichael
authored andcommitted
[release 1.2] fix: linter issue
megacheck, gosimple and unused has been deprecated and subsumed by staticcheck. And staticcheck also has been upgraded. we need to update code for the linter issue. close: #2945 Signed-off-by: Wei Fu <fuweid89@gmail.com> Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
1 parent 5c38d94 commit bf3c932

File tree

26 files changed

+40
-57
lines changed

26 files changed

+40
-57
lines changed

.gometalinter.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
"Enable": [
1212
"structcheck",
13-
"unused",
1413
"varcheck",
1514
"staticcheck",
1615
"unconvert",

archive/tar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func applyNaive(ctx context.Context, root string, tr *tar.Reader, options ApplyO
295295
linkBasename := filepath.Base(hdr.Linkname)
296296
srcHdr = aufsHardlinks[linkBasename]
297297
if srcHdr == nil {
298-
return 0, fmt.Errorf("Invalid aufs hardlink")
298+
return 0, fmt.Errorf("invalid aufs hardlink")
299299
}
300300
p, err := fs.RootPath(aufsTempdir, linkBasename)
301301
if err != nil {

archive/tar_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ func TestBreakouts(t *testing.T) {
283283
if err != nil {
284284
return err
285285
}
286-
if bytes.Compare(b, content) != 0 {
286+
if !bytes.Equal(b, content) {
287287
return errors.Errorf("content differs: expected %v, got %v", content, b)
288288
}
289289
return nil
@@ -1133,7 +1133,7 @@ func fileEntry(name string, expected []byte, mode int) tarEntryValidator {
11331133
if hdr.Mode != int64(mode) {
11341134
return errors.Errorf("wrong mode %o, expected %o", hdr.Mode, mode)
11351135
}
1136-
if bytes.Compare(b, expected) != 0 {
1136+
if !bytes.Equal(b, expected) {
11371137
return errors.Errorf("different file content")
11381138
}
11391139
return nil

archive/tar_windows.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func tarName(p string) (string, error) {
7474
// in file names, it is mostly safe to replace however we must
7575
// check just in case
7676
if strings.Contains(p, "/") {
77-
return "", fmt.Errorf("Windows path contains forward slash: %s", p)
77+
return "", fmt.Errorf("windows path contains forward slash: %s", p)
7878
}
7979

8080
return strings.Replace(p, string(os.PathSeparator), "/", -1), nil
@@ -130,11 +130,7 @@ func skipFile(hdr *tar.Header) bool {
130130
// specific or Linux-specific, this warning should be changed to an error
131131
// to cater for the situation where someone does manage to upload a Linux
132132
// image but have it tagged as Windows inadvertently.
133-
if strings.Contains(hdr.Name, ":") {
134-
return true
135-
}
136-
137-
return false
133+
return strings.Contains(hdr.Name, ":")
138134
}
139135

140136
// handleTarTypeBlockCharFifo is an OS-specific helper function used by

container_linux_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ func TestDaemonRestartWithRunningShim(t *testing.T) {
911911
}
912912

913913
pid := task.Pid()
914-
if pid <= 0 {
914+
if pid < 1 {
915915
t.Fatalf("invalid task pid %d", pid)
916916
}
917917

@@ -1201,7 +1201,7 @@ func testUserNamespaces(t *testing.T, readonlyRootFS bool) {
12011201
t.Fatal(err)
12021202
}
12031203

1204-
if pid := task.Pid(); pid <= 0 {
1204+
if pid := task.Pid(); pid < 1 {
12051205
t.Errorf("invalid task pid %d", pid)
12061206
}
12071207
if err := task.Start(ctx); err != nil {

container_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestContainerStart(t *testing.T) {
136136
t.Fatal(err)
137137
}
138138

139-
if pid := task.Pid(); pid <= 0 {
139+
if pid := task.Pid(); pid < 1 {
140140
t.Errorf("invalid task pid %d", pid)
141141
}
142142
if err := task.Start(ctx); err != nil {
@@ -435,7 +435,7 @@ func TestContainerPids(t *testing.T) {
435435
}
436436

437437
pid := task.Pid()
438-
if pid <= 0 {
438+
if pid < 1 {
439439
t.Errorf("invalid task pid %d", pid)
440440
}
441441
processes, err := task.Pids(ctx)
@@ -785,7 +785,7 @@ func TestWaitStoppedTask(t *testing.T) {
785785
t.Fatal(err)
786786
}
787787

788-
if pid := task.Pid(); pid <= 0 {
788+
if pid := task.Pid(); pid < 1 {
789789
t.Errorf("invalid task pid %d", pid)
790790
}
791791
if err := task.Start(ctx); err != nil {

content/local/locks.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,5 @@ func unlock(ref string) {
4747
locksMu.Lock()
4848
defer locksMu.Unlock()
4949

50-
if _, ok := locks[ref]; ok {
51-
delete(locks, ref)
52-
}
50+
delete(locks, ref)
5351
}

contrib/seccomp/seccomp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ func WithProfile(profile string) oci.SpecOpts {
3737
s.Linux.Seccomp = &specs.LinuxSeccomp{}
3838
f, err := ioutil.ReadFile(profile)
3939
if err != nil {
40-
return fmt.Errorf("Cannot load seccomp profile %q: %v", profile, err)
40+
return fmt.Errorf("cannot load seccomp profile %q: %v", profile, err)
4141
}
4242
if err := json.Unmarshal(f, s.Linux.Seccomp); err != nil {
43-
return fmt.Errorf("Decoding seccomp profile failed %q: %v", profile, err)
43+
return fmt.Errorf("decoding seccomp profile failed %q: %v", profile, err)
4444
}
4545
return nil
4646
}

diff/apply/apply.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (s *fsApplier) Apply(ctx context.Context, desc ocispec.Descriptor, mounts [
5858
defer func() {
5959
if err == nil {
6060
log.G(ctx).WithFields(logrus.Fields{
61-
"d": time.Now().Sub(t1),
61+
"d": time.Since(t1),
6262
"dgst": desc.Digest,
6363
"size": desc.Size,
6464
"media": desc.MediaType,

diff/lcow/lcow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (s windowsLcowDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mou
9999
defer func() {
100100
if err == nil {
101101
log.G(ctx).WithFields(logrus.Fields{
102-
"d": time.Now().Sub(t1),
102+
"d": time.Since(t1),
103103
"dgst": desc.Digest,
104104
"size": desc.Size,
105105
"media": desc.MediaType,

0 commit comments

Comments
 (0)