diff --git a/.gometalinter.json b/.gometalinter.json index 452cfc2ea..0bd36f2bc 100644 --- a/.gometalinter.json +++ b/.gometalinter.json @@ -7,13 +7,13 @@ "fetch\\.go:.*::error: unrecognized printf verb 'r'" ], "EnableGC": true, - "WarnUnmatchedDirective": true, "Enable": [ "structcheck", "unused", "varcheck", "staticcheck", + "unconvert", "gofmt", "goimports", diff --git a/archive/strconv.go b/archive/strconv.go index 185ee5dd2..8f4f26ba8 100644 --- a/archive/strconv.go +++ b/archive/strconv.go @@ -46,7 +46,7 @@ func parsePAXTime(s string) (time.Time, error) { } nsecs, _ := strconv.ParseInt(sn, 10, 64) // Must succeed if len(ss) > 0 && ss[0] == '-' { - return time.Unix(secs, -1*int64(nsecs)), nil // Negative correction + return time.Unix(secs, -nsecs), nil // Negative correction } - return time.Unix(secs, int64(nsecs)), nil + return time.Unix(secs, nsecs), nil } diff --git a/archive/tar_unix.go b/archive/tar_unix.go index 6ecdbcfff..631d08229 100644 --- a/archive/tar_unix.go +++ b/archive/tar_unix.go @@ -29,11 +29,14 @@ func setHeaderForSpecialDevice(hdr *tar.Header, name string, fi os.FileInfo) err return errors.New("unsupported stat type") } + // Rdev is int32 on darwin/bsd, int64 on linux/solaris + rdev := uint64(s.Rdev) // nolint: unconvert + // Currently go does not fill in the major/minors if s.Mode&syscall.S_IFBLK != 0 || s.Mode&syscall.S_IFCHR != 0 { - hdr.Devmajor = int64(unix.Major(uint64(s.Rdev))) - hdr.Devminor = int64(unix.Minor(uint64(s.Rdev))) + hdr.Devmajor = int64(unix.Major(rdev)) + hdr.Devminor = int64(unix.Minor(rdev)) } return nil diff --git a/cmd/ctr/commands/pprof/pprof.go b/cmd/ctr/commands/pprof/pprof.go index 4e1ee94e7..62b2fafdf 100644 --- a/cmd/ctr/commands/pprof/pprof.go +++ b/cmd/ctr/commands/pprof/pprof.go @@ -93,7 +93,7 @@ var pprofTraceCommand = cli.Command{ cli.DurationFlag{ Name: "seconds,s", Usage: "trace time (seconds)", - Value: time.Duration(5 * time.Second), + Value: 5 * time.Second, }, }, Action: func(context *cli.Context) error { diff --git a/content/local/store_unix.go b/content/local/store_unix.go index c0587e1b2..464970611 100644 --- a/content/local/store_unix.go +++ b/content/local/store_unix.go @@ -12,8 +12,7 @@ import ( func getATime(fi os.FileInfo) time.Time { if st, ok := fi.Sys().(*syscall.Stat_t); ok { - return time.Unix(int64(sys.StatAtime(st).Sec), - int64(sys.StatAtime(st).Nsec)) + return sys.StatATimeAsTime(st) } return fi.ModTime() diff --git a/events/events.go b/events/events.go index 2bfedb1e8..6f4c8b3af 100644 --- a/events/events.go +++ b/events/events.go @@ -26,9 +26,9 @@ func (e *Envelope) Field(fieldpath []string) (string, bool) { switch fieldpath[0] { // unhandled: timestamp case "namespace": - return string(e.Namespace), len(e.Namespace) > 0 + return e.Namespace, len(e.Namespace) > 0 case "topic": - return string(e.Topic), len(e.Topic) > 0 + return e.Topic, len(e.Topic) > 0 case "event": decoded, err := typeurl.UnmarshalAny(e.Event) if err != nil { diff --git a/fs/du_unix.go b/fs/du_unix.go index 6328e80f3..fe3426d27 100644 --- a/fs/du_unix.go +++ b/fs/du_unix.go @@ -15,6 +15,15 @@ type inode struct { dev, ino uint64 } +func newInode(stat *syscall.Stat_t) inode { + return inode{ + // Dev is uint32 on darwin/bsd, uint64 on linux/solaris + dev: uint64(stat.Dev), // nolint: unconvert + // Ino is uint32 on bsd, uint64 on darwin/linux/solaris + ino: uint64(stat.Ino), // nolint: unconvert + } +} + func diskUsage(roots ...string) (Usage, error) { var ( @@ -28,9 +37,7 @@ func diskUsage(roots ...string) (Usage, error) { return err } - stat := fi.Sys().(*syscall.Stat_t) - - inoKey := inode{dev: uint64(stat.Dev), ino: uint64(stat.Ino)} + inoKey := newInode(fi.Sys().(*syscall.Stat_t)) if _, ok := inodes[inoKey]; !ok { inodes[inoKey] = struct{}{} size += fi.Size() @@ -60,9 +67,7 @@ func diffUsage(ctx context.Context, a, b string) (Usage, error) { } if kind == ChangeKindAdd || kind == ChangeKindModify { - stat := fi.Sys().(*syscall.Stat_t) - - inoKey := inode{dev: uint64(stat.Dev), ino: uint64(stat.Ino)} + inoKey := newInode(fi.Sys().(*syscall.Stat_t)) if _, ok := inodes[inoKey]; !ok { inodes[inoKey] = struct{}{} size += fi.Size() diff --git a/fs/hardlink_unix.go b/fs/hardlink_unix.go index 3b825c940..a6f99778d 100644 --- a/fs/hardlink_unix.go +++ b/fs/hardlink_unix.go @@ -13,5 +13,6 @@ func getLinkInfo(fi os.FileInfo) (uint64, bool) { return 0, false } - return uint64(s.Ino), !fi.IsDir() && s.Nlink > 1 + // Ino is uint32 on bsd, uint64 on darwin/linux/solaris + return uint64(s.Ino), !fi.IsDir() && s.Nlink > 1 // nolint: unconvert } diff --git a/images/image.go b/images/image.go index 7b4215faf..3f58e0620 100644 --- a/images/image.go +++ b/images/image.go @@ -357,13 +357,5 @@ func RootFS(ctx context.Context, provider content.Provider, configDesc ocispec.D if err := json.Unmarshal(p, &config); err != nil { return nil, err } - - // TODO(stevvooe): Remove this bit when OCI structure uses correct type for - // rootfs.DiffIDs. - var diffIDs []digest.Digest - for _, diffID := range config.RootFS.DiffIDs { - diffIDs = append(diffIDs, digest.Digest(diffID)) - } - - return diffIDs, nil + return config.RootFS.DiffIDs, nil } diff --git a/metadata/images.go b/metadata/images.go index 070439a8c..8bf0c6173 100644 --- a/metadata/images.go +++ b/metadata/images.go @@ -275,7 +275,7 @@ func writeImage(bkt *bolt.Bucket, image *images.Image) error { } // write the target bucket - tbkt, err := bkt.CreateBucketIfNotExists([]byte(bucketKeyTarget)) + tbkt, err := bkt.CreateBucketIfNotExists(bucketKeyTarget) if err != nil { return err } diff --git a/metrics/cgroups/oom.go b/metrics/cgroups/oom.go index 196c8fb07..aafe59571 100644 --- a/metrics/cgroups/oom.go +++ b/metrics/cgroups/oom.go @@ -89,7 +89,7 @@ func (o *oomCollector) Collect(ch chan<- prometheus.Metric) { // Close closes the epoll fd func (o *oomCollector) Close() error { - return unix.Close(int(o.fd)) + return unix.Close(o.fd) } func (o *oomCollector) start() { diff --git a/services/introspection/service.go b/services/introspection/service.go index 001db8e53..057e607d1 100644 --- a/services/introspection/service.go +++ b/services/introspection/service.go @@ -73,9 +73,9 @@ func adaptPlugin(o interface{}) filters.Adaptor { switch fieldpath[0] { case "type": - return string(obj.Type), len(obj.Type) > 0 + return obj.Type, len(obj.Type) > 0 case "id": - return string(obj.ID), len(obj.ID) > 0 + return obj.ID, len(obj.ID) > 0 case "platforms": // TODO(stevvooe): Another case here where have multiple values. // May need to refactor the filter system to allow filtering by diff --git a/sys/stat_bsd.go b/sys/stat_bsd.go index e043ae52b..84c59ab6f 100644 --- a/sys/stat_bsd.go +++ b/sys/stat_bsd.go @@ -4,6 +4,7 @@ package sys import ( "syscall" + "time" ) // StatAtime returns the access time from a stat struct @@ -20,3 +21,8 @@ func StatCtime(st *syscall.Stat_t) syscall.Timespec { func StatMtime(st *syscall.Stat_t) syscall.Timespec { return st.Mtimespec } + +// StatATimeAsTime returns the access time as a time.Time +func StatATimeAsTime(st *syscall.Stat_t) time.Time { + return time.Unix(int64(st.Atimespec.Sec), int64(st.Atimespec.Nsec)) // nolint: unconvert +} diff --git a/sys/stat_unix.go b/sys/stat_unix.go index 1f983a98d..799b9b997 100644 --- a/sys/stat_unix.go +++ b/sys/stat_unix.go @@ -4,6 +4,7 @@ package sys import ( "syscall" + "time" ) // StatAtime returns the Atim @@ -20,3 +21,8 @@ func StatCtime(st *syscall.Stat_t) syscall.Timespec { func StatMtime(st *syscall.Stat_t) syscall.Timespec { return st.Mtim } + +// StatATimeAsTime returns st.Atim as a time.Time +func StatATimeAsTime(st *syscall.Stat_t) time.Time { + return time.Unix(st.Atim.Sec, st.Atim.Nsec) +}