From a8c714358ce4cf76db246f88b9495a2b903b2c38 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 26 Oct 2024 12:46:08 +0200 Subject: [PATCH 1/6] golangci-lint: don't use deprecated name for "govet" linter WARN [lintersdb] The name "vet" is deprecated. The linter has been renamed to: govet. Signed-off-by: Sebastiaan van Stijn --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 4ededb0d..2f823714 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,7 +6,7 @@ linters: - goimports - ineffassign - revive - - vet + - govet - unused - misspell disable: From 5158c3f19836c8dd55dfc1ef84cb8656fca29f9f Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 26 Oct 2024 12:46:33 +0200 Subject: [PATCH 2/6] golangci-lint: sort linters Signed-off-by: Sebastiaan van Stijn --- .golangci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 2f823714..5345b2ac 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,14 +1,14 @@ linters: enable: - - staticcheck - - unconvert - gofmt - goimports + - govet - ineffassign + - misspell - revive - - govet + - staticcheck + - unconvert - unused - - misspell disable: - errcheck From 583d7ed1582f6b45643c7e11d2b93f6a68b7c623 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 26 Oct 2024 13:07:38 +0200 Subject: [PATCH 3/6] commands/mount_unsupported: drop nil-assignment (revive) commands/mount_unsupported.go:26:31: var-declaration: should drop = nil from declaration of var MountCmd; it is the zero value (revive) var MountCmd *cobra.Command = nil ^ Signed-off-by: Sebastiaan van Stijn --- cmd/continuity/commands/mount_unsupported.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/continuity/commands/mount_unsupported.go b/cmd/continuity/commands/mount_unsupported.go index f2cc1918..e2b1be63 100644 --- a/cmd/continuity/commands/mount_unsupported.go +++ b/cmd/continuity/commands/mount_unsupported.go @@ -22,4 +22,4 @@ import ( "github.com/spf13/cobra" ) -var MountCmd *cobra.Command = nil +var MountCmd *cobra.Command From 2200bb480f47137ea31eada2d9b0dcfc2474222b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 26 Oct 2024 13:36:48 +0200 Subject: [PATCH 4/6] don't use "ctx" for continuity.Context arguments ctx is commonly used for context.Context. Using it for any other purpose should be avoided to prevent confusion. Signed-off-by: Sebastiaan van Stijn --- manifest.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/manifest.go b/manifest.go index 659a4015..c0eefb82 100644 --- a/manifest.go +++ b/manifest.go @@ -78,11 +78,11 @@ func MarshalText(w io.Writer, m *Manifest) error { } // BuildManifest creates the manifest for the given context -func BuildManifest(ctx Context) (*Manifest, error) { +func BuildManifest(fsContext Context) (*Manifest, error) { resourcesByPath := map[string]Resource{} hardLinks := newHardlinkManager() - if err := ctx.Walk(func(p string, fi os.FileInfo, err error) error { + if err := fsContext.Walk(func(p string, fi os.FileInfo, err error) error { if err != nil { return fmt.Errorf("error walking %s: %w", p, err) } @@ -92,7 +92,7 @@ func BuildManifest(ctx Context) (*Manifest, error) { return nil } - resource, err := ctx.Resource(p, fi) + resource, err := fsContext.Resource(p, fi) if err != nil { if err == ErrNotFound { return nil @@ -141,9 +141,9 @@ func BuildManifest(ctx Context) (*Manifest, error) { // VerifyManifest verifies all the resources in a manifest // against files from the given context. -func VerifyManifest(ctx Context, manifest *Manifest) error { +func VerifyManifest(fsContext Context, manifest *Manifest) error { for _, resource := range manifest.Resources { - if err := ctx.Verify(resource); err != nil { + if err := fsContext.Verify(resource); err != nil { return err } } @@ -153,9 +153,9 @@ func VerifyManifest(ctx Context, manifest *Manifest) error { // ApplyManifest applies on the resources in a manifest to // the given context. -func ApplyManifest(ctx Context, manifest *Manifest) error { +func ApplyManifest(fsContext Context, manifest *Manifest) error { for _, resource := range manifest.Resources { - if err := ctx.Apply(resource); err != nil { + if err := fsContext.Apply(resource); err != nil { return err } } From 94c04905cf9ed5b65bbe2eac4f3f858769cb9f5a Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 26 Oct 2024 13:54:06 +0200 Subject: [PATCH 5/6] rename variables that shadowed package-level type Signed-off-by: Sebastiaan van Stijn --- manifest.go | 30 +++++++++++++++--------------- manifest_test.go | 24 ++++++++++++------------ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/manifest.go b/manifest.go index c0eefb82..e6bdd75b 100644 --- a/manifest.go +++ b/manifest.go @@ -56,8 +56,8 @@ func Unmarshal(p []byte) (*Manifest, error) { func Marshal(m *Manifest) ([]byte, error) { var bm pb.Manifest - for _, resource := range m.Resources { - bm.Resource = append(bm.Resource, toProto(resource)) + for _, rsrc := range m.Resources { + bm.Resource = append(bm.Resource, toProto(rsrc)) } return proto.Marshal(&bm) @@ -65,8 +65,8 @@ func Marshal(m *Manifest) ([]byte, error) { func MarshalText(w io.Writer, m *Manifest) error { var bm pb.Manifest - for _, resource := range m.Resources { - bm.Resource = append(bm.Resource, toProto(resource)) + for _, rsrc := range m.Resources { + bm.Resource = append(bm.Resource, toProto(rsrc)) } b, err := prototext.Marshal(&bm) @@ -92,7 +92,7 @@ func BuildManifest(fsContext Context) (*Manifest, error) { return nil } - resource, err := fsContext.Resource(p, fi) + rsrc, err := fsContext.Resource(p, fi) if err != nil { if err == ErrNotFound { return nil @@ -101,7 +101,7 @@ func BuildManifest(fsContext Context) (*Manifest, error) { } // add to the hardlink manager - if err := hardLinks.Add(fi, resource); err == nil { + if err := hardLinks.Add(fi, rsrc); 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 @@ -110,7 +110,7 @@ func BuildManifest(fsContext Context) (*Manifest, error) { return fmt.Errorf("adding hardlink %s: %w", p, err) } - resourcesByPath[p] = resource + resourcesByPath[p] = rsrc return nil }); err != nil { @@ -123,13 +123,13 @@ func BuildManifest(fsContext Context) (*Manifest, error) { return nil, err } - for _, resource := range hardLinked { - resourcesByPath[resource.Path()] = resource + for _, rsrc := range hardLinked { + resourcesByPath[rsrc.Path()] = rsrc } var resources []Resource - for _, resource := range resourcesByPath { - resources = append(resources, resource) + for _, rsrc := range resourcesByPath { + resources = append(resources, rsrc) } sort.Stable(ByPath(resources)) @@ -142,8 +142,8 @@ func BuildManifest(fsContext Context) (*Manifest, error) { // VerifyManifest verifies all the resources in a manifest // against files from the given context. func VerifyManifest(fsContext Context, manifest *Manifest) error { - for _, resource := range manifest.Resources { - if err := fsContext.Verify(resource); err != nil { + for _, rsrc := range manifest.Resources { + if err := fsContext.Verify(rsrc); err != nil { return err } } @@ -154,8 +154,8 @@ func VerifyManifest(fsContext Context, manifest *Manifest) error { // ApplyManifest applies on the resources in a manifest to // the given context. func ApplyManifest(fsContext Context, manifest *Manifest) error { - for _, resource := range manifest.Resources { - if err := fsContext.Apply(resource); err != nil { + for _, rsrc := range manifest.Resources { + if err := fsContext.Apply(rsrc); err != nil { return err } } diff --git a/manifest_test.go b/manifest_test.go index 4db9853a..5fe9c25b 100644 --- a/manifest_test.go +++ b/manifest_test.go @@ -158,9 +158,9 @@ func TestWalkFS(t *testing.T) { t.Log(b.String()) // TODO(dmcgowan): always verify, currently hard links not supported - //if err := VerifyManifest(ctx, m); err != nil { + // if err := VerifyManifest(ctx, m); err != nil { // t.Fatalf("error verifying manifest: %v") - //} + // } expectedResources, err := expectedResourceList(root, testResources) if err != nil { @@ -238,9 +238,9 @@ type dresource struct { } func generateTestFiles(t *testing.T, root string, resources []dresource) { - for i, resource := range resources { - p := filepath.Join(root, resource.path) - switch resource.kind { + for i, rsrc := range resources { + p := filepath.Join(root, rsrc.path) + switch rsrc.kind { case rfile: size := rng.Intn(4 << 20) d := make([]byte, size) @@ -250,35 +250,35 @@ func generateTestFiles(t *testing.T, root string, resources []dresource) { resources[i].size = size // this relies on the proper directory parent being defined. - if err := os.WriteFile(p, d, resource.mode); err != nil { + if err := os.WriteFile(p, d, rsrc.mode); err != nil { t.Fatalf("error writing %q: %v", p, err) } case rdirectory: - if err := os.Mkdir(p, resource.mode); err != nil { + if err := os.Mkdir(p, rsrc.mode); err != nil { t.Fatalf("error creating directory %q: %v", p, err) } case rhardlink: - target := filepath.Join(root, resource.target) + target := filepath.Join(root, rsrc.target) if err := os.Link(target, p); err != nil { t.Fatalf("error creating hardlink: %v", err) } case rrelsymlink: - if err := os.Symlink(resource.target, p); err != nil { + if err := os.Symlink(rsrc.target, p); err != nil { t.Fatalf("error creating symlink: %v", err) } case rabssymlink: // for absolute links, we join with root. - target := filepath.Join(root, resource.target) + target := filepath.Join(root, rsrc.target) if err := os.Symlink(target, p); err != nil { t.Fatalf("error creating symlink: %v", err) } case rchardev, rnamedpipe: - if err := devices.Mknod(p, resource.mode, resource.major, resource.minor); err != nil { + if err := devices.Mknod(p, rsrc.mode, rsrc.major, rsrc.minor); err != nil { t.Fatalf("error creating device %q: %v", p, err) } default: - t.Fatalf("unknown resource type: %v", resource.kind) + t.Fatalf("unknown resource type: %v", rsrc.kind) } st, err := os.Lstat(p) From 38f66a6d37247c12e5aac5b5ceac4ccb16a1c76e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 26 Oct 2024 13:54:57 +0200 Subject: [PATCH 6/6] TestWalkFS: fix unhandled error Signed-off-by: Sebastiaan van Stijn --- manifest_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/manifest_test.go b/manifest_test.go index 5fe9c25b..0c82b207 100644 --- a/manifest_test.go +++ b/manifest_test.go @@ -154,7 +154,10 @@ func TestWalkFS(t *testing.T) { } var b bytes.Buffer - MarshalText(&b, m) + err = MarshalText(&b, m) + if err != nil { + t.Fatalf("error marshaling manifest: %v", err) + } t.Log(b.String()) // TODO(dmcgowan): always verify, currently hard links not supported