chore(deps): bump github.com/otiai10/copy from 1.11.0 to 1.12.0 (#2598)

Bumps [github.com/otiai10/copy](https://github.com/otiai10/copy) from 1.11.0 to 1.12.0.
- [Release notes](https://github.com/otiai10/copy/releases)
- [Commits](https://github.com/otiai10/copy/compare/v1.11.0...v1.12.0)

---
updated-dependencies:
- dependency-name: github.com/otiai10/copy
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
dependabot[bot] 2023-06-25 20:58:22 -07:00 committed by GitHub
parent 0d925dd651
commit 1e70e4ae01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 58 additions and 11 deletions

2
go.mod
View File

@ -28,7 +28,7 @@ require (
github.com/karrick/godirwalk v1.16.1
github.com/minio/highwayhash v1.0.2
github.com/moby/buildkit v0.11.6
github.com/otiai10/copy v1.11.0
github.com/otiai10/copy v1.12.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/afero v1.9.5

4
go.sum
View File

@ -545,8 +545,8 @@ github.com/opencontainers/runtime-spec v1.1.0-rc.1/go.mod h1:jwyrGlmzljRJv/Fgzds
github.com/opencontainers/selinux v1.10.0/go.mod h1:2i0OySw99QjzBBQByd1Gr9gSjvuho1lHsJxIJ3gGbJI=
github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaLpt7tQ7oU=
github.com/opencontainers/selinux v1.11.0/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec=
github.com/otiai10/copy v1.11.0 h1:OKBD80J/mLBrwnzXqGtFCzprFSGioo30JcmR4APsNwc=
github.com/otiai10/copy v1.11.0/go.mod h1:rSaLseMUsZFFbsFGc7wCJnnkTAvdc5L6VWxPE4308Ww=
github.com/otiai10/copy v1.12.0 h1:cLMgSQnXBs1eehF0Wy/FAGsgDTDmAqFR7rQylBb1nDY=
github.com/otiai10/copy v1.12.0/go.mod h1:rSaLseMUsZFFbsFGc7wCJnnkTAvdc5L6VWxPE4308Ww=
github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=

View File

@ -77,6 +77,15 @@ type Options struct {
// If zero, the internal default buffer of 32KB is used.
// See https://golang.org/pkg/io/#CopyBuffer for more information.
CopyBufferSize uint
// If you want to add some limitation on reading src file,
// you can wrap the src and provide new reader,
// such as `RateLimitReader` in the test case.
WrapReader func(src io.Reader) io.Reader
// If given, copy.Copy refers to this fs.FS instead of the OS filesystem.
// e.g., You can use embed.FS to copy files from embedded filesystem.
FS fs.FS
}
```

View File

@ -2,6 +2,7 @@ package copy
import (
"io"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
@ -17,6 +18,13 @@ type timespec struct {
// Copy copies src to dest, doesn't matter if src is a directory or a file.
func Copy(src, dest string, opts ...Options) error {
opt := assureOptions(src, dest, opts...)
if opt.FS != nil {
info, err := fs.Stat(opt.FS, src)
if err != nil {
return onError(src, dest, err, opt)
}
return switchboard(src, dest, info, opt)
}
info, err := os.Lstat(src)
if err != nil {
return onError(src, dest, err, opt)
@ -65,14 +73,20 @@ func copyNextOrSkip(src, dest string, info os.FileInfo, opt Options) error {
// with considering existence of parent directory
// and file permission.
func fcopy(src, dest string, info os.FileInfo, opt Options) (err error) {
s, err := os.Open(src)
var readcloser io.ReadCloser
if opt.FS != nil {
readcloser, err = opt.FS.Open(src)
} else {
readcloser, err = os.Open(src)
}
if err != nil {
if os.IsNotExist(err) {
return nil
}
return
}
defer fclose(s, &err)
defer fclose(readcloser, &err)
if err = os.MkdirAll(filepath.Dir(dest), os.ModePerm); err != nil {
return
@ -92,10 +106,10 @@ func fcopy(src, dest string, info os.FileInfo, opt Options) (err error) {
var buf []byte = nil
var w io.Writer = f
var r io.Reader = s
var r io.Reader = readcloser
if opt.WrapReader != nil {
r = opt.WrapReader(s)
r = opt.WrapReader(r)
}
if opt.CopyBufferSize != 0 {
@ -145,7 +159,23 @@ func dcopy(srcdir, destdir string, info os.FileInfo, opt Options) (err error) {
}
defer chmodfunc(&err)
contents, err := ioutil.ReadDir(srcdir)
var contents []os.FileInfo
if opt.FS != nil {
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
}
contents = append(contents, info)
}
} else {
contents, err = ioutil.ReadDir(srcdir)
}
if err != nil {
if os.IsNotExist(err) {
return nil
@ -237,7 +267,7 @@ func lcopy(src, dest string) error {
// fclose ANYHOW closes file,
// with asiging error raised during Close,
// BUT respecting the error already reported.
func fclose(f *os.File, reported *error) {
func fclose(f io.Closer, reported *error) {
if err := f.Close(); *reported == nil {
*reported = err
}

View File

@ -2,6 +2,7 @@ package copy
import (
"io"
"io/fs"
"os"
)
@ -58,7 +59,11 @@ type Options struct {
// If you want to add some limitation on reading src file,
// you can wrap the src and provide new reader,
// such as `RateLimitReader` in the test case.
WrapReader func(src *os.File) io.Reader
WrapReader func(src io.Reader) io.Reader
// If given, copy.Copy refers to this fs.FS instead of the OS filesystem.
// e.g., You can use embed.FS to copy files from embedded filesystem.
FS fs.FS
intent struct {
src string

View File

@ -0,0 +1 @@
# Hello

View File

@ -16,4 +16,5 @@ func setup(m *testing.M) {
os.Chmod("test/data/case07/dir_0555", 0o555)
os.Chmod("test/data/case07/file_0444", 0o444)
syscall.Mkfifo("test/data/case11/foo/bar", 0o555)
Copy("test/data/case18/assets", "test/data/case18/assets.backup")
}

View File

@ -9,6 +9,7 @@ import (
)
func setup(m *testing.M) {
os.RemoveAll("test/data.copy")
os.MkdirAll("test/data.copy", os.ModePerm)
os.Symlink("test/data/case01", "test/data/case03/case01")
os.Chmod("test/data/case07/dir_0555", 0555)

2
vendor/modules.txt vendored
View File

@ -739,7 +739,7 @@ github.com/opencontainers/runtime-spec/specs-go
github.com/opencontainers/selinux/go-selinux
github.com/opencontainers/selinux/go-selinux/label
github.com/opencontainers/selinux/pkg/pwalkdir
# github.com/otiai10/copy v1.11.0
# github.com/otiai10/copy v1.12.0
## explicit; go 1.18
github.com/otiai10/copy
# github.com/pelletier/go-toml v1.9.5