Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve destination file ownership on unix OSes #1185

Merged
merged 1 commit into from
Feb 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions manager/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
"syscall"

"github.com/pkg/errors"
)
Expand Down Expand Up @@ -148,6 +150,18 @@ func AtomicWrite(path string, createDestDirs bool, contents []byte, perms os.Fil
}
} else {
perms = currentInfo.Mode()

// The file exists, so try to preserve the ownership as well.
sysInfo := currentInfo.Sys()
if sysInfo != nil {
stat, ok := sysInfo.(*syscall.Stat_t)
if ok {
if err := os.Chown(f.Name(), int(stat.Uid), int(stat.Gid)); err != nil {
log.Printf("[WARN] (runner) could not preserve file permissions for %q: %v",
f.Name(), err)
}
}
}
}
}

Expand Down