Skip to content

Commit 885b59f

Browse files
JustAdamjwilder
authored andcommitted
Update permissions of temp file to match that of original file.
1 parent 0cf31ba commit 885b59f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

template.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"path/filepath"
1010
"strings"
11+
"syscall"
1112
"text/template"
1213
)
1314

@@ -108,7 +109,13 @@ func generateFile(config Config, containers Context) bool {
108109
if config.Dest != "" {
109110

110111
contents := []byte{}
111-
if _, err := os.Stat(config.Dest); err == nil {
112+
if fi, err := os.Stat(config.Dest); err == nil {
113+
if err := dest.Chmod(fi.Mode()); err != nil {
114+
log.Fatalf("unable to chmod temp file: %s\n", err)
115+
}
116+
if err := dest.Chown(int(fi.Sys().(*syscall.Stat_t).Uid), int(fi.Sys().(*syscall.Stat_t).Gid)); err != nil {
117+
log.Fatalf("unable to chown temp file: %s\n", err)
118+
}
112119
contents, err = ioutil.ReadFile(config.Dest)
113120
if err != nil {
114121
log.Fatalf("unable to compare current file contents: %s: %s\n", config.Dest, err)

0 commit comments

Comments
 (0)