From e603bdf2737b12dbc7f8813c7818190cc5f0297e Mon Sep 17 00:00:00 2001 From: web3-bot Date: Thu, 1 Sep 2022 09:14:34 +0000 Subject: [PATCH 1/5] bump go.mod to Go 1.18 and run go fix --- filewriter_unix.go | 1 - filewriter_unix_test.go | 1 - filewriter_windows.go | 1 - filewriter_windows_test.go | 1 - go.mod | 2 +- is_hidden.go | 1 - is_hidden_windows.go | 1 - 7 files changed, 1 insertion(+), 7 deletions(-) diff --git a/filewriter_unix.go b/filewriter_unix.go index 8252e21..98d0400 100644 --- a/filewriter_unix.go +++ b/filewriter_unix.go @@ -1,5 +1,4 @@ //go:build darwin || linux || netbsd || openbsd || freebsd || dragonfly -// +build darwin linux netbsd openbsd freebsd dragonfly package files diff --git a/filewriter_unix_test.go b/filewriter_unix_test.go index 09aeb91..14c1967 100644 --- a/filewriter_unix_test.go +++ b/filewriter_unix_test.go @@ -1,5 +1,4 @@ //go:build darwin || linux || netbsd || openbsd -// +build darwin linux netbsd openbsd package files diff --git a/filewriter_windows.go b/filewriter_windows.go index 4392e0e..a5d6261 100644 --- a/filewriter_windows.go +++ b/filewriter_windows.go @@ -1,5 +1,4 @@ //go:build windows -// +build windows package files diff --git a/filewriter_windows_test.go b/filewriter_windows_test.go index 4193ac9..586a9db 100644 --- a/filewriter_windows_test.go +++ b/filewriter_windows_test.go @@ -1,5 +1,4 @@ //go:build windows -// +build windows package files diff --git a/go.mod b/go.mod index 982ae65..3103656 100644 --- a/go.mod +++ b/go.mod @@ -12,4 +12,4 @@ require ( gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect ) -go 1.17 +go 1.18 diff --git a/is_hidden.go b/is_hidden.go index 9ab08f7..9842ca2 100644 --- a/is_hidden.go +++ b/is_hidden.go @@ -1,5 +1,4 @@ //go:build !windows -// +build !windows package files diff --git a/is_hidden_windows.go b/is_hidden_windows.go index a8b95ca..9a07038 100644 --- a/is_hidden_windows.go +++ b/is_hidden_windows.go @@ -1,5 +1,4 @@ //go:build windows -// +build windows package files From c2dbc997b17a8d211c9f51a18755827efdac0836 Mon Sep 17 00:00:00 2001 From: web3-bot Date: Thu, 1 Sep 2022 09:14:40 +0000 Subject: [PATCH 2/5] stop using the deprecated io/ioutil package --- filewriter_test.go | 7 +++---- filewriter_unix_test.go | 3 +-- filewriter_windows_test.go | 3 +-- filter_test.go | 5 ++--- helpers_test.go | 4 ++-- multipartfile.go | 3 +-- readerfile.go | 3 +-- serialfile.go | 3 +-- serialfile_test.go | 8 ++++---- webfile_test.go | 10 +++++----- 10 files changed, 21 insertions(+), 28 deletions(-) diff --git a/filewriter_test.go b/filewriter_test.go index c61e29f..00a0b1c 100644 --- a/filewriter_test.go +++ b/filewriter_test.go @@ -2,7 +2,6 @@ package files import ( "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -20,7 +19,7 @@ func TestWriteTo(t *testing.T) { "a": NewBytesFile([]byte("foobar")), }), }) - tmppath, err := ioutil.TempDir("", "files-test") + tmppath, err := os.MkdirTemp("", "files-test") if err != nil { t.Fatal(err) } @@ -60,7 +59,7 @@ func TestWriteTo(t *testing.T) { return fmt.Errorf("expected a directory at %q", rpath) } } else { - actual, err := ioutil.ReadFile(cpath) + actual, err := os.ReadFile(cpath) if err != nil { return err } @@ -79,7 +78,7 @@ func TestWriteTo(t *testing.T) { } func TestDontAllowOverwrite(t *testing.T) { - tmppath, err := ioutil.TempDir("", "files-test") + tmppath, err := os.MkdirTemp("", "files-test") assert.NoError(t, err) defer os.RemoveAll(tmppath) diff --git a/filewriter_unix_test.go b/filewriter_unix_test.go index 14c1967..ffc33ce 100644 --- a/filewriter_unix_test.go +++ b/filewriter_unix_test.go @@ -3,7 +3,6 @@ package files import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -12,7 +11,7 @@ import ( ) func TestWriteToInvalidPaths(t *testing.T) { - tmppath, err := ioutil.TempDir("", "files-test") + tmppath, err := os.MkdirTemp("", "files-test") assert.NoError(t, err) defer os.RemoveAll(tmppath) diff --git a/filewriter_windows_test.go b/filewriter_windows_test.go index 586a9db..ca0222b 100644 --- a/filewriter_windows_test.go +++ b/filewriter_windows_test.go @@ -3,7 +3,6 @@ package files import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -12,7 +11,7 @@ import ( ) func TestWriteToInvalidPaths(t *testing.T) { - tmppath, err := ioutil.TempDir("", "files-test") + tmppath, err := os.MkdirTemp("", "files-test") assert.NoError(t, err) defer os.RemoveAll(tmppath) diff --git a/filter_test.go b/filter_test.go index ad2e48c..8ce25ee 100644 --- a/filter_test.go +++ b/filter_test.go @@ -1,7 +1,6 @@ package files import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -35,13 +34,13 @@ func TestFileFilter(t *testing.T) { if err == nil { t.Errorf("creating a filter without an invalid ignore file path should have failed") } - tmppath, err := ioutil.TempDir("", "filter-test") + tmppath, err := os.MkdirTemp("", "filter-test") if err != nil { t.Fatal(err) } ignoreFilePath := filepath.Join(tmppath, "ignoreFile") ignoreFileContents := []byte("a.txt") - if err := ioutil.WriteFile(ignoreFilePath, ignoreFileContents, 0666); err != nil { + if err := os.WriteFile(ignoreFilePath, ignoreFileContents, 0666); err != nil { t.Fatal(err) } filterWithIgnoreFile, err := NewFilter(ignoreFilePath, nil, false) diff --git a/helpers_test.go b/helpers_test.go index ec420bd..0180b8f 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -1,7 +1,7 @@ package files import ( - "io/ioutil" + "io" "testing" ) @@ -56,7 +56,7 @@ func CheckDir(t *testing.T, dir Directory, expected []Event) { if !ok { t.Fatalf("[%d] expected file to be a normal file: %T", i, it.Node()) } - out, err := ioutil.ReadAll(mf) + out, err := io.ReadAll(mf) if err != nil { t.Errorf("[%d] failed to read file", i) continue diff --git a/multipartfile.go b/multipartfile.go index 24211cd..2765398 100644 --- a/multipartfile.go +++ b/multipartfile.go @@ -2,7 +2,6 @@ package files import ( "io" - "io/ioutil" "mime" "mime/multipart" "net/url" @@ -94,7 +93,7 @@ func (w *multipartWalker) nextFile() (Node, error) { walker: w, }, nil case applicationSymlink: - out, err := ioutil.ReadAll(part) + out, err := io.ReadAll(part) if err != nil { return nil, err } diff --git a/readerfile.go b/readerfile.go index f98fec4..a03dae2 100644 --- a/readerfile.go +++ b/readerfile.go @@ -3,7 +3,6 @@ package files import ( "bytes" "io" - "io/ioutil" "os" "path/filepath" ) @@ -29,7 +28,7 @@ func NewReaderFile(reader io.Reader) File { func NewReaderStatFile(reader io.Reader, stat os.FileInfo) File { rc, ok := reader.(io.ReadCloser) if !ok { - rc = ioutil.NopCloser(reader) + rc = io.NopCloser(reader) } return &ReaderFile{"", rc, stat, -1} diff --git a/serialfile.go b/serialfile.go index 86af306..77871d3 100644 --- a/serialfile.go +++ b/serialfile.go @@ -3,7 +3,6 @@ package files import ( "errors" "fmt" - "io/ioutil" "os" "path/filepath" ) @@ -52,7 +51,7 @@ func NewSerialFileWithFilter(path string, filter *Filter, stat os.FileInfo) (Nod case mode.IsDir(): // for directories, stat all of the contents first, so we know what files to // open when Entries() is called - contents, err := ioutil.ReadDir(path) + contents, err := os.ReadDir(path) if err != nil { return nil, err } diff --git a/serialfile_test.go b/serialfile_test.go index ae76396..80c252a 100644 --- a/serialfile_test.go +++ b/serialfile_test.go @@ -2,7 +2,7 @@ package files import ( "fmt" - "io/ioutil" + "io" "os" "path/filepath" "sort" @@ -22,7 +22,7 @@ func TestSerialFile(t *testing.T) { } func testSerialFile(t *testing.T, hidden, withIgnoreRules bool) { - tmppath, err := ioutil.TempDir("", "files-test") + tmppath, err := os.MkdirTemp("", "files-test") if err != nil { t.Fatal(err) } @@ -67,7 +67,7 @@ func testSerialFile(t *testing.T, hidden, withIgnoreRules bool) { if c == "" { continue } - if err := ioutil.WriteFile(path, []byte(c), 0666); err != nil { + if err := os.WriteFile(path, []byte(c), 0666); err != nil { t.Fatal(err) } } @@ -158,7 +158,7 @@ testInputs: return fmt.Errorf("expected a directory at %q", path) } case File: - actual, err := ioutil.ReadAll(nd) + actual, err := io.ReadAll(nd) if err != nil { return err } diff --git a/webfile_test.go b/webfile_test.go index 57a67fe..94cddb5 100644 --- a/webfile_test.go +++ b/webfile_test.go @@ -2,7 +2,7 @@ package files import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/url" @@ -21,7 +21,7 @@ func TestWebFile(t *testing.T) { t.Fatal(err) } wf := NewWebFile(u) - body, err := ioutil.ReadAll(wf) + body, err := io.ReadAll(wf) if err != nil { t.Fatal(err) } @@ -41,7 +41,7 @@ func TestWebFile_notFound(t *testing.T) { t.Fatal(err) } wf := NewWebFile(u) - _, err = ioutil.ReadAll(wf) + _, err = io.ReadAll(wf) if err == nil { t.Fatal("expected error") } @@ -68,7 +68,7 @@ func TestWebFileSize(t *testing.T) { t.Errorf("expected size to be %d, got %d", len(body), size) } - actual, err := ioutil.ReadAll(wf1) + actual, err := io.ReadAll(wf1) if err != nil { t.Fatal(err) } @@ -81,7 +81,7 @@ func TestWebFileSize(t *testing.T) { // Read size after reading file. wf2 := NewWebFile(u) - actual, err = ioutil.ReadAll(wf2) + actual, err = io.ReadAll(wf2) if err != nil { t.Fatal(err) } From 178229e462cf21e4ba7a59bc69b3318f998d1dd4 Mon Sep 17 00:00:00 2001 From: web3-bot Date: Thu, 1 Sep 2022 09:14:41 +0000 Subject: [PATCH 3/5] update .github/workflows/go-test.yml --- .github/workflows/go-test.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index b86241a..8a1697b 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -10,16 +10,16 @@ jobs: fail-fast: false matrix: os: [ "ubuntu", "windows", "macos" ] - go: [ "1.17.x", "1.18.x" ] + go: [ "1.18.x", "1.19.x" ] env: COVERAGES: "" runs-on: ${{ format('{0}-latest', matrix.os) }} name: ${{ matrix.os }} (go ${{ matrix.go }}) steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: recursive - - uses: actions/setup-go@v2 + - uses: actions/setup-go@v3 with: go-version: ${{ matrix.go }} - name: Go information @@ -43,7 +43,7 @@ jobs: # Use -coverpkg=./..., so that we include cross-package coverage. # If package ./A imports ./B, and ./A's tests also cover ./B, # this means ./B's coverage will be significantly higher than 0%. - run: go test -v -coverprofile=module-coverage.txt -coverpkg=./... ./... + run: go test -v -shuffle=on -coverprofile=module-coverage.txt -coverpkg=./... ./... - name: Run tests (32 bit) if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX. uses: protocol/multiple-go-modules@v1.2 @@ -52,7 +52,7 @@ jobs: with: run: | export "PATH=${{ env.PATH_386 }}:$PATH" - go test -v ./... + go test -v -shuffle=on ./... - name: Run tests with race detector if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow uses: protocol/multiple-go-modules@v1.2 @@ -62,7 +62,7 @@ jobs: shell: bash run: echo "COVERAGES=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV - name: Upload coverage to Codecov - uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0 + uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0 with: files: '${{ env.COVERAGES }}' env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }} From 84dc4b8a7a615685c107d150ead658bc41d21606 Mon Sep 17 00:00:00 2001 From: web3-bot Date: Thu, 1 Sep 2022 09:14:41 +0000 Subject: [PATCH 4/5] update .github/workflows/go-check.yml --- .github/workflows/go-check.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go-check.yml b/.github/workflows/go-check.yml index 25e1afd..251f7fa 100644 --- a/.github/workflows/go-check.yml +++ b/.github/workflows/go-check.yml @@ -11,12 +11,12 @@ jobs: env: RUNGOGENERATE: false steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: recursive - - uses: actions/setup-go@v2 + - uses: actions/setup-go@v3 with: - go-version: "1.18.x" + go-version: "1.19.x" - name: Run repo-specific setup uses: ./.github/actions/go-check-setup if: hashFiles('./.github/actions/go-check-setup') != '' @@ -27,7 +27,7 @@ jobs: echo "RUNGOGENERATE=true" >> $GITHUB_ENV fi - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@d7e217c1ff411395475b2971c0824e1e7cc1af98 # 2022.1 (v0.3.0) + run: go install honnef.co/go/tools/cmd/staticcheck@376210a89477dedbe6fdc4484b233998650d7b3c # 2022.1.3 (v0.3.3) - name: Check that go.mod is tidy uses: protocol/multiple-go-modules@v1.2 with: From 263276c1f170d34e51279193ee44eb3f3d00d40b Mon Sep 17 00:00:00 2001 From: galargh Date: Thu, 1 Sep 2022 11:33:55 +0200 Subject: [PATCH 5/5] fix: type of contents in serialfile --- serialfile.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/serialfile.go b/serialfile.go index 77871d3..176038c 100644 --- a/serialfile.go +++ b/serialfile.go @@ -3,6 +3,7 @@ package files import ( "errors" "fmt" + "io/fs" "os" "path/filepath" ) @@ -51,10 +52,18 @@ func NewSerialFileWithFilter(path string, filter *Filter, stat os.FileInfo) (Nod case mode.IsDir(): // for directories, stat all of the contents first, so we know what files to // open when Entries() is called - contents, err := os.ReadDir(path) + entries, err := os.ReadDir(path) if err != nil { return nil, err } + contents := make([]fs.FileInfo, 0, len(entries)) + for _, entry := range entries { + content, err := entry.Info() + if err != nil { + return nil, err + } + contents = append(contents, content) + } return &serialFile{path, contents, stat, filter}, nil case mode&os.ModeSymlink != 0: target, err := os.Readlink(path)