Skip to content

Commit

Permalink
Merge pull request #133 from alexandear/replace-deprecated-ioutil-wit…
Browse files Browse the repository at this point in the history
…h-os

Replace deprecated 'io/ioutil' package with 'os'
  • Loading branch information
otiai10 committed Jan 8, 2024
2 parents c1ce9c6 + 620e9fe commit 9e8f096
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 9e8f096

Please sign in to comment.