From 2ee23eec5eee2797effb029d2c545ff81f9505bc Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Sat, 12 Apr 2025 14:08:58 +0200 Subject: [PATCH 1/6] chore: update golangci-lint Signed-off-by: Mark Sagi-Kazar --- .editorconfig | 3 ++ .github/workflows/ci.yaml | 4 +-- .golangci.yaml | 61 +++++++++++++++++++++++++++++---------- 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/.editorconfig b/.editorconfig index 4492e9f9..a85749f1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,3 +10,6 @@ trim_trailing_whitespace = true [*.go] indent_style = tab + +[{*.yml,*.yaml}] +indent_size = 2 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e56359a0..b991f783 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -50,6 +50,6 @@ jobs: go-version: "1.24" - name: Lint - uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2 + uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0 with: - version: v1.64.7 + version: v2.0.2 diff --git a/.golangci.yaml b/.golangci.yaml index 806289a2..fbba3201 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,18 +1,47 @@ -linters-settings: - gci: - sections: - - standard - - default - - prefix(github.com/spf13/afero) +version: "2" + +run: + timeout: 10m linters: - disable-all: true - enable: - - gci - - gofmt - - gofumpt - - staticcheck - -issues: - exclude-dirs: - - gcsfs/internal/stiface + enable: + - govet + - ineffassign + # - misspell + - nolintlint + # - revive + - unused + + disable: + - errcheck + - staticcheck + + settings: + misspell: + locale: US + nolintlint: + allow-unused: false # report any unused nolint directives + require-specific: false # don't require nolint directives to be specific about which linter is being skipped + + exclusions: + paths: + - gcsfs/internal/stiface + +formatters: + enable: + - gci + - gofmt + # - gofumpt + - goimports + # - golines + + settings: + gci: + sections: + - standard + - default + - localmodule + + exclusions: + paths: + - gcsfs/internal/stiface From a991449002ca0cee55185ae48879a06e6b9442ae Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Sat, 12 Apr 2025 14:09:23 +0200 Subject: [PATCH 2/6] ci: add dependency review Signed-off-by: Mark Sagi-Kazar --- .github/workflows/ci.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b991f783..a9e7123b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -53,3 +53,15 @@ jobs: uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0 with: version: v2.0.2 + + dependency-review: + name: Dependency review + runs-on: ubuntu-latest + if: github.event_name == 'pull_request' + + steps: + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Dependency Review + uses: actions/dependency-review-action@3b139cfc5fae8b618d3eae3675e383bb1769c019 # v4.5.0 From 66924a372a4ed1e700a65d7c859d6acd0db98354 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Sat, 12 Apr 2025 14:09:58 +0200 Subject: [PATCH 3/6] ci: add scorecard analysis Signed-off-by: Mark Sagi-Kazar --- .github/workflows/analysis-scorecard.yaml | 47 +++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/analysis-scorecard.yaml diff --git a/.github/workflows/analysis-scorecard.yaml b/.github/workflows/analysis-scorecard.yaml new file mode 100644 index 00000000..5fce75fb --- /dev/null +++ b/.github/workflows/analysis-scorecard.yaml @@ -0,0 +1,47 @@ +name: OpenSSF Scorecard + +on: + branch_protection_rule: + push: + branches: [main] + schedule: + - cron: "30 0 * * 5" + +permissions: + contents: read + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + permissions: + actions: read + contents: read + id-token: write + security-events: write + + steps: + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false + + - name: Run analysis + uses: ossf/scorecard-action@f49aabe0b5af0936a0987cfb85d86b75731b0186 # v2.4.1 + with: + results_file: results.sarif + results_format: sarif + publish_results: true + + - name: Upload results as artifact + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: OpenSSF Scorecard results + path: results.sarif + retention-days: 5 + + - name: Upload results to GitHub Security tab + uses: github/codeql-action/upload-sarif@cdcdbb579706841c47f7063dda365e292e5cad7a # v2.13.4 + with: + sarif_file: results.sarif From 3fa25f7ea79f9aea7505ad5fe4a58ac03c6f8a7a Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Sat, 12 Apr 2025 14:11:02 +0200 Subject: [PATCH 4/6] docs: update badges Signed-off-by: Mark Sagi-Kazar --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 86f15455..e043a346 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,10 @@ A FileSystem Abstraction System for Go -[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/spf13/afero/ci.yaml?branch=master&style=flat-square)](https://github.com/spf13/afero/actions?query=workflow%3ACI) -[![Join the chat at https://gitter.im/spf13/afero](https://badges.gitter.im/Dev%20Chat.svg)](https://gitter.im/spf13/afero?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![Go Report Card](https://goreportcard.com/badge/github.com/spf13/afero?style=flat-square)](https://goreportcard.com/report/github.com/spf13/afero) -![Go Version](https://img.shields.io/badge/go%20version-%3E=1.23-61CFDD.svg?style=flat-square) -[![PkgGoDev](https://pkg.go.dev/badge/mod/github.com/spf13/afero)](https://pkg.go.dev/mod/github.com/spf13/afero) +[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/spf13/afero/ci.yaml?style=flat-square)](https://github.com/spf13/afero/actions/workflows/ci.yaml) +[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/mod/github.com/spf13/afero) +![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/spf13/afero?style=flat-square&color=61CFDD) +[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/spf13/afero/badge?style=flat-square)](https://deps.dev/go/github.com%252Fspf13%252Fafero) # Overview From 638ed6545fb02272f14d203429e56178869fc38c Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Sat, 12 Apr 2025 14:19:51 +0200 Subject: [PATCH 5/6] chore: fix lint violations Signed-off-by: Mark Sagi-Kazar --- .golangci.yaml | 9 ++++--- afero_test.go | 27 ++++++++++++++++--- basepath_test.go | 6 +++-- copyOnWriteFs.go | 9 +++++-- gcsfs/file.go | 5 +++- gcsfs/fs.go | 12 ++++++--- gcsfs/gcs.go | 12 +++++++-- gcsfs/gcs_mocks.go | 20 +++++++++++--- gcsfs/gcs_test.go | 37 +++++++++++++++++++++----- iofs.go | 9 +++++-- iofs_test.go | 39 ++++++++++++++++++++++----- ioutil_test.go | 1 + lstater.go | 2 +- mem/file.go | 22 ++++++++++++--- sftpfs/sftp_test.go | 5 +++- symlink_test.go | 7 ++++- tarfs/tarfs_test.go | 9 ++++++- unionFile.go | 5 ++-- util.go | 4 +-- util_test.go | 65 +++++++++++++++++++++++++++++++++++++-------- 20 files changed, 247 insertions(+), 58 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index fbba3201..4f359b81 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -7,14 +7,15 @@ linters: enable: - govet - ineffassign - # - misspell + - misspell - nolintlint # - revive + - staticcheck - unused disable: - errcheck - - staticcheck + # - staticcheck settings: misspell: @@ -31,9 +32,9 @@ formatters: enable: - gci - gofmt - # - gofumpt + - gofumpt - goimports - # - golines + - golines settings: gci: diff --git a/afero_test.go b/afero_test.go index 827c05c3..a6cb05c4 100644 --- a/afero_test.go +++ b/afero_test.go @@ -60,7 +60,9 @@ func TestRead0(t *testing.T) { for _, fs := range Fss { f := tmpFile(fs) defer f.Close() - f.WriteString("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.") + f.WriteString( + "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", + ) var b []byte // b := make([]byte, 0) @@ -103,7 +105,12 @@ func TestOpenFile(t *testing.T) { contents, _ := io.ReadAll(f) expectedContents := "initial|append" if string(contents) != expectedContents { - t.Errorf("%v: appending, expected '%v', got: '%v'", fs.Name(), expectedContents, string(contents)) + t.Errorf( + "%v: appending, expected '%v', got: '%v'", + fs.Name(), + expectedContents, + string(contents), + ) } f.Close() @@ -158,7 +165,11 @@ func TestCreate(t *testing.T) { continue } if string(buf) != secondContent { - t.Error(fs.Name(), "Content should be", "\""+secondContent+"\" but is \""+string(buf)+"\"") + t.Error( + fs.Name(), + "Content should be", + "\""+secondContent+"\" but is \""+string(buf)+"\"", + ) f.Close() continue } @@ -351,7 +362,15 @@ func TestSeek(t *testing.T) { // http://code.google.com/p/go/issues/detail?id=91 break } - t.Errorf("#%d: Seek(%v, %v) = %v, %v want %v, nil", i, tt.in, tt.whence, off, err, tt.out) + t.Errorf( + "#%d: Seek(%v, %v) = %v, %v want %v, nil", + i, + tt.in, + tt.whence, + off, + err, + tt.out, + ) } } } diff --git a/basepath_test.go b/basepath_test.go index 1c46abd2..1120210c 100644 --- a/basepath_test.go +++ b/basepath_test.go @@ -123,12 +123,14 @@ func TestNestedBasePaths(t *testing.T) { t.Errorf("Got error %s", err.Error()) } - if s.BaseFs == level3Fs { + switch s.BaseFs { + case level3Fs: pathToExist := filepath.Join(ds.Dir3, s.FileName) if _, err := level2Fs.Stat(pathToExist); err != nil { t.Errorf("Got error %s (path %s)", err.Error(), pathToExist) } - } else if s.BaseFs == level2Fs { + + case level2Fs: pathToExist := filepath.Join(ds.Dir2, ds.Dir3, s.FileName) if _, err := level1Fs.Stat(pathToExist); err != nil { t.Errorf("Got error %s (path %s)", err.Error(), pathToExist) diff --git a/copyOnWriteFs.go b/copyOnWriteFs.go index 184d6dd7..aba2879e 100644 --- a/copyOnWriteFs.go +++ b/copyOnWriteFs.go @@ -34,7 +34,8 @@ func (u *CopyOnWriteFs) isBaseFile(name string) (bool, error) { _, err := u.base.Stat(name) if err != nil { if oerr, ok := err.(*os.PathError); ok { - if oerr.Err == os.ErrNotExist || oerr.Err == syscall.ENOENT || oerr.Err == syscall.ENOTDIR { + if oerr.Err == os.ErrNotExist || oerr.Err == syscall.ENOENT || + oerr.Err == syscall.ENOTDIR { return false, nil } } @@ -237,7 +238,11 @@ func (u *CopyOnWriteFs) OpenFile(name string, flag int, perm os.FileMode) (File, return u.layer.OpenFile(name, flag, perm) } - return nil, &os.PathError{Op: "open", Path: name, Err: syscall.ENOTDIR} // ...or os.ErrNotExist? + return nil, &os.PathError{ + Op: "open", + Path: name, + Err: syscall.ENOTDIR, + } // ...or os.ErrNotExist? } if b { return u.base.OpenFile(name, flag, perm) diff --git a/gcsfs/file.go b/gcsfs/file.go index 54178bc3..81a09377 100644 --- a/gcsfs/file.go +++ b/gcsfs/file.go @@ -108,7 +108,10 @@ func (o *GcsFile) Seek(newOffset int64, whence int) (int64, error) { if (whence == 0 && newOffset == o.fhOffset) || (whence == 1 && newOffset == 0) { return o.fhOffset, nil } - log.Printf("WARNING: Seek behavior triggered, highly inefficent. Offset before seek is at %d\n", o.fhOffset) + log.Printf( + "WARNING: Seek behavior triggered, highly inefficent. Offset before seek is at %d\n", + o.fhOffset, + ) // Fore the reader/writers to be reopened (at correct offset) err := o.Sync() diff --git a/gcsfs/fs.go b/gcsfs/fs.go index 914704f7..6e8660c6 100644 --- a/gcsfs/fs.go +++ b/gcsfs/fs.go @@ -158,7 +158,9 @@ func (fs *Fs) Create(name string) (*GcsFile, error) { } func (fs *Fs) Mkdir(name string, _ os.FileMode) error { - name = fs.ensureNoLeadingSeparator(fs.ensureTrailingSeparator(fs.normSeparators(ensureNoPrefix(name)))) + name = fs.ensureNoLeadingSeparator( + fs.ensureTrailingSeparator(fs.normSeparators(ensureNoPrefix(name))), + ) if err := validateName(name); err != nil { return err } @@ -181,7 +183,9 @@ func (fs *Fs) Mkdir(name string, _ os.FileMode) error { } func (fs *Fs) MkdirAll(path string, perm os.FileMode) error { - path = fs.ensureNoLeadingSeparator(fs.ensureTrailingSeparator(fs.normSeparators(ensureNoPrefix(path)))) + path = fs.ensureNoLeadingSeparator( + fs.ensureTrailingSeparator(fs.normSeparators(ensureNoPrefix(path))), + ) if err := validateName(path); err != nil { return err } @@ -404,7 +408,9 @@ func (fs *Fs) Chmod(_ string, _ os.FileMode) error { } func (fs *Fs) Chtimes(_ string, _, _ time.Time) error { - return errors.New("method Chtimes is not implemented. Create, Delete, Updated times are read only fields in GCS and set implicitly") + return errors.New( + "method Chtimes is not implemented. Create, Delete, Updated times are read only fields in GCS and set implicitly", + ) } func (fs *Fs) Chown(_ string, _, _ int) error { diff --git a/gcsfs/gcs.go b/gcsfs/gcs.go index f9daa21f..eb09e897 100644 --- a/gcsfs/gcs.go +++ b/gcsfs/gcs.go @@ -48,7 +48,11 @@ func NewGcsFS(ctx context.Context, opts ...option.ClientOption) (afero.Fs, error } // NewGcsFSWithSeparator is the same as NewGcsFS, but the files system will use the provided folder separator. -func NewGcsFSWithSeparator(ctx context.Context, folderSeparator string, opts ...option.ClientOption) (afero.Fs, error) { +func NewGcsFSWithSeparator( + ctx context.Context, + folderSeparator string, + opts ...option.ClientOption, +) (afero.Fs, error) { client, err := storage.NewClient(ctx, opts...) if err != nil { return nil, err @@ -65,7 +69,11 @@ func NewGcsFSFromClient(ctx context.Context, client *storage.Client) (afero.Fs, } // NewGcsFSFromClientWithSeparator is the same as NewGcsFSFromClient, but the file system will use the provided folder separator. -func NewGcsFSFromClientWithSeparator(ctx context.Context, client *storage.Client, folderSeparator string) (afero.Fs, error) { +func NewGcsFSFromClientWithSeparator( + ctx context.Context, + client *storage.Client, + folderSeparator string, +) (afero.Fs, error) { c := stiface.AdaptClient(client) return &GcsFs{NewGcsFsWithSeparator(ctx, c, folderSeparator)}, nil diff --git a/gcsfs/gcs_mocks.go b/gcsfs/gcs_mocks.go index 9e64970a..adb5f0fe 100644 --- a/gcsfs/gcs_mocks.go +++ b/gcsfs/gcs_mocks.go @@ -73,7 +73,10 @@ func (o *objectMock) NewWriter(_ context.Context) stiface.Writer { return &writerMock{name: o.name, fs: o.fs} } -func (o *objectMock) NewRangeReader(_ context.Context, offset, length int64) (stiface.Reader, error) { +func (o *objectMock) NewRangeReader( + _ context.Context, + offset, length int64, +) (stiface.Reader, error) { if o.name == "" { return nil, ErrEmptyObjectName } @@ -126,7 +129,11 @@ func (o *objectMock) Attrs(_ context.Context) (*storage.ObjectAttrs, error) { return nil, err } - res := &storage.ObjectAttrs{Name: normSeparators(o.name), Size: info.Size(), Updated: info.ModTime()} + res := &storage.ObjectAttrs{ + Name: normSeparators(o.name), + Size: info.Size(), + Updated: info.ModTime(), + } if info.IsDir() { // we have to mock it here, because of FileInfo logic @@ -240,7 +247,14 @@ func (it *objectItMock) Next() (*storage.ObjectAttrs, error) { if err != nil { return nil, err } - it.infos = append(it.infos, &storage.ObjectAttrs{Name: normSeparators(info.Name()), Size: info.Size(), Updated: info.ModTime()}) + it.infos = append( + it.infos, + &storage.ObjectAttrs{ + Name: normSeparators(info.Name()), + Size: info.Size(), + Updated: info.ModTime(), + }, + ) } else { var fInfos []os.FileInfo fInfos, err = it.dir.Readdir(0) diff --git a/gcsfs/gcs_test.go b/gcsfs/gcs_test.go index ba3d09cd..cbc2adf3 100644 --- a/gcsfs/gcs_test.go +++ b/gcsfs/gcs_test.go @@ -55,7 +55,10 @@ var dirs = []struct { name string children []string }{ - {"", []string{"sub", "testDir1", "testFile"}}, // in this case it will be prepended with bucket name + { + "", + []string{"sub", "testDir1", "testFile"}, + }, // in this case it will be prepended with bucket name {"sub", []string{"testDir2"}}, {"sub/testDir2", []string{"testFile"}}, {"testDir1", []string{"testFile"}}, @@ -365,7 +368,14 @@ func TestGcsSeek(t *testing.T) { } if n != s.offOut { - t.Errorf("%v: (off: %v, whence: %v): got %v, expected %v", f.name, s.offIn, s.whence, n, s.offOut) + t.Errorf( + "%v: (off: %v, whence: %v): got %v, expected %v", + f.name, + s.offIn, + s.whence, + n, + s.offOut, + ) } } } @@ -693,7 +703,10 @@ func TestGcsGlob(t *testing.T) { prefixedEntries := [][]string{{}, {}} for _, entry := range s.entries { prefixedEntries[0] = append(prefixedEntries[0], filepath.Join(bucketName, entry)) - prefixedEntries[1] = append(prefixedEntries[1], string(os.PathSeparator)+filepath.Join(bucketName, entry)) + prefixedEntries[1] = append( + prefixedEntries[1], + string(os.PathSeparator)+filepath.Join(bucketName, entry), + ) } for i, prefixedGlob := range prefixedGlobs { @@ -775,7 +788,11 @@ func TestGcsMkdirAll(t *testing.T) { t.Errorf("%s: mode is not directory", filepath.Join(bucketName, "a")) } if info.Mode() != os.ModeDir|0o755 { - t.Errorf("%s: wrong permissions, expected drwxr-xr-x, got %s", filepath.Join(bucketName, "a"), info.Mode()) + t.Errorf( + "%s: wrong permissions, expected drwxr-xr-x, got %s", + filepath.Join(bucketName, "a"), + info.Mode(), + ) } info, err = gcsAfs.Stat(filepath.Join(bucketName, "a/b")) if err != nil { @@ -785,7 +802,11 @@ func TestGcsMkdirAll(t *testing.T) { t.Errorf("%s: mode is not directory", filepath.Join(bucketName, "a/b")) } if info.Mode() != os.ModeDir|0o755 { - t.Errorf("%s: wrong permissions, expected drwxr-xr-x, got %s", filepath.Join(bucketName, "a/b"), info.Mode()) + t.Errorf( + "%s: wrong permissions, expected drwxr-xr-x, got %s", + filepath.Join(bucketName, "a/b"), + info.Mode(), + ) } info, err = gcsAfs.Stat(dirName) if err != nil { @@ -800,7 +821,11 @@ func TestGcsMkdirAll(t *testing.T) { err = gcsAfs.RemoveAll(filepath.Join(bucketName, "a")) if err != nil { - t.Fatalf("failed to remove the folder %s with error: %s", filepath.Join(bucketName, "a"), err) + t.Fatalf( + "failed to remove the folder %s with error: %s", + filepath.Join(bucketName, "a"), + err, + ) } }) } diff --git a/iofs.go b/iofs.go index b13155ca..57ba5673 100644 --- a/iofs.go +++ b/iofs.go @@ -137,7 +137,7 @@ type readDirFile struct { var _ fs.ReadDirFile = readDirFile{} func (r readDirFile) ReadDir(n int) ([]fs.DirEntry, error) { - items, err := r.File.Readdir(n) + items, err := r.Readdir(n) if err != nil { return nil, err } @@ -161,7 +161,12 @@ var _ Fs = FromIOFS{} func (f FromIOFS) Create(name string) (File, error) { return nil, notImplemented("create", name) } -func (f FromIOFS) Mkdir(name string, perm os.FileMode) error { return notImplemented("mkdir", name) } +func (f FromIOFS) Mkdir( + name string, + perm os.FileMode, +) error { + return notImplemented("mkdir", name) +} func (f FromIOFS) MkdirAll(path string, perm os.FileMode) error { return notImplemented("mkdirall", path) diff --git a/iofs_test.go b/iofs_test.go index 0f126f0d..9af55001 100644 --- a/iofs_test.go +++ b/iofs_test.go @@ -291,7 +291,11 @@ func TestFromIOFS(t *testing.T) { } if lenFile := len(fsys["dir1/dir2/hello.txt"].Data); int64(lenFile) != stat.Size() { - t.Errorf("dir1/dir2/hello.txt stat told invalid size: expected %d, got %d", lenFile, stat.Size()) + t.Errorf( + "dir1/dir2/hello.txt stat told invalid size: expected %d, got %d", + lenFile, + stat.Size(), + ) return } }) @@ -427,21 +431,40 @@ func TestFromIOFS_File(t *testing.T) { } if len(expectedItems) != len(items) { - t.Errorf("Items count mismatch, expected %d, got %d", len(expectedItems), len(items)) + t.Errorf( + "Items count mismatch, expected %d, got %d", + len(expectedItems), + len(items), + ) return } for i, item := range items { if item.Name() != expectedItems[i].Name { - t.Errorf("Item %d: expected name %s, got %s", i, expectedItems[i].Name, item.Name()) + t.Errorf( + "Item %d: expected name %s, got %s", + i, + expectedItems[i].Name, + item.Name(), + ) } if item.IsDir() != expectedItems[i].IsDir { - t.Errorf("Item %d: expected IsDir %t, got %t", i, expectedItems[i].IsDir, item.IsDir()) + t.Errorf( + "Item %d: expected IsDir %t, got %t", + i, + expectedItems[i].IsDir, + item.IsDir(), + ) } if item.Size() != expectedItems[i].Size { - t.Errorf("Item %d: expected IsDir %d, got %d", i, expectedItems[i].Size, item.Size()) + t.Errorf( + "Item %d: expected IsDir %d, got %d", + i, + expectedItems[i].Size, + item.Size(), + ) } } }) @@ -471,7 +494,11 @@ func TestFromIOFS_File(t *testing.T) { expectedItems := []string{"dir1", "dir2", "test.txt"} if len(expectedItems) != len(items) { - t.Errorf("Items count mismatch, expected %d, got %d", len(expectedItems), len(items)) + t.Errorf( + "Items count mismatch, expected %d, got %d", + len(expectedItems), + len(items), + ) return } diff --git a/ioutil_test.go b/ioutil_test.go index 004c66ba..edeaf453 100644 --- a/ioutil_test.go +++ b/ioutil_test.go @@ -152,6 +152,7 @@ func TestTempFile(t *testing.T) { pattern: "foo-*.bar", }, want: func(t *testing.T, base string) { + //nolint: staticcheck if !(strings.HasPrefix(base, "foo-") || strings.HasPrefix(base, "bar")) || len(base) <= len("foo-*.bar") { t.Errorf("TempFile() file = %v, invalid file name", base) diff --git a/lstater.go b/lstater.go index 89c1bfc0..360edf93 100644 --- a/lstater.go +++ b/lstater.go @@ -21,7 +21,7 @@ import ( // filesystems saying so. // It will call Lstat if the filesystem iself is, or it delegates to, the os filesystem. // Else it will call Stat. -// In addtion to the FileInfo, it will return a boolean telling whether Lstat was called or not. +// In addition to the FileInfo, it will return a boolean telling whether Lstat was called or not. type Lstater interface { LstatIfPossible(name string) (os.FileInfo, bool, error) } diff --git a/mem/file.go b/mem/file.go index 62fe4498..c77fcd40 100644 --- a/mem/file.go +++ b/mem/file.go @@ -150,7 +150,11 @@ func (f *File) Sync() error { func (f *File) Readdir(count int) (res []os.FileInfo, err error) { if !f.fileData.dir { - return nil, &os.PathError{Op: "readdir", Path: f.fileData.name, Err: errors.New("not a dir")} + return nil, &os.PathError{ + Op: "readdir", + Path: f.fileData.name, + Err: errors.New("not a dir"), + } } var outLength int64 @@ -236,7 +240,11 @@ func (f *File) Truncate(size int64) error { return ErrFileClosed } if f.readOnly { - return &os.PathError{Op: "truncate", Path: f.fileData.name, Err: errors.New("file handle is read only")} + return &os.PathError{ + Op: "truncate", + Path: f.fileData.name, + Err: errors.New("file handle is read only"), + } } if size < 0 { return ErrOutOfRange @@ -273,7 +281,11 @@ func (f *File) Write(b []byte) (n int, err error) { return 0, ErrFileClosed } if f.readOnly { - return 0, &os.PathError{Op: "write", Path: f.fileData.name, Err: errors.New("file handle is read only")} + return 0, &os.PathError{ + Op: "write", + Path: f.fileData.name, + Err: errors.New("file handle is read only"), + } } n = len(b) cur := atomic.LoadInt64(&f.at) @@ -285,7 +297,9 @@ func (f *File) Write(b []byte) (n int, err error) { tail = f.fileData.data[n+int(cur):] } if diff > 0 { - f.fileData.data = append(f.fileData.data, append(bytes.Repeat([]byte{0o0}, int(diff)), b...)...) + f.fileData.data = append( + f.fileData.data, + append(bytes.Repeat([]byte{0o0}, int(diff)), b...)...) f.fileData.data = append(f.fileData.data, tail...) } else { f.fileData.data = append(f.fileData.data[:cur], b...) diff --git a/sftpfs/sftp_test.go b/sftpfs/sftp_test.go index 505807bb..620d0356 100644 --- a/sftpfs/sftp_test.go +++ b/sftpfs/sftp_test.go @@ -223,7 +223,10 @@ func MakeSSHKeyPair(bits int, pubKeyPath, privateKeyPath string) error { return err } - privateKeyPEM := &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(privateKey)} + privateKeyPEM := &pem.Block{ + Type: "RSA PRIVATE KEY", + Bytes: x509.MarshalPKCS1PrivateKey(privateKey), + } if err := pem.Encode(privateKeyFile, privateKeyPEM); err != nil { return err } diff --git a/symlink_test.go b/symlink_test.go index 77dd742f..aa5b63b0 100644 --- a/symlink_test.go +++ b/symlink_test.go @@ -79,7 +79,12 @@ func TestSymlinkIfPossible(t *testing.T) { testLink(osFs, osPath, filepath.Join(workDir, "os/link.txt"), nil) testLink(overlayFs1, osPath, filepath.Join(workDir, "overlay/link1.txt"), ¬Supported) testLink(overlayFs2, pathFileMem, filepath.Join(workDir, "overlay2/link2.txt"), nil) - testLink(overlayFsMemOnly, pathFileMem, filepath.Join(memWorkDir, "overlay3/link.txt"), ¬Supported) + testLink( + overlayFsMemOnly, + pathFileMem, + filepath.Join(memWorkDir, "overlay3/link.txt"), + ¬Supported, + ) testLink(basePathFs, "afero.txt", "basepath/link.txt", nil) testLink(basePathFsMem, pathFileMem, "link/file.txt", ¬Supported) testLink(roFs, osPath, filepath.Join(workDir, "ro/link.txt"), ¬Supported) diff --git a/tarfs/tarfs_test.go b/tarfs/tarfs_test.go index 228ed9b4..6310a116 100644 --- a/tarfs/tarfs_test.go +++ b/tarfs/tarfs_test.go @@ -185,7 +185,14 @@ func TestSeek(t *testing.T) { } if n != s.offout { - t.Errorf("%v: (off: %v, whence: %v): got %v, expected %v", f.name, s.offin, s.whence, n, s.offout) + t.Errorf( + "%v: (off: %v, whence: %v): got %v, expected %v", + f.name, + s.offin, + s.whence, + n, + s.offout, + ) } } diff --git a/unionFile.go b/unionFile.go index 62dd6c93..2e2253f5 100644 --- a/unionFile.go +++ b/unionFile.go @@ -92,7 +92,8 @@ func (f *UnionFile) Seek(o int64, w int) (pos int64, err error) { func (f *UnionFile) Write(s []byte) (n int, err error) { if f.Layer != nil { n, err = f.Layer.Write(s) - if err == nil && f.Base != nil { // hmm, do we have fixed size files where a write may hit the EOF mark? + if err == nil && + f.Base != nil { // hmm, do we have fixed size files where a write may hit the EOF mark? _, err = f.Base.Write(s) } return n, err @@ -157,7 +158,7 @@ var defaultUnionMergeDirsFn = func(lofi, bofi []os.FileInfo) ([]os.FileInfo, err // return a single view of the overlayed directories. // At the end of the directory view, the error is io.EOF if c > 0. func (f *UnionFile) Readdir(c int) (ofi []os.FileInfo, err error) { - var merge DirsMerger = f.Merger + merge := f.Merger if merge == nil { merge = defaultUnionMergeDirsFn } diff --git a/util.go b/util.go index 9e4cba27..23176883 100644 --- a/util.go +++ b/util.go @@ -113,11 +113,11 @@ func GetTempDir(fs Fs, subPath string) string { if subPath != "" { // preserve windows backslash :-( if FilePathSeparator == "\\" { - subPath = strings.Replace(subPath, "\\", "____", -1) + subPath = strings.ReplaceAll(subPath, "\\", "____") } dir = dir + UnicodeSanitize((subPath)) if FilePathSeparator == "\\" { - dir = strings.Replace(dir, "____", "\\", -1) + dir = strings.ReplaceAll(dir, "____", "\\") } if exists, _ := Exists(fs, dir); exists { diff --git a/util_test.go b/util_test.go index 13ec23b1..a8e7212f 100644 --- a/util_test.go +++ b/util_test.go @@ -102,7 +102,7 @@ func TestIsEmpty(t *testing.T) { nonEmptyNonZeroLengthFilesDirectory, _ := createTempDirWithNonZeroLengthFiles() defer deleteTempDir(nonEmptyNonZeroLengthFilesDirectory) nonExistentFile := os.TempDir() + "/this-file-does-not-exist.txt" - nonExistentDir := os.TempDir() + "/this/direcotry/does/not/exist/" + nonExistentDir := os.TempDir() + "/this/directory/does/not/exist/" fileDoesNotExist := fmt.Errorf("%q path does not exist", nonExistentFile) dirDoesNotExist := fmt.Errorf("%q path does not exist", nonExistentDir) @@ -125,11 +125,24 @@ func TestIsEmpty(t *testing.T) { for i, d := range data { exists, err := IsEmpty(testFS, d.input) if d.expectedResult != exists { - t.Errorf("Test %d %q failed exists. Expected result %t got %t", i, d.input, d.expectedResult, exists) + t.Errorf( + "Test %d %q failed exists. Expected result %t got %t", + i, + d.input, + d.expectedResult, + exists, + ) } if d.expectedErr != nil { if d.expectedErr.Error() != err.Error() { - t.Errorf("Test %d failed with err. Expected %q(%#v) got %q(%#v)", i, d.expectedErr, d.expectedErr, err, err) + t.Errorf( + "Test %d failed with err. Expected %q(%#v) got %q(%#v)", + i, + d.expectedErr, + d.expectedErr, + err, + err, + ) } } else { if d.expectedErr != err { @@ -267,7 +280,7 @@ func TestExists(t *testing.T) { emptyDirectory, _ := createEmptyTempDir() defer deleteTempDir(emptyDirectory) nonExistentFile := os.TempDir() + "/this-file-does-not-exist.txt" - nonExistentDir := os.TempDir() + "/this/direcotry/does/not/exist/" + nonExistentDir := os.TempDir() + "/this/directory/does/not/exist/" type test struct { input string @@ -320,7 +333,12 @@ func TestSafeWriteToDisk(t *testing.T) { e := SafeWriteReader(testFS, d.filename, reader) if d.expectedErr != nil { if d.expectedErr.Error() != e.Error() { - t.Errorf("Test %d failed. Expected error %q but got %q", i, d.expectedErr.Error(), e.Error()) + t.Errorf( + "Test %d failed. Expected error %q but got %q", + i, + d.expectedErr.Error(), + e.Error(), + ) } } else { if d.expectedErr != e { @@ -359,14 +377,24 @@ func TestWriteToDisk(t *testing.T) { for i, d := range data { e := WriteReader(testFS, d.filename, reader) if d.expectedErr != e { - t.Errorf("Test %d failed. WriteToDisk Error Expected %q but got %q", i, d.expectedErr, e) + t.Errorf( + "Test %d failed. WriteToDisk Error Expected %q but got %q", + i, + d.expectedErr, + e, + ) } contents, e := ReadFile(testFS, d.filename) if e != nil { t.Errorf("Test %d failed. Could not read file %s. Reason: %s\n", i, d.filename, e) } if randomString != string(contents) { - t.Errorf("Test %d failed. Expected contents %q but got %q", i, randomString, string(contents)) + t.Errorf( + "Test %d failed. Expected contents %q but got %q", + i, + randomString, + string(contents), + ) } reader.Seek(0, 0) } @@ -384,7 +412,10 @@ func TestGetTempDir(t *testing.T) { }{ {"", dir}, {testDir + " Foo bar ", dir + testDir + " Foo bar " + FilePathSeparator}, - {testDir + "Foo.Bar/foo_Bar-Foo", dir + testDir + "Foo.Bar/foo_Bar-Foo" + FilePathSeparator}, + { + testDir + "Foo.Bar/foo_Bar-Foo", + dir + testDir + "Foo.Bar/foo_Bar-Foo" + FilePathSeparator, + }, {testDir + "fOO,bar:foo%bAR", dir + testDir + "fOObarfoo%bAR" + FilePathSeparator}, {testDir + "FOo/BaR.html", dir + testDir + "FOo/BaR.html" + FilePathSeparator}, {testDir + "трям/трям", dir + testDir + "трям/трям" + FilePathSeparator}, @@ -431,9 +462,21 @@ func TestFullBaseFsPath(t *testing.T) { ExpectedPath string } specs := []spec{ - {BaseFs: level3Fs, FileName: "f.txt", ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, ds.Dir3, "f.txt")}, - {BaseFs: level3Fs, FileName: "", ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, ds.Dir3, "")}, - {BaseFs: level2Fs, FileName: "f.txt", ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, "f.txt")}, + { + BaseFs: level3Fs, + FileName: "f.txt", + ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, ds.Dir3, "f.txt"), + }, + { + BaseFs: level3Fs, + FileName: "", + ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, ds.Dir3, ""), + }, + { + BaseFs: level2Fs, + FileName: "f.txt", + ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, "f.txt"), + }, {BaseFs: level2Fs, FileName: "", ExpectedPath: filepath.Join(ds.Dir1, ds.Dir2, "")}, {BaseFs: level1Fs, FileName: "f.txt", ExpectedPath: filepath.Join(ds.Dir1, "f.txt")}, {BaseFs: level1Fs, FileName: "", ExpectedPath: filepath.Join(ds.Dir1, "")}, From 90b8ab916e1ef9ec14be32c80010445b4b1eac26 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Sat, 12 Apr 2025 14:21:09 +0200 Subject: [PATCH 6/6] ci: fix scorecard branch Signed-off-by: Mark Sagi-Kazar --- .github/workflows/analysis-scorecard.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/analysis-scorecard.yaml b/.github/workflows/analysis-scorecard.yaml index 5fce75fb..6f686cc0 100644 --- a/.github/workflows/analysis-scorecard.yaml +++ b/.github/workflows/analysis-scorecard.yaml @@ -3,7 +3,7 @@ name: OpenSSF Scorecard on: branch_protection_rule: push: - branches: [main] + branches: [master] schedule: - cron: "30 0 * * 5"