diff --git a/internal/exec/stages/files/filesystemEntries.go b/internal/exec/stages/files/filesystemEntries.go index 56083bcaac..7b3660d5a5 100644 --- a/internal/exec/stages/files/filesystemEntries.go +++ b/internal/exec/stages/files/filesystemEntries.go @@ -393,6 +393,7 @@ func (s stage) getOrderedCreationList(config types.Config) ([]filesystemEntry, e // Map from paths in the config to where they resolve for duplicate checking paths := map[string]string{} for _, d := range config.Storage.Directories { + d.Mode = cutil.IntToPtr(int(util.ToFileMode(uint32(int(*d.Mode))))) path, err := s.JoinPath(d.Path) if err != nil { return nil, err @@ -407,6 +408,7 @@ func (s stage) getOrderedCreationList(config types.Config) ([]filesystemEntry, e } for _, f := range config.Storage.Files { + f.Mode = cutil.IntToPtr(int(util.ToFileMode(uint32(int(*f.Mode))))) path, err := s.JoinPath(f.Path) if err != nil { return nil, err diff --git a/internal/exec/util/file.go b/internal/exec/util/file.go index fe56087a65..f1942d57a8 100644 --- a/internal/exec/util/file.go +++ b/internal/exec/util/file.go @@ -169,6 +169,24 @@ func (u Util) SetPermissions(mode *int, node types.Node) error { return nil } +// ToFileMode converts Go permission bits to POSIX permission bits. +func ToFileMode(m uint32) os.FileMode { + mode := os.FileMode(m & 0000777) + + if m&unix.S_ISGID != 0 { + mode |= os.ModeSetgid + + } + if m&unix.S_ISUID != 0 { + mode |= os.ModeSetuid + } + if m&unix.S_ISVTX != 0 { + mode |= os.ModeSticky + } + + return mode +} + // PerformFetch performs a fetch operation generated by PrepareFetch, retrieving // the file and writing it to disk. Any encountered errors are returned. func (u Util) PerformFetch(f FetchOp) error {