Remove umask, replace with explicit chmod after create

Call chmod on all open files and created directories to
ensure permission is set as expected without changing umask.

Fixes #1608

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2017-10-11 14:38:05 -07:00
parent 3cc75915db
commit e20b371807
5 changed files with 49 additions and 17 deletions

View File

@@ -43,20 +43,28 @@ func open(p string) (*os.File, error) {
}
func openFile(name string, flag int, perm os.FileMode) (*os.File, error) {
return os.OpenFile(name, flag, perm)
f, err := os.OpenFile(name, flag, perm)
if err != nil {
return nil, err
}
// Call chmod to avoid permission mask
if err := os.Chmod(name, perm); err != nil {
return nil, err
}
return f, err
}
func mkdirAll(path string, perm os.FileMode) error {
return os.MkdirAll(path, perm)
}
func prepareApply() func() {
// Unset unmask before doing an apply operation,
// restore unmask when complete
oldmask := unix.Umask(0)
return func() {
unix.Umask(oldmask)
func mkdir(path string, perm os.FileMode) error {
if err := os.Mkdir(path, perm); err != nil {
return err
}
// Only final created directory gets explicit permission
// call to avoid permission mask
return os.Chmod(path, perm)
}
func skipFile(*tar.Header) bool {