Skip to content

Commit 0c09a25

Browse files
committed
Replace usage of deprecated ioutil
1 parent d0f90ae commit 0c09a25

File tree

13 files changed

+62
-54
lines changed

13 files changed

+62
-54
lines changed

db.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,11 @@ func (db *DB) FileSize() (int64, error) {
419419
return 0, err
420420
}
421421
for _, file := range files {
422-
size += file.Size()
422+
info, err := file.Info()
423+
if err != nil {
424+
return 0, err
425+
}
426+
size += info.Size()
423427
}
424428
return size, nil
425429
}

db_test.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"flag"
77
"fmt"
88
"io"
9-
"io/ioutil"
109
"log"
1110
"os"
1211
"path/filepath"
@@ -30,7 +29,7 @@ var (
3029
func TestMain(m *testing.M) {
3130
flag.Parse()
3231
if !testing.Verbose() {
33-
SetLogger(log.New(ioutil.Discard, "", 0))
32+
SetLogger(log.New(io.Discard, "", 0))
3433
}
3534
// Run tests against all file systems.
3635
for _, fsys := range []fs.FileSystem{fs.Mem, fs.OSMMap, fs.OS} {
@@ -43,6 +42,7 @@ func TestMain(m *testing.M) {
4342
os.Exit(exitCode)
4443
}
4544
}
45+
_ = cleanDir(testDBName)
4646
os.Exit(0)
4747
}
4848

@@ -87,6 +87,17 @@ func TestHeaderSize(t *testing.T) {
8787
}
8888
}
8989

90+
func cleanDir(path string) error {
91+
files, err := testFS.ReadDir(path)
92+
if err != nil {
93+
return err
94+
}
95+
for _, file := range files {
96+
_ = testFS.Remove(filepath.Join(testDBName, file.Name()))
97+
}
98+
return nil
99+
}
100+
90101
func createTestDB(opts *Options) (*DB, error) {
91102
if opts == nil {
92103
opts = &Options{FileSystem: testFS}
@@ -95,15 +106,10 @@ func createTestDB(opts *Options) (*DB, error) {
95106
opts.FileSystem = testFS
96107
}
97108
}
98-
path := testDBName
99-
files, err := testFS.ReadDir(path)
100-
if err != nil && !os.IsNotExist(err) {
109+
if err := cleanDir(testDBName); err != nil {
101110
return nil, err
102111
}
103-
for _, file := range files {
104-
_ = testFS.Remove(filepath.Join(path, file.Name()))
105-
}
106-
return Open(path, opts)
112+
return Open(testDBName, opts)
107113
}
108114

109115
func TestEmpty(t *testing.T) {

file_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (fs *errfs) Rename(oldpath, newpath string) error {
3030
return errfileError
3131
}
3232

33-
func (fs *errfs) ReadDir(name string) ([]os.FileInfo, error) {
33+
func (fs *errfs) ReadDir(name string) ([]os.DirEntry, error) {
3434
return nil, errfileError
3535
}
3636

fs/fs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type FileSystem interface {
5656
Rename(oldpath, newpath string) error
5757

5858
// ReadDir reads the directory and returns a list of directory entries.
59-
ReadDir(name string) ([]os.FileInfo, error)
59+
ReadDir(name string) ([]os.DirEntry, error)
6060

6161
// CreateLockFile creates a lock file.
6262
CreateLockFile(name string, perm os.FileMode) (LockFile, bool, error)

fs/mem.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ func (fs *memFS) Rename(oldpath, newpath string) error {
7070
return os.ErrNotExist
7171
}
7272

73-
func (fs *memFS) ReadDir(dir string) ([]os.FileInfo, error) {
73+
func (fs *memFS) ReadDir(dir string) ([]os.DirEntry, error) {
7474
dir = filepath.Clean(dir)
75-
var fis []os.FileInfo
75+
var entries []os.DirEntry
7676
for name, f := range fs.files {
7777
if filepath.Dir(name) == dir {
78-
fis = append(fis, f)
78+
entries = append(entries, f)
7979
}
8080
}
81-
return fis, nil
81+
return entries, nil
8282
}
8383

8484
type memFile struct {
@@ -223,6 +223,14 @@ func (f *memFile) Sys() interface{} {
223223
return nil
224224
}
225225

226+
func (f *memFile) Type() os.FileMode {
227+
return f.perm
228+
}
229+
230+
func (f *memFile) Info() (os.FileInfo, error) {
231+
return f.Stat()
232+
}
233+
226234
func (f *memFile) Slice(start int64, end int64) ([]byte, error) {
227235
if f.closed {
228236
return nil, os.ErrClosed

fs/os.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package fs
22

33
import (
4-
"io/ioutil"
54
"os"
65
)
76

@@ -34,8 +33,8 @@ func (fs *osFS) Rename(oldpath, newpath string) error {
3433
return os.Rename(oldpath, newpath)
3534
}
3635

37-
func (fs *osFS) ReadDir(name string) ([]os.FileInfo, error) {
38-
return ioutil.ReadDir(name)
36+
func (fs *osFS) ReadDir(name string) ([]os.DirEntry, error) {
37+
return os.ReadDir(name)
3938
}
4039

4140
type osFile struct {

fs/os_mmap_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build !windows
1+
//go:build !windows
22

33
package fs
44

fs/os_mmap_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build windows
1+
//go:build windows
22

33
package fs
44

fs/os_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build !windows
1+
//go:build !windows
22

33
package fs
44

fs/os_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build windows
1+
//go:build windows
22

33
package fs
44

0 commit comments

Comments
 (0)