diff options
author | Ben Burwell <ben@benburwell.com> | 2019-08-13 14:38:31 -0400 |
---|---|---|
committer | Ben Burwell <ben@benburwell.com> | 2019-08-13 14:38:31 -0400 |
commit | 3fa3887c342393b25e2df48f4c096cbf31ce2d5f (patch) | |
tree | 5694d77f58c1e05fd369c9fd1b949fb2f204653c | |
parent | e083b1b1558dc1e97da361c505653a38bd339cef (diff) |
Preserve file mode on adopt/apply
-rw-r--r-- | adopt.go | 6 | ||||
-rw-r--r-- | apply.go | 6 |
2 files changed, 10 insertions, 2 deletions
@@ -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 } @@ -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 } |