From cc456d75d3ee9a3c727b2784415fd47d2c5e7b70 Mon Sep 17 00:00:00 2001 From: web3-bot Date: Thu, 1 Sep 2022 09:13:27 +0000 Subject: [PATCH 1/4] bump go.mod to Go 1.18 and run go fix --- go.mod | 2 +- rename.go | 1 - util_unix.go | 1 - util_windows.go | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 6f71afa..c273d54 100644 --- a/go.mod +++ b/go.mod @@ -18,4 +18,4 @@ require ( go.uber.org/zap v1.10.0 // indirect ) -go 1.17 +go 1.18 diff --git a/rename.go b/rename.go index 7e2f5ac..6a7b83b 100644 --- a/rename.go +++ b/rename.go @@ -1,5 +1,4 @@ //go:build !plan9 -// +build !plan9 package flatfs diff --git a/util_unix.go b/util_unix.go index d138c2e..c022650 100644 --- a/util_unix.go +++ b/util_unix.go @@ -1,5 +1,4 @@ //go:build !windows -// +build !windows package flatfs diff --git a/util_windows.go b/util_windows.go index 41b107a..e9a4e28 100644 --- a/util_windows.go +++ b/util_windows.go @@ -1,5 +1,4 @@ //go:build windows -// +build windows // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style From 6b60b287ee2ec2e0a5a83b7a2dfe310bfbb6e8ce Mon Sep 17 00:00:00 2001 From: web3-bot Date: Thu, 1 Sep 2022 09:13:30 +0000 Subject: [PATCH 2/4] stop using the deprecated io/ioutil package --- convert_test.go | 3 +-- flatfs.go | 4 ++-- flatfs/main.go | 2 +- flatfs_test.go | 13 ++++++------- shard.go | 5 ++--- sync.go | 2 +- util_unix.go | 5 ++--- util_windows.go | 4 ++-- 8 files changed, 17 insertions(+), 21 deletions(-) diff --git a/convert_test.go b/convert_test.go index 45ebf29..549c0fa 100644 --- a/convert_test.go +++ b/convert_test.go @@ -3,7 +3,6 @@ package flatfs_test import ( "bytes" "encoding/base32" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -22,7 +21,7 @@ func TestMove(t *testing.T) { v1dir := filepath.Join(tempdir, "v1") createDatastore(t, v1dir, flatfs.Prefix(3)) - err := ioutil.WriteFile(filepath.Join(v1dir, "README_ALSO"), []byte("something"), 0666) + err := os.WriteFile(filepath.Join(v1dir, "README_ALSO"), []byte("something"), 0666) if err != nil { t.Fatalf("WriteFile fail: %v\n", err) } diff --git a/flatfs.go b/flatfs.go index 1df6659..2f4e400 100644 --- a/flatfs.go +++ b/flatfs.go @@ -184,8 +184,8 @@ type opResult struct { // Begins starts the processing of an op: // - if no other op for the same key exist, register it and return immediately // - if another op exist for the same key, wait until it's done: -// - if that previous op succeeded, consider that ours shouldn't execute and return nil -// - if that previous op failed, start ours +// - if that previous op succeeded, consider that ours shouldn't execute and return nil +// - if that previous op failed, start ours func (m *opMap) Begin(name string) *opResult { for { myOp := &opResult{opMap: m, name: name} diff --git a/flatfs/main.go b/flatfs/main.go index 2f76281..0495e16 100644 --- a/flatfs/main.go +++ b/flatfs/main.go @@ -5,7 +5,7 @@ import ( "os" "strconv" - "github.com/ipfs/go-ds-flatfs" + flatfs "github.com/ipfs/go-ds-flatfs" ) // To convert from the old format to a new format with a different diff --git a/flatfs_test.go b/flatfs_test.go index 9484fd7..fe85b2b 100644 --- a/flatfs_test.go +++ b/flatfs_test.go @@ -5,7 +5,6 @@ import ( "encoding/base32" "encoding/json" "fmt" - "io/ioutil" "math" "math/rand" "os" @@ -47,7 +46,7 @@ func checkTemp(t *testing.T, dir string) { } func tempdir(t testing.TB) (path string, cleanup func()) { - path, err := ioutil.TempDir("", "test-datastore-flatfs-") + path, err := os.MkdirTemp("", "test-datastore-flatfs-") if err != nil { t.Fatalf("cannot create temp directory: %v", err) } @@ -281,7 +280,7 @@ func testStorage(p *params, t *testing.T) { case ".", "..", "SHARDING", flatfs.DiskUsageFile, ".temp": // ignore case "_README": - _, err := ioutil.ReadFile(absPath) + _, err := os.ReadFile(absPath) if err != nil { t.Error("could not read _README file") } @@ -587,7 +586,7 @@ func testDiskUsage(dirFunc mkShardFunc, t *testing.T) { fs.Close() // Check that disk usage file is correct - duB, err := ioutil.ReadFile(filepath.Join(temp, flatfs.DiskUsageFile)) + duB, err := os.ReadFile(filepath.Join(temp, flatfs.DiskUsageFile)) if err != nil { t.Fatal(err) } @@ -1012,7 +1011,7 @@ func TestNonDatastoreDir(t *testing.T) { tempdir, cleanup := tempdir(t) defer cleanup() - err := ioutil.WriteFile(filepath.Join(tempdir, "afile"), []byte("Some Content"), 0644) + err := os.WriteFile(filepath.Join(tempdir, "afile"), []byte("Some Content"), 0644) if err != nil { t.Fatal(err) } @@ -1059,7 +1058,7 @@ func TestNoCluster(t *testing.T) { } fs.Close() - dirs, err := ioutil.ReadDir(tempdir) + dirs, err := os.ReadDir(tempdir) if err != nil { t.Fatalf("ReadDir fail: %v\n", err) } @@ -1072,7 +1071,7 @@ func TestNoCluster(t *testing.T) { continue } count += 1 - files, err := ioutil.ReadDir(filepath.Join(tempdir, dir.Name())) + files, err := os.ReadDir(filepath.Join(tempdir, dir.Name())) if err != nil { t.Fatalf("ReadDir fail: %v\n", err) } diff --git a/shard.go b/shard.go index c72f68f..65c202c 100644 --- a/shard.go +++ b/shard.go @@ -2,7 +2,6 @@ package flatfs import ( "fmt" - "io/ioutil" "os" "path/filepath" "strconv" @@ -118,7 +117,7 @@ func ParseShardFunc(str string) (*ShardIdV1, error) { } func ReadShardFunc(dir string) (*ShardIdV1, error) { - buf, err := ioutil.ReadFile(filepath.Join(dir, SHARDING_FN)) + buf, err := os.ReadFile(filepath.Join(dir, SHARDING_FN)) if os.IsNotExist(err) { return nil, ErrShardingFileMissing } else if err != nil { @@ -143,7 +142,7 @@ func WriteShardFunc(dir string, id *ShardIdV1) error { func WriteReadme(dir string, id *ShardIdV1) error { if id.String() == IPFS_DEF_SHARD.String() { - err := ioutil.WriteFile(filepath.Join(dir, README_FN), []byte(README_IPFS_DEF_SHARD), 0444) + err := os.WriteFile(filepath.Join(dir, README_FN), []byte(README_IPFS_DEF_SHARD), 0444) if err != nil { return err } diff --git a/sync.go b/sync.go index bf38c16..c670dc1 100644 --- a/sync.go +++ b/sync.go @@ -9,7 +9,7 @@ import ( // 16 should be able to sataurate most RAIDs // in case of two used disks per write (RAID 1, 5) and queue depth of 2, // 16 concurrent Sync calls should be able to saturate 16 HDDs RAID -//TODO: benchmark it out, maybe provide tweak parmeter +// TODO: benchmark it out, maybe provide tweak parmeter const SyncThreadsMax = 16 var syncSemaphore chan struct{} = make(chan struct{}, SyncThreadsMax) diff --git a/util_unix.go b/util_unix.go index c022650..47ba1d4 100644 --- a/util_unix.go +++ b/util_unix.go @@ -3,14 +3,13 @@ package flatfs import ( - "io/ioutil" "os" ) func tempFileOnce(dir, pattern string) (*os.File, error) { - return ioutil.TempFile(dir, pattern) + return os.CreateTemp(dir, pattern) } func readFileOnce(filename string) ([]byte, error) { - return ioutil.ReadFile(filename) + return os.ReadFile(filename) } diff --git a/util_windows.go b/util_windows.go index e9a4e28..7a0c3af 100644 --- a/util_windows.go +++ b/util_windows.go @@ -12,7 +12,7 @@ package flatfs import ( "bytes" - "io/ioutil" + "io" "os" "path/filepath" "strconv" @@ -97,5 +97,5 @@ func readFileOnce(filename string) ([]byte, error) { } } - return ioutil.ReadAll(f) + return io.ReadAll(f) } From b6550f9e39fcb233c4b3e76b6ef1daf204c59d17 Mon Sep 17 00:00:00 2001 From: web3-bot Date: Thu, 1 Sep 2022 09:13:31 +0000 Subject: [PATCH 3/4] 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 c5a442ebe936c0bac9c96b280c2760f1c797cc83 Mon Sep 17 00:00:00 2001 From: web3-bot Date: Thu, 1 Sep 2022 09:13:31 +0000 Subject: [PATCH 4/4] 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: