Repository: incubator-mynewt-newt Updated Branches: refs/heads/develop 18cde7cf1 -> 21deb707e
newt - Preserve permissions on copy dir / file. Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/01931a20 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/01931a20 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/01931a20 Branch: refs/heads/develop Commit: 01931a20b523081397035c88045374015ea1ffd7 Parents: 18cde7c Author: Christopher Collins <ccoll...@apache.org> Authored: Mon Oct 10 23:32:37 2016 -0700 Committer: Christopher Collins <ccoll...@apache.org> Committed: Mon Oct 10 23:36:10 2016 -0700 ---------------------------------------------------------------------- util/util.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/01931a20/util/util.go ---------------------------------------------------------------------- diff --git a/util/util.go b/util/util.go index 2cda3e8..3ecf400 100644 --- a/util/util.go +++ b/util/util.go @@ -363,12 +363,17 @@ func CopyFile(srcFile string, dstFile string) error { } defer in.Close() + info, err := in.Stat() + if err != nil { + return ChildNewtError(err) + } + dstDir := filepath.Dir(dstFile) if err := os.MkdirAll(dstDir, os.ModePerm); err != nil { return ChildNewtError(err) } - out, err := os.Create(dstFile) + out, err := os.OpenFile(dstFile, os.O_CREATE|os.O_WRONLY, info.Mode()) if err != nil { return ChildNewtError(err) } @@ -394,7 +399,12 @@ func CopyDir(srcDirStr, dstDirStr string) error { return ChildNewtError(err) } - if err := os.MkdirAll(filepath.Dir(dstDirStr), os.ModePerm); err != nil { + info, err := srcDir.Stat() + if err != nil { + return ChildNewtError(err) + } + + if err := os.MkdirAll(filepath.Dir(dstDirStr), info.Mode()); err != nil { return ChildNewtError(err) }