Skip to content

Commit

Permalink
Merge pull request wal-g#1515 from testwill/ioutil
Browse files Browse the repository at this point in the history
chore: remove refs to deprecated io/ioutil
  • Loading branch information
serprex authored Jul 15, 2023
2 parents 3f9d9c3 + 41888ee commit e0d0d90
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
3 changes: 1 addition & 2 deletions internal/databases/postgres/wal_restore_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -195,7 +194,7 @@ func timelineWithSegmentNoSliceToMap(slice []*TimelineWithSegmentNo) map[uint32]
// getDirectoryFilenames returns slice of filenames in directory by path
func getDirectoryFilenames(path string) ([]string, error) {
result := make([]string, 0)
files, err := ioutil.ReadDir(path)
files, err := os.ReadDir(path)
if err != nil {
return nil, err
}
Expand Down
15 changes: 8 additions & 7 deletions internal/databases/postgres/walk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/sha256"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -197,12 +196,12 @@ func extract(t *testing.T, dir string) string {
// initial bytes are the same.
func compare(t *testing.T, dir1, dir2 string) bool {
// ReadDir returns directory by filename.
files1, err := ioutil.ReadDir(dir1)
files1, err := os.ReadDir(dir1)
if err != nil {
t.Log(err)
}

files2, err := ioutil.ReadDir(dir2)
files2, err := os.ReadDir(dir2)
if err != nil {
t.Log(err)
}
Expand All @@ -212,9 +211,11 @@ func compare(t *testing.T, dir1, dir2 string) bool {
var deepEqual bool
for i, f2 := range files2 {
f1 := files1[i]
info1, _ := f1.Info()
info2, _ := f2.Info()
name := f1.Name() == f2.Name()
size := f1.Size() == f2.Size()
mode := f1.Mode() == f2.Mode()
size := info1.Size() == info2.Size()
mode := info1.Mode() == info2.Mode()
isDir := f1.IsDir() == f2.IsDir()

// If directory is in ExcludedFilenames list, make sure it exists but is empty.
Expand Down Expand Up @@ -243,8 +244,8 @@ func compare(t *testing.T, dir1, dir2 string) bool {

}
} else {
t.Logf("walk: Original: \t%s\t %d\t %d\t %v", f1.Name(), f1.Size(), f1.Mode(), f1.IsDir())
t.Logf("walk: Extracted: \t%s\t %d\t %d\t %v", f2.Name(), f2.Size(), f2.Mode(), f2.IsDir())
t.Logf("walk: Original: \t%s\t %d\t %d\t %v", f1.Name(), info1.Size(), info1.Mode(), f1.IsDir())
t.Logf("walk: Extracted: \t%s\t %d\t %d\t %v", f2.Name(), info2.Size(), info2.Mode(), f2.IsDir())
}

}
Expand Down
6 changes: 3 additions & 3 deletions pkg/storages/fs/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package fs
import (
"fmt"
"io"
"io/ioutil"
"os"
"path"

Expand Down Expand Up @@ -43,7 +42,7 @@ func (folder *Folder) GetPath() string {
}

func (folder *Folder) ListFolder() (objects []storage.Object, subFolders []storage.Folder, err error) {
files, err := ioutil.ReadDir(path.Join(folder.rootPath, folder.subpath))
files, err := os.ReadDir(path.Join(folder.rootPath, folder.subpath))
if err != nil {
return nil, nil, NewError(err, "Unable to read folder")
}
Expand All @@ -53,7 +52,8 @@ func (folder *Folder) ListFolder() (objects []storage.Object, subFolders []stora
subPath := path.Join(folder.subpath, fileInfo.Name()) + "/"
subFolders = append(subFolders, NewFolder(folder.rootPath, subPath))
} else {
objects = append(objects, storage.NewLocalObject(fileInfo.Name(), fileInfo.ModTime(), fileInfo.Size()))
info, _ := fileInfo.Info()
objects = append(objects, storage.NewLocalObject(fileInfo.Name(), info.ModTime(), info.Size()))
}
}
return
Expand Down
8 changes: 4 additions & 4 deletions tests_func/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -73,7 +72,7 @@ func SplitEnvLine(line string) (string, string) {
}

func CopyDirectory(src, dest string, filter string) error {
entries, err := ioutil.ReadDir(src)
entries, err := os.ReadDir(src)
if err != nil {
return err
}
Expand Down Expand Up @@ -117,9 +116,10 @@ func CopyDirectory(src, dest string, filter string) error {
return err
}

isSymlink := entry.Mode()&os.ModeSymlink != 0
info, _ := entry.Info()
isSymlink := info.Mode()&os.ModeSymlink != 0
if !isSymlink {
if err := os.Chmod(destPath, entry.Mode()); err != nil {
if err := os.Chmod(destPath, info.Mode()); err != nil {
return err
}
}
Expand Down

0 comments on commit e0d0d90

Please sign in to comment.