diff --git a/.golangci.yml b/.golangci.yml index 4ededb0..5345b2a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,14 +1,14 @@ linters: enable: - - staticcheck - - unconvert - gofmt - goimports + - govet - ineffassign + - misspell - revive - - vet + - staticcheck + - unconvert - unused - - misspell disable: - errcheck diff --git a/cmd/continuity/commands/mount_unsupported.go b/cmd/continuity/commands/mount_unsupported.go index f2cc191..e2b1be6 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 diff --git a/manifest.go b/manifest.go index 659a401..e6bdd75 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) @@ -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) + rsrc, err := fsContext.Resource(p, fi) if err != nil { if err == ErrNotFound { return nil @@ -101,7 +101,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, 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(ctx 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(ctx 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)) @@ -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 { - for _, resource := range manifest.Resources { - if err := ctx.Verify(resource); err != nil { +func VerifyManifest(fsContext Context, manifest *Manifest) error { + for _, rsrc := range manifest.Resources { + if err := fsContext.Verify(rsrc); 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 { - for _, resource := range manifest.Resources { - if err := ctx.Apply(resource); err != nil { +func ApplyManifest(fsContext Context, manifest *Manifest) error { + 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 4db9853..0c82b20 100644 --- a/manifest_test.go +++ b/manifest_test.go @@ -154,13 +154,16 @@ 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 - //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 +241,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 +253,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)