Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated 'io/ioutil' package with 'os' #133

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading