From a780d6dfbb58807abd3118add4e567017a0931f9 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 22 Jun 2021 15:37:59 +0200 Subject: [PATCH 1/2] fs/stat: add FreeBSD This forwards the build-tag from containerd/containerd: https://github.com/containerd/containerd/commit/4c47fe0a2f1801a22a5e7038f5484445b2421c5b Signed-off-by: Sebastiaan van Stijn --- fs/{stat_darwinfreebsd.go => stat_darwinbsd.go} | 4 ++-- fs/stat_linuxopenbsd.go | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) rename fs/{stat_darwinfreebsd.go => stat_darwinbsd.go} (90%) diff --git a/fs/stat_darwinfreebsd.go b/fs/stat_darwinbsd.go similarity index 90% rename from fs/stat_darwinfreebsd.go rename to fs/stat_darwinbsd.go index cb7400a3..d225f6ae 100644 --- a/fs/stat_darwinfreebsd.go +++ b/fs/stat_darwinbsd.go @@ -1,4 +1,4 @@ -// +build darwin freebsd +// +build darwin freebsd netbsd /* Copyright The containerd Authors. @@ -40,5 +40,5 @@ func StatMtime(st *syscall.Stat_t) syscall.Timespec { // 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 + return time.Unix(int64(st.Atimespec.Sec), int64(st.Atimespec.Nsec)) //nolint: unconvert // int64 conversions ensure the line compiles for 32-bit systems as well. } diff --git a/fs/stat_linuxopenbsd.go b/fs/stat_linuxopenbsd.go index c68df6e5..9363910d 100644 --- a/fs/stat_linuxopenbsd.go +++ b/fs/stat_linuxopenbsd.go @@ -40,6 +40,5 @@ func StatMtime(st *syscall.Stat_t) syscall.Timespec { // StatATimeAsTime returns st.Atim as a time.Time func StatATimeAsTime(st *syscall.Stat_t) time.Time { - // The int64 conversions ensure the line compiles for 32-bit systems as well. - return time.Unix(int64(st.Atim.Sec), int64(st.Atim.Nsec)) // nolint: unconvert + return time.Unix(int64(st.Atim.Sec), int64(st.Atim.Nsec)) //nolint: unconvert // int64 conversions ensure the line compiles for 32-bit systems as well. } From fa7d1622372f1a787bfe51d59183b598813ce9d9 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 22 Jun 2021 15:39:51 +0200 Subject: [PATCH 2/2] reformat nolint comments Unlike comments for "humans", nolint comments should not have a leading whitespace. Also combined some comments, and renamed local variables so that we don't have to suppress linting warnings for those. Signed-off-by: Sebastiaan van Stijn --- fs/du_unix.go | 6 ++---- fs/du_unix_test.go | 4 ++-- fs/hardlink_unix.go | 3 +-- manifest.go | 10 ++++------ 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/fs/du_unix.go b/fs/du_unix.go index 9da43d1b..abe04868 100644 --- a/fs/du_unix.go +++ b/fs/du_unix.go @@ -41,10 +41,8 @@ type inode struct { func newInode(stat *syscall.Stat_t) inode { return inode{ - // Dev is uint32 on darwin/bsd, uint64 on linux/solaris/freebsd - dev: uint64(stat.Dev), // nolint: unconvert - // Ino is uint32 on bsd, uint64 on darwin/linux/solaris/freebsd - ino: uint64(stat.Ino), // nolint: unconvert + dev: uint64(stat.Dev), //nolint: unconvert // dev is uint32 on darwin/bsd, uint64 on linux/solaris/freebsd + ino: uint64(stat.Ino), //nolint: unconvert // ino is uint32 on bsd, uint64 on darwin/linux/solaris/freebsd } } diff --git a/fs/du_unix_test.go b/fs/du_unix_test.go index e0f19f05..b105542b 100644 --- a/fs/du_unix_test.go +++ b/fs/du_unix_test.go @@ -34,7 +34,7 @@ func getBsize(root string) (int64, error) { return 0, err } - return int64(s.Bsize), nil // nolint: unconvert + return int64(s.Bsize), nil //nolint: unconvert } // getTmpAlign returns filesystem specific size alignment functions @@ -92,6 +92,6 @@ func duCheck(root string) (usage int64, err error) { if err != nil { return 0, err } - return blocks * blocksUnitSize, nil + return blocks * blocksUnitSize, nil } diff --git a/fs/hardlink_unix.go b/fs/hardlink_unix.go index f95f0904..bc5f960a 100644 --- a/fs/hardlink_unix.go +++ b/fs/hardlink_unix.go @@ -29,6 +29,5 @@ func getLinkInfo(fi os.FileInfo) (uint64, bool) { return 0, false } - // Ino is uint32 on bsd, uint64 on darwin/linux/solaris - return uint64(s.Ino), !fi.IsDir() && s.Nlink > 1 // nolint: unconvert + return uint64(s.Ino), !fi.IsDir() && s.Nlink > 1 //nolint: unconvert // ino is uint32 on bsd, uint64 on darwin/linux/solaris } diff --git a/manifest.go b/manifest.go index 299fbcce..012af556 100644 --- a/manifest.go +++ b/manifest.go @@ -75,7 +75,7 @@ func MarshalText(w io.Writer, m *Manifest) error { // BuildManifest creates the manifest for the given context func BuildManifest(ctx Context) (*Manifest, error) { resourcesByPath := map[string]Resource{} - hardlinks := newHardlinkManager() + hardLinks := newHardlinkManager() if err := ctx.Walk(func(p string, fi os.FileInfo, err error) error { if err != nil { @@ -97,7 +97,7 @@ func BuildManifest(ctx Context) (*Manifest, error) { } // add to the hardlink manager - if err := hardlinks.Add(fi, resource); err == nil { + if err := hardLinks.Add(fi, resource); err == nil { // Resource has been accepted by hardlink manager so we don't add // it to the resourcesByPath until we merge at the end. return nil @@ -114,14 +114,12 @@ func BuildManifest(ctx Context) (*Manifest, error) { } // merge and post-process the hardlinks. - // nolint:misspell - hardlinked, err := hardlinks.Merge() + hardLinked, err := hardLinks.Merge() if err != nil { return nil, err } - // nolint:misspell - for _, resource := range hardlinked { + for _, resource := range hardLinked { resourcesByPath[resource.Path()] = resource }