diff --git a/go.mod b/go.mod index 8e05e7783b..4c05edb866 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index fd65dd381d..677793fd10 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/vendor/github.com/otiai10/copy/README.md b/vendor/github.com/otiai10/copy/README.md index dc66c4e95a..1cc8fc8c82 100644 --- a/vendor/github.com/otiai10/copy/README.md +++ b/vendor/github.com/otiai10/copy/README.md @@ -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 } ``` diff --git a/vendor/github.com/otiai10/copy/copy.go b/vendor/github.com/otiai10/copy/copy.go index a84ff7bae1..085db78249 100644 --- a/vendor/github.com/otiai10/copy/copy.go +++ b/vendor/github.com/otiai10/copy/copy.go @@ -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 } diff --git a/vendor/github.com/otiai10/copy/options.go b/vendor/github.com/otiai10/copy/options.go index 52d636c95d..1b4e508332 100644 --- a/vendor/github.com/otiai10/copy/options.go +++ b/vendor/github.com/otiai10/copy/options.go @@ -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 diff --git a/vendor/github.com/otiai10/copy/test/data/case18/assets/README.md b/vendor/github.com/otiai10/copy/test/data/case18/assets/README.md new file mode 100644 index 0000000000..5570c7ff58 --- /dev/null +++ b/vendor/github.com/otiai10/copy/test/data/case18/assets/README.md @@ -0,0 +1 @@ +# Hello \ No newline at end of file diff --git a/vendor/github.com/otiai10/copy/test_setup.go b/vendor/github.com/otiai10/copy/test_setup.go index f3c2d83cd2..64a5292788 100644 --- a/vendor/github.com/otiai10/copy/test_setup.go +++ b/vendor/github.com/otiai10/copy/test_setup.go @@ -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") } diff --git a/vendor/github.com/otiai10/copy/test_setup_x.go b/vendor/github.com/otiai10/copy/test_setup_x.go index fc56b7329e..4c35b144b1 100644 --- a/vendor/github.com/otiai10/copy/test_setup_x.go +++ b/vendor/github.com/otiai10/copy/test_setup_x.go @@ -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) diff --git a/vendor/modules.txt b/vendor/modules.txt index 00df1de8d2..5a7b8ec374 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -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