Skip to content

Commit

Permalink
Do not unnecessarily fork to chmod mountpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jp39 committed Sep 11, 2024
1 parent 313eef9 commit f5f9732
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pkg/zfs/zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,25 @@ func (z *zfsImpl) SetPermissions(dataset *Dataset) error {
return err
}
cmd := exec.Command("update-permissions", dataset.Mountpoint)
if !filepath.IsAbs(cmd.Path) {
// update-permissions not found in PATH
cmd = exec.Command("chmod", "g+w", dataset.Mountpoint)
if filepath.IsAbs(cmd.Path) {
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("could not update permissions on '%s': %w: %s", dataset.Hostname, err, out)
}
return nil
}

out, err := cmd.CombinedOutput()
// update-permissions executable not found in PATH
st, err := os.Lstat(dataset.Mountpoint)
if err != nil {
return fmt.Errorf("could not update permissions on '%s': %w: %s", dataset.Hostname, err, out)
return err
}

// Add group write bit
if err := os.Chmod(dataset.Mountpoint, st.Mode()|0o020); err != nil {
return err
}

return nil
}

Expand Down

0 comments on commit f5f9732

Please sign in to comment.