Add unconvert linter
This linter checks for unnecessary type convertions. Some convertions are whitelisted because their type is different on 32bit platforms Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
parent
50a6c62492
commit
184bc25629
@ -7,13 +7,13 @@
|
|||||||
"fetch\\.go:.*::error: unrecognized printf verb 'r'"
|
"fetch\\.go:.*::error: unrecognized printf verb 'r'"
|
||||||
],
|
],
|
||||||
"EnableGC": true,
|
"EnableGC": true,
|
||||||
"WarnUnmatchedDirective": true,
|
|
||||||
|
|
||||||
"Enable": [
|
"Enable": [
|
||||||
"structcheck",
|
"structcheck",
|
||||||
"unused",
|
"unused",
|
||||||
"varcheck",
|
"varcheck",
|
||||||
"staticcheck",
|
"staticcheck",
|
||||||
|
"unconvert",
|
||||||
|
|
||||||
"gofmt",
|
"gofmt",
|
||||||
"goimports",
|
"goimports",
|
||||||
|
@ -46,7 +46,7 @@ func parsePAXTime(s string) (time.Time, error) {
|
|||||||
}
|
}
|
||||||
nsecs, _ := strconv.ParseInt(sn, 10, 64) // Must succeed
|
nsecs, _ := strconv.ParseInt(sn, 10, 64) // Must succeed
|
||||||
if len(ss) > 0 && ss[0] == '-' {
|
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
|
||||||
}
|
}
|
||||||
|
@ -29,11 +29,14 @@ func setHeaderForSpecialDevice(hdr *tar.Header, name string, fi os.FileInfo) err
|
|||||||
return errors.New("unsupported stat type")
|
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
|
// Currently go does not fill in the major/minors
|
||||||
if s.Mode&syscall.S_IFBLK != 0 ||
|
if s.Mode&syscall.S_IFBLK != 0 ||
|
||||||
s.Mode&syscall.S_IFCHR != 0 {
|
s.Mode&syscall.S_IFCHR != 0 {
|
||||||
hdr.Devmajor = int64(unix.Major(uint64(s.Rdev)))
|
hdr.Devmajor = int64(unix.Major(rdev))
|
||||||
hdr.Devminor = int64(unix.Minor(uint64(s.Rdev)))
|
hdr.Devminor = int64(unix.Minor(rdev))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -93,7 +93,7 @@ var pprofTraceCommand = cli.Command{
|
|||||||
cli.DurationFlag{
|
cli.DurationFlag{
|
||||||
Name: "seconds,s",
|
Name: "seconds,s",
|
||||||
Usage: "trace time (seconds)",
|
Usage: "trace time (seconds)",
|
||||||
Value: time.Duration(5 * time.Second),
|
Value: 5 * time.Second,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(context *cli.Context) error {
|
||||||
|
@ -12,8 +12,7 @@ import (
|
|||||||
|
|
||||||
func getATime(fi os.FileInfo) time.Time {
|
func getATime(fi os.FileInfo) time.Time {
|
||||||
if st, ok := fi.Sys().(*syscall.Stat_t); ok {
|
if st, ok := fi.Sys().(*syscall.Stat_t); ok {
|
||||||
return time.Unix(int64(sys.StatAtime(st).Sec),
|
return sys.StatATimeAsTime(st)
|
||||||
int64(sys.StatAtime(st).Nsec))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fi.ModTime()
|
return fi.ModTime()
|
||||||
|
@ -26,9 +26,9 @@ func (e *Envelope) Field(fieldpath []string) (string, bool) {
|
|||||||
switch fieldpath[0] {
|
switch fieldpath[0] {
|
||||||
// unhandled: timestamp
|
// unhandled: timestamp
|
||||||
case "namespace":
|
case "namespace":
|
||||||
return string(e.Namespace), len(e.Namespace) > 0
|
return e.Namespace, len(e.Namespace) > 0
|
||||||
case "topic":
|
case "topic":
|
||||||
return string(e.Topic), len(e.Topic) > 0
|
return e.Topic, len(e.Topic) > 0
|
||||||
case "event":
|
case "event":
|
||||||
decoded, err := typeurl.UnmarshalAny(e.Event)
|
decoded, err := typeurl.UnmarshalAny(e.Event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -15,6 +15,15 @@ type inode struct {
|
|||||||
dev, ino uint64
|
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) {
|
func diskUsage(roots ...string) (Usage, error) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -28,9 +37,7 @@ func diskUsage(roots ...string) (Usage, error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
stat := fi.Sys().(*syscall.Stat_t)
|
inoKey := newInode(fi.Sys().(*syscall.Stat_t))
|
||||||
|
|
||||||
inoKey := inode{dev: uint64(stat.Dev), ino: uint64(stat.Ino)}
|
|
||||||
if _, ok := inodes[inoKey]; !ok {
|
if _, ok := inodes[inoKey]; !ok {
|
||||||
inodes[inoKey] = struct{}{}
|
inodes[inoKey] = struct{}{}
|
||||||
size += fi.Size()
|
size += fi.Size()
|
||||||
@ -60,9 +67,7 @@ func diffUsage(ctx context.Context, a, b string) (Usage, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if kind == ChangeKindAdd || kind == ChangeKindModify {
|
if kind == ChangeKindAdd || kind == ChangeKindModify {
|
||||||
stat := fi.Sys().(*syscall.Stat_t)
|
inoKey := newInode(fi.Sys().(*syscall.Stat_t))
|
||||||
|
|
||||||
inoKey := inode{dev: uint64(stat.Dev), ino: uint64(stat.Ino)}
|
|
||||||
if _, ok := inodes[inoKey]; !ok {
|
if _, ok := inodes[inoKey]; !ok {
|
||||||
inodes[inoKey] = struct{}{}
|
inodes[inoKey] = struct{}{}
|
||||||
size += fi.Size()
|
size += fi.Size()
|
||||||
|
@ -13,5 +13,6 @@ func getLinkInfo(fi os.FileInfo) (uint64, bool) {
|
|||||||
return 0, false
|
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
|
||||||
}
|
}
|
||||||
|
@ -357,13 +357,5 @@ func RootFS(ctx context.Context, provider content.Provider, configDesc ocispec.D
|
|||||||
if err := json.Unmarshal(p, &config); err != nil {
|
if err := json.Unmarshal(p, &config); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
return config.RootFS.DiffIDs, nil
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ func writeImage(bkt *bolt.Bucket, image *images.Image) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// write the target bucket
|
// write the target bucket
|
||||||
tbkt, err := bkt.CreateBucketIfNotExists([]byte(bucketKeyTarget))
|
tbkt, err := bkt.CreateBucketIfNotExists(bucketKeyTarget)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ func (o *oomCollector) Collect(ch chan<- prometheus.Metric) {
|
|||||||
|
|
||||||
// Close closes the epoll fd
|
// Close closes the epoll fd
|
||||||
func (o *oomCollector) Close() error {
|
func (o *oomCollector) Close() error {
|
||||||
return unix.Close(int(o.fd))
|
return unix.Close(o.fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *oomCollector) start() {
|
func (o *oomCollector) start() {
|
||||||
|
@ -73,9 +73,9 @@ func adaptPlugin(o interface{}) filters.Adaptor {
|
|||||||
|
|
||||||
switch fieldpath[0] {
|
switch fieldpath[0] {
|
||||||
case "type":
|
case "type":
|
||||||
return string(obj.Type), len(obj.Type) > 0
|
return obj.Type, len(obj.Type) > 0
|
||||||
case "id":
|
case "id":
|
||||||
return string(obj.ID), len(obj.ID) > 0
|
return obj.ID, len(obj.ID) > 0
|
||||||
case "platforms":
|
case "platforms":
|
||||||
// TODO(stevvooe): Another case here where have multiple values.
|
// TODO(stevvooe): Another case here where have multiple values.
|
||||||
// May need to refactor the filter system to allow filtering by
|
// May need to refactor the filter system to allow filtering by
|
||||||
|
@ -4,6 +4,7 @@ package sys
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StatAtime returns the access time from a stat struct
|
// 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 {
|
func StatMtime(st *syscall.Stat_t) syscall.Timespec {
|
||||||
return st.Mtimespec
|
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
|
||||||
|
}
|
||||||
|
@ -4,6 +4,7 @@ package sys
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StatAtime returns the Atim
|
// StatAtime returns the Atim
|
||||||
@ -20,3 +21,8 @@ func StatCtime(st *syscall.Stat_t) syscall.Timespec {
|
|||||||
func StatMtime(st *syscall.Stat_t) syscall.Timespec {
|
func StatMtime(st *syscall.Stat_t) syscall.Timespec {
|
||||||
return st.Mtim
|
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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user