Fix #647 Copy dir permissions

* update otiai10 to latest version which has correct permission logic
This commit is contained in:
Cole Wippern 2020-01-10 13:07:50 -08:00
parent 48f66e958c
commit e2d1cbfe71
7 changed files with 27 additions and 4 deletions

3
go.mod
View File

@ -71,8 +71,7 @@ require (
github.com/opencontainers/runtime-spec v1.0.1 // indirect
github.com/opencontainers/selinux v1.0.0-rc1 // indirect
github.com/opentracing/opentracing-go v1.0.2 // indirect
github.com/otiai10/copy v0.0.0-20180813032824-7e9a647135a1
github.com/otiai10/mint v1.3.0 // indirect
github.com/otiai10/copy v1.0.2
github.com/pborman/uuid v1.2.0 // indirect
github.com/pelletier/go-buffruneio v0.2.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect

2
go.sum
View File

@ -176,6 +176,8 @@ github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/otiai10/copy v0.0.0-20180813032824-7e9a647135a1 h1:A7kMXwDPBTfIVRv2l6XV3U6Su3SzLUzZjxnDDQVZDIY=
github.com/otiai10/copy v0.0.0-20180813032824-7e9a647135a1/go.mod h1:pXzZSDlN+HPzSdyIBnKNN9ptD9Hx7iZMWIJPTwo4FPE=
github.com/otiai10/copy v1.0.2 h1:DDNipYy6RkIkjMwy+AWzgKiNTyj2RUI9yEMeETEpVyc=
github.com/otiai10/copy v1.0.2/go.mod h1:c7RpqBkwMom4bYTSkLSym4VSJz/XtncWRAj/J4PEIMY=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95 h1:+OLn68pqasWca0z5ryit9KGfp3sUsW4Lqg32iRMJyzs=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
github.com/otiai10/mint v1.3.0 h1:Ady6MKVezQwHBkGzLFbrsywyp09Ah7rkmfjV3Bcr5uc=

View File

@ -1,2 +1,3 @@
testdata.copy
coverage.txt
vendor

View File

@ -7,6 +7,13 @@ import (
"path/filepath"
)
const (
// tmpPermissionForDirectory makes the destination directory writable,
// so that stuff can be copied recursively even if any original directory is NOT writable.
// See https://github.com/otiai10/copy/pull/9 for more information.
tmpPermissionForDirectory = os.FileMode(0755)
)
// Copy copies src to dest, doesn't matter if src is a directory or a file
func Copy(src, dest string) error {
info, err := os.Lstat(src)
@ -63,9 +70,14 @@ func fcopy(src, dest string, info os.FileInfo) error {
// and pass everything to "copy" recursively.
func dcopy(srcdir, destdir string, info os.FileInfo) error {
if err := os.MkdirAll(destdir, info.Mode()); err != nil {
originalMode := info.Mode()
// Make dest dir with 0755 so that everything writable.
if err := os.MkdirAll(destdir, tmpPermissionForDirectory); err != nil {
return err
}
// Recover dir mode with original one.
defer os.Chmod(destdir, originalMode)
contents, err := ioutil.ReadDir(srcdir)
if err != nil {
@ -79,6 +91,7 @@ func dcopy(srcdir, destdir string, info os.FileInfo) error {
return err
}
}
return nil
}

5
vendor/github.com/otiai10/copy/go.mod generated vendored Normal file
View File

@ -0,0 +1,5 @@
module github.com/otiai10/copy
go 1.12
require github.com/otiai10/mint v1.3.0

3
vendor/github.com/otiai10/copy/go.sum generated vendored Normal file
View File

@ -0,0 +1,3 @@
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
github.com/otiai10/mint v1.3.0 h1:Ady6MKVezQwHBkGzLFbrsywyp09Ah7rkmfjV3Bcr5uc=
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=

2
vendor/modules.txt vendored
View File

@ -331,7 +331,7 @@ github.com/opencontainers/selinux/go-selinux/label
github.com/opentracing/opentracing-go
github.com/opentracing/opentracing-go/ext
github.com/opentracing/opentracing-go/log
# github.com/otiai10/copy v0.0.0-20180813032824-7e9a647135a1
# github.com/otiai10/copy v1.0.2
github.com/otiai10/copy
# github.com/pelletier/go-buffruneio v0.2.0
github.com/pelletier/go-buffruneio