Skip to content

Commit

Permalink
Replace deprecated 'io/ioutil' package with 'os'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Jan 6, 2024
1 parent fba066a commit 620e9fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestCopy(t *testing.T) {
When(t, "specified src is just a file", func(t *testing.T) {
err := Copy("test/data/case01/README.md", "test/data.copy/case01/README.md")
Expect(t, err).ToBe(nil)
content, err := ioutil.ReadFile("test/data.copy/case01/README.md")
content, err := os.ReadFile("test/data.copy/case01/README.md")
Expect(t, err).ToBe(nil)
Expect(t, string(content)).ToBe("case01 - README.md")
})
Expand Down
28 changes: 14 additions & 14 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"io"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -167,28 +166,29 @@ func dcopy(srcdir, destdir string, info os.FileInfo, opt Options) (err error) {
}
defer chmodfunc(&err)

var contents []os.FileInfo
var entries []fs.DirEntry
if opt.FS != nil {
entries, err := fs.ReadDir(opt.FS, srcdir)
entries, err = fs.ReadDir(opt.FS, srcdir)
if err != nil {
return err
}
for _, e := range entries {
info, err := e.Info()
if err != nil {
return err
} else {
entries, err = os.ReadDir(srcdir)
if err != nil {
if os.IsNotExist(err) {
return nil
}
contents = append(contents, info)
return err
}
} else {
contents, err = ioutil.ReadDir(srcdir)
}

if err != nil {
if os.IsNotExist(err) {
return nil
contents := make([]fs.FileInfo, 0, len(entries))
for _, e := range entries {
info, err := e.Info()
if err != nil {
return err
}
return
contents = append(contents, info)
}

if yes, err := shouldCopyDirectoryConcurrent(opt, srcdir, destdir); err != nil {
Expand Down

0 comments on commit 620e9fe

Please sign in to comment.