mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-19 00:14:18 +02:00
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:
+9
@@ -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
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
+36
-6
@@ -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
|
||||
}
|
||||
|
||||
+6
-1
@@ -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
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
# Hello
|
||||
+1
@@ -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")
|
||||
}
|
||||
|
||||
+1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user