Skip to content

Commit

Permalink
fix: set permissions for new files
Browse files Browse the repository at this point in the history
  • Loading branch information
femnad committed Feb 4, 2024
1 parent f8fd934 commit 37b5c62
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
10 changes: 7 additions & 3 deletions internal/filecontent.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ func chown(file, user, group string) error {
return MaybeRunWithSudo(chownCmd)
}

func chmod(target string, mode int) error {
octal := strconv.FormatInt(int64(mode), 8)
chmodCmd := fmt.Sprintf("chmod %s %s", octal, target)
return MaybeRunWithSudoForPath(chmodCmd, target)
}

func ensureDir(dir string) error {
hasDirPerms, err := hasPerms(dir)
if err != nil {
Expand Down Expand Up @@ -303,9 +309,7 @@ func WriteContent(file ManagedFile) (bool, error) {
}

if currentMode != mode || !dstExists {
octal := strconv.FormatInt(int64(mode), 8)
chmod := fmt.Sprintf("chmod %s %s", octal, target)
err = MaybeRunWithSudoForPath(chmod, target)
err = chmod(target, mode)
if err != nil {
return changed, err
}
Expand Down
11 changes: 8 additions & 3 deletions internal/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ func Move(src, dst string, setOwner bool) error {
return err
}

if setOwner {
return chown(dst, rootUser, rootUser)
if !setOwner {
return nil
}

return nil
err = chown(dst, rootUser, rootUser)
if err != nil {
return err
}

return chmod(dst, defaultFileMode)
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

const (
version = "0.31.8"
version = "0.31.9"
)

type args struct {
Expand Down

0 comments on commit 37b5c62

Please sign in to comment.