fix user permission issue
Some checks failed
CI / test-build (push) Failing after 2m13s

This commit is contained in:
2025-12-15 02:01:09 +07:00
parent f45c878051
commit 732e5aca11
2 changed files with 40 additions and 2 deletions

View File

@@ -27,8 +27,28 @@ func New() *Service {
}
// execCommand executes a shell command and returns output
// For ZFS operations that require elevated privileges, it uses sudo
func (s *Service) execCommand(name string, args ...string) (string, error) {
cmd := exec.Command(name, args...)
// Commands that require root privileges
privilegedCommands := []string{"zpool", "zfs"}
useSudo := false
for _, cmd := range privilegedCommands {
if strings.Contains(name, cmd) {
useSudo = true
break
}
}
var cmd *exec.Cmd
if useSudo {
// Use sudo for privileged commands
sudoArgs := append([]string{name}, args...)
cmd = exec.Command("sudo", sudoArgs...)
} else {
cmd = exec.Command(name, args...)
}
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr