Skip to content

Commit

Permalink
Remove references to io/ioutil package
Browse files Browse the repository at this point in the history
io/ioutil has been deprecated in Go 1.16.

Signed-off-by: Austin Vazquez <[email protected]>
  • Loading branch information
austinvazquez committed Oct 25, 2022
1 parent 325f9b6 commit 3505a2a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion driver/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func WriteFile(r Driver, filename string, data []byte, perm os.FileMode) error {
return nil
}

// ReadDir works the same as ioutil.ReadDir with the Driver abstraction
// ReadDir works the same as os.ReadDir with the Driver abstraction
func ReadDir(r Driver, dirname string) ([]os.FileInfo, error) {
f, err := r.Open(dirname)
if err != nil {
Expand Down
34 changes: 19 additions & 15 deletions fs/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package fs

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sync"
Expand Down Expand Up @@ -111,7 +110,7 @@ func copyDirectory(dst, src string, inodes map[uint64]string, o *copyDirOpts) er
}
}

fis, err := ioutil.ReadDir(src)
entries, err := os.ReadDir(src)
if err != nil {
return fmt.Errorf("failed to read %s: %w", src, err)
}
Expand All @@ -124,18 +123,23 @@ func copyDirectory(dst, src string, inodes map[uint64]string, o *copyDirOpts) er
return fmt.Errorf("failed to copy xattrs: %w", err)
}

for _, fi := range fis {
source := filepath.Join(src, fi.Name())
target := filepath.Join(dst, fi.Name())
for _, entry := range entries {
source := filepath.Join(src, entry.Name())
target := filepath.Join(dst, entry.Name())

fileInfo, err := entry.Info()
if err != nil {
return fmt.Errorf("failed to get file info for %s: %w", entry.Name(), err)
}

switch {
case fi.IsDir():
case entry.IsDir():
if err := copyDirectory(target, source, inodes, o); err != nil {
return err
}
continue
case (fi.Mode() & os.ModeType) == 0:
link, err := getLinkSource(target, fi, inodes)
case (entry.Type() & os.ModeType) == 0:
link, err := getLinkSource(target, fileInfo, inodes)
if err != nil {
return fmt.Errorf("failed to get hardlink: %w", err)
}
Expand All @@ -146,26 +150,26 @@ func copyDirectory(dst, src string, inodes map[uint64]string, o *copyDirOpts) er
} else if err := CopyFile(target, source); err != nil {
return fmt.Errorf("failed to copy files: %w", err)
}
case (fi.Mode() & os.ModeSymlink) == os.ModeSymlink:
case (entry.Type() & os.ModeSymlink) == os.ModeSymlink:
link, err := os.Readlink(source)
if err != nil {
return fmt.Errorf("failed to read link: %s: %w", source, err)
}
if err := os.Symlink(link, target); err != nil {
return fmt.Errorf("failed to create symlink: %s: %w", target, err)
}
case (fi.Mode() & os.ModeDevice) == os.ModeDevice,
(fi.Mode() & os.ModeNamedPipe) == os.ModeNamedPipe,
(fi.Mode() & os.ModeSocket) == os.ModeSocket:
if err := copyIrregular(target, fi); err != nil {
case (entry.Type() & os.ModeDevice) == os.ModeDevice,
(entry.Type() & os.ModeNamedPipe) == os.ModeNamedPipe,
(entry.Type() & os.ModeSocket) == os.ModeSocket:
if err := copyIrregular(target, fileInfo); err != nil {
return fmt.Errorf("failed to create irregular file: %w", err)
}
default:
logrus.Warnf("unsupported mode: %s: %s", source, fi.Mode())
logrus.Warnf("unsupported mode: %s: %s", source, entry.Type())
continue
}

if err := copyFileInfo(fi, source, target); err != nil {
if err := copyFileInfo(fileInfo, source, target); err != nil {
return fmt.Errorf("failed to copy file info: %w", err)
}

Expand Down
3 changes: 1 addition & 2 deletions fs/dtype_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ package fs

import (
"fmt"
"io/ioutil"
"os"
"syscall"
"unsafe"
)

func locateDummyIfEmpty(path string) (string, error) {
children, err := ioutil.ReadDir(path)
children, err := os.ReadDir(path)
if err != nil {
return "", err
}
Expand Down
5 changes: 2 additions & 3 deletions testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package continuity
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
)
Expand All @@ -31,7 +30,7 @@ func tree(w io.Writer, dir string) error {
}

func _tree(w io.Writer, dir string, indent string) error {
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
return err
}
Expand All @@ -44,7 +43,7 @@ func _tree(w io.Writer, dir string, indent string) error {
fIndent += "`-- "
}
target := ""
if f.Mode()&os.ModeSymlink == os.ModeSymlink {
if (f.Type() & os.ModeSymlink) == os.ModeSymlink {
realPath, err := os.Readlink(fPath)
if err != nil {
target += fmt.Sprintf(" -> unknown (error: %v)", err)
Expand Down

0 comments on commit 3505a2a

Please sign in to comment.