aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Burwell <ben@benburwell.com>2019-08-13 14:38:31 -0400
committerBen Burwell <ben@benburwell.com>2019-08-13 14:38:31 -0400
commit3fa3887c342393b25e2df48f4c096cbf31ce2d5f (patch)
tree5694d77f58c1e05fd369c9fd1b949fb2f204653c
parente083b1b1558dc1e97da361c505653a38bd339cef (diff)
Preserve file mode on adopt/apply
-rw-r--r--adopt.go6
-rw-r--r--apply.go6
2 files changed, 10 insertions, 2 deletions
diff --git a/adopt.go b/adopt.go
index 0f900eb..0393d08 100644
--- a/adopt.go
+++ b/adopt.go
@@ -30,7 +30,11 @@ func adoptFile(name string) error {
return err
}
defer from.Close()
- to, err := os.OpenFile(toPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600)
+ fromInfo, err := os.Stat(fromPath)
+ if err != nil {
+ return err
+ }
+ to, err := os.OpenFile(toPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, fromInfo.Mode())
if err != nil {
return err
}
diff --git a/apply.go b/apply.go
index eaa528a..89abf8d 100644
--- a/apply.go
+++ b/apply.go
@@ -42,7 +42,11 @@ func applyFile(name string) error {
if err = os.MkdirAll(filepath.Dir(d), 0700); err != nil {
return err
}
- out, err := os.OpenFile(d, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600)
+ srcInfo, err := os.Stat(src)
+ if err != nil {
+ return err
+ }
+ out, err := os.OpenFile(d, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, srcInfo.Mode())
if err != nil {
return err
}