From 38fcdae95788e9c47bdacd674f06164bab91de1b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 28 Oct 2024 15:44:52 +0100 Subject: [PATCH 1/3] cmd/continuity: fix SA1019: entry.User/entry.Group is deprecated Add nolint-comments, and a small utility to show either the user/group name (if present), otherwise fall back to use Uid/Gid. Before this patch: cd cmd/continuity go install continuity build ./continuityfs/ > manifest.pb continuity ls ./manifest.pb -rw-r--r-- 7.5 kB /fuse.go -rw-r--r-- 1.7 kB /provider.go With this patch: cd cmd/continuity go install continuity build ./continuityfs/ > manifest.pb continuity ls ./manifest.pb -rw-r--r-- 501 20 7.5 kB /fuse.go -rw-r--r-- 501 20 1.7 kB /provider.go Signed-off-by: Sebastiaan van Stijn --- cmd/continuity/commands/ls.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/cmd/continuity/commands/ls.go b/cmd/continuity/commands/ls.go index b2862acd..86cfe007 100644 --- a/cmd/continuity/commands/ls.go +++ b/cmd/continuity/commands/ls.go @@ -20,8 +20,10 @@ import ( "fmt" "log" "os" + "strconv" "text/tabwriter" + "github.com/containerd/continuity/proto" "github.com/dustin/go-humanize" "github.com/spf13/cobra" ) @@ -42,17 +44,28 @@ var LSCmd = &cobra.Command{ w := tabwriter.NewWriter(os.Stdout, 0, 2, 2, ' ', 0) for _, entry := range bm.Resource { + user, group := getUserGroup(entry) for _, path := range entry.Path { if os.FileMode(entry.Mode)&os.ModeSymlink != 0 { - //nolint:unconvert - fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v -> %v\n", os.FileMode(entry.Mode), entry.User, entry.Group, humanize.Bytes(uint64(entry.Size)), path, entry.Target) + _, _ = fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v -> %v\n", os.FileMode(entry.Mode), user, group, humanize.Bytes(uint64(entry.Size)), path, entry.Target) //nolint:unconvert } else { - //nolint:unconvert - fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\n", os.FileMode(entry.Mode), entry.User, entry.Group, humanize.Bytes(uint64(entry.Size)), path) + _, _ = fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\n", os.FileMode(entry.Mode), user, group, humanize.Bytes(uint64(entry.Size)), path) //nolint:unconvert } } } - w.Flush() + _ = w.Flush() }, } + +func getUserGroup(entry *proto.Resource) (user, group string) { + user = entry.User //nolint:staticcheck // ignore SA1019: entry.User is deprecated. + if user == "" { + user = strconv.FormatInt(entry.Uid, 10) + } + group = entry.Group //nolint:staticcheck // ignore SA1019: entry.Group is deprecated. + if group == "" { + group = strconv.FormatInt(entry.Gid, 10) + } + return user, group +} From cadd3a2d76962f90047608655e607861862e329e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 28 Oct 2024 15:50:35 +0100 Subject: [PATCH 2/3] cmd/continuity/continuityfs: SA1019: fuse.ENOENT is deprecated Error: continuityfs/fuse.go:200:15: SA1019: fuse.ENOENT is deprecated: Return a syscall.Errno directly. See ToErrno for exact rules. (staticcheck) return nil, fuse.ENOENT ^ Signed-off-by: Sebastiaan van Stijn --- cmd/continuity/continuityfs/fuse.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/continuity/continuityfs/fuse.go b/cmd/continuity/continuityfs/fuse.go index b0997d7a..90c133d7 100644 --- a/cmd/continuity/continuityfs/fuse.go +++ b/cmd/continuity/continuityfs/fuse.go @@ -197,7 +197,7 @@ type direnter interface { func (d *Dir) Lookup(ctx context.Context, name string) (fs.Node, error) { node, ok := d.nodes[name] if !ok { - return nil, fuse.ENOENT + return nil, syscall.ENOENT } return node, nil } From 4c00ab7567238214d4dd9b9797435774836e3381 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 26 Oct 2024 13:37:13 +0200 Subject: [PATCH 3/3] Makefile: make "lint" target also lint cmd/continuity module cmd/continuity is a separate module, and therefore was not linted. Signed-off-by: Sebastiaan van Stijn --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index a622e939..8d84e9fd 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,7 @@ generate: lint: @echo "+ $@" @golangci-lint run + @(cd cmd/continuity && golangci-lint --config=../../.golangci.yml run) build: @echo "+ $@"