upgrade golang to 1.17 and replace iouitl with io and os (#297)

pull/192/head^2
Benjamin 2022-01-30 11:28:06 +08:00 committed by GitHub
parent 7d9f2ecba1
commit d5db64bdbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 24 additions and 15 deletions

View File

@ -1,3 +1,4 @@
//go:build arm64
// +build arm64 // +build arm64
package bbolt package bbolt

View File

@ -1,3 +1,4 @@
//go:build mips64 || mips64le
// +build mips64 mips64le // +build mips64 mips64le
package bbolt package bbolt

View File

@ -1,3 +1,4 @@
//go:build mips || mipsle
// +build mips mipsle // +build mips mipsle
package bbolt package bbolt

View File

@ -1,3 +1,4 @@
//go:build ppc
// +build ppc // +build ppc
package bbolt package bbolt

View File

@ -1,3 +1,4 @@
//go:build ppc64
// +build ppc64 // +build ppc64
package bbolt package bbolt

View File

@ -1,3 +1,4 @@
//go:build ppc64le
// +build ppc64le // +build ppc64le
package bbolt package bbolt

View File

@ -1,3 +1,4 @@
//go:build riscv64
// +build riscv64 // +build riscv64
package bbolt package bbolt

View File

@ -1,3 +1,4 @@
//go:build s390x
// +build s390x // +build s390x
package bbolt package bbolt

View File

@ -1,3 +1,4 @@
//go:build !windows && !plan9 && !solaris && !aix
// +build !windows,!plan9,!solaris,!aix // +build !windows,!plan9,!solaris,!aix
package bbolt package bbolt

View File

@ -1,3 +1,4 @@
//go:build aix
// +build aix // +build aix
package bbolt package bbolt

View File

@ -1,3 +1,4 @@
//go:build !windows && !plan9 && !linux && !openbsd
// +build !windows,!plan9,!linux,!openbsd // +build !windows,!plan9,!linux,!openbsd
package bbolt package bbolt

View File

@ -7,7 +7,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"os" "os"
"runtime" "runtime"
@ -1364,7 +1363,7 @@ func (cmd *BenchCommand) ParseFlags(args []string) (*BenchOptions, error) {
// Generate temp path if one is not passed in. // Generate temp path if one is not passed in.
if options.Path == "" { if options.Path == "" {
f, err := ioutil.TempFile("", "bolt-bench-") f, err := os.CreateTemp("", "bolt-bench-")
if err != nil { if err != nil {
return nil, fmt.Errorf("temp file: %s", err) return nil, fmt.Errorf("temp file: %s", err)
} }
@ -1951,7 +1950,7 @@ func newCompactCommand(m *Main) *CompactCommand {
func (cmd *CompactCommand) Run(args ...string) (err error) { func (cmd *CompactCommand) Run(args ...string) (err error) {
// Parse flags. // Parse flags.
fs := flag.NewFlagSet("", flag.ContinueOnError) fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.SetOutput(ioutil.Discard) fs.SetOutput(io.Discard)
fs.StringVar(&cmd.DstPath, "o", "", "") fs.StringVar(&cmd.DstPath, "o", "", "")
fs.Int64Var(&cmd.TxMaxSize, "tx-max-size", 65536, "") fs.Int64Var(&cmd.TxMaxSize, "tx-max-size", 65536, "")
if err := fs.Parse(args); err == flag.ErrHelp { if err := fs.Parse(args); err == flag.ErrHelp {

View File

@ -6,7 +6,6 @@ import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"os" "os"
"strconv" "strconv"
@ -265,7 +264,7 @@ func NewMain() *Main {
// MustOpen creates a Bolt database in a temporary location. // MustOpen creates a Bolt database in a temporary location.
func MustOpen(mode os.FileMode, options *bolt.Options) *DB { func MustOpen(mode os.FileMode, options *bolt.Options) *DB {
// Create temporary path. // Create temporary path.
f, _ := ioutil.TempFile("", "bolt-") f, _ := os.CreateTemp("", "bolt-")
f.Close() f.Close()
os.Remove(f.Name()) os.Remove(f.Name())

View File

@ -7,7 +7,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"hash/fnv" "hash/fnv"
"io/ioutil"
"log" "log"
"math/rand" "math/rand"
"os" "os"
@ -158,7 +157,7 @@ func TestOpen_ErrVersionMismatch(t *testing.T) {
} }
// Read data file. // Read data file.
buf, err := ioutil.ReadFile(path) buf, err := os.ReadFile(path)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -168,7 +167,7 @@ func TestOpen_ErrVersionMismatch(t *testing.T) {
meta0.version++ meta0.version++
meta1 := (*meta)(unsafe.Pointer(&buf[pageSize+pageHeaderSize])) meta1 := (*meta)(unsafe.Pointer(&buf[pageSize+pageHeaderSize]))
meta1.version++ meta1.version++
if err := ioutil.WriteFile(path, buf, 0666); err != nil { if err := os.WriteFile(path, buf, 0666); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -195,7 +194,7 @@ func TestOpen_ErrChecksum(t *testing.T) {
} }
// Read data file. // Read data file.
buf, err := ioutil.ReadFile(path) buf, err := os.ReadFile(path)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -205,7 +204,7 @@ func TestOpen_ErrChecksum(t *testing.T) {
meta0.pgid++ meta0.pgid++
meta1 := (*meta)(unsafe.Pointer(&buf[pageSize+pageHeaderSize])) meta1 := (*meta)(unsafe.Pointer(&buf[pageSize+pageHeaderSize]))
meta1.pgid++ meta1.pgid++
if err := ioutil.WriteFile(path, buf, 0666); err != nil { if err := os.WriteFile(path, buf, 0666); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -643,7 +642,7 @@ func TestDB_Concurrent_WriteTo(t *testing.T) {
wg.Add(wtxs * rtxs) wg.Add(wtxs * rtxs)
f := func(tx *bolt.Tx) { f := func(tx *bolt.Tx) {
defer wg.Done() defer wg.Done()
f, err := ioutil.TempFile("", "bolt-") f, err := os.CreateTemp("", "bolt-")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -1747,7 +1746,7 @@ func (db *DB) CopyTempFile() {
// tempfile returns a temporary file path. // tempfile returns a temporary file path.
func tempfile() string { func tempfile() string {
f, err := ioutil.TempFile("", "bolt-") f, err := os.CreateTemp("", "bolt-")
if err != nil { if err != nil {
panic(err) panic(err)
} }

2
go.mod
View File

@ -1,5 +1,5 @@
module go.etcd.io/bbolt module go.etcd.io/bbolt
go 1.12 go 1.17
require golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d require golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d

View File

@ -2,7 +2,6 @@ package bbolt
import ( import (
"fmt" "fmt"
"io/ioutil"
"math/rand" "math/rand"
"os" "os"
"path/filepath" "path/filepath"
@ -12,7 +11,7 @@ import (
func createDb(t *testing.T) (*DB, func()) { func createDb(t *testing.T) (*DB, func()) {
// First, create a temporary directory to be used for the duration of // First, create a temporary directory to be used for the duration of
// this test. // this test.
tempDirName, err := ioutil.TempDir("", "bboltmemtest") tempDirName, err := os.MkdirTemp("", "bboltmemtest")
if err != nil { if err != nil {
t.Fatalf("error creating temp dir: %v", err) t.Fatalf("error creating temp dir: %v", err)
} }

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows // +build !windows
package bbolt package bbolt

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows // +build !windows
package bbolt_test package bbolt_test