Skip to content

Commit

Permalink
Update permissions of temp file to match that of original file.
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAdam authored and jwilder committed Oct 1, 2014
1 parent 0cf31ba commit 885b59f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion template.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"strings"
"syscall"
"text/template"
)

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

contents := []byte{}
if _, err := os.Stat(config.Dest); err == nil {
if fi, err := os.Stat(config.Dest); err == nil {
if err := dest.Chmod(fi.Mode()); err != nil {
log.Fatalf("unable to chmod temp file: %s\n", err)
}
if err := dest.Chown(int(fi.Sys().(*syscall.Stat_t).Uid), int(fi.Sys().(*syscall.Stat_t).Gid)); err != nil {
log.Fatalf("unable to chown temp file: %s\n", err)
}
contents, err = ioutil.ReadFile(config.Dest)
if err != nil {
log.Fatalf("unable to compare current file contents: %s: %s\n", config.Dest, err)
Expand Down

0 comments on commit 885b59f

Please sign in to comment.