MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / WriteFileWithOptionalSudo

Function WriteFileWithOptionalSudo

agent/utils/cmd/cmd.go:54–64  ·  view source on GitHub ↗
(name string, data []byte, perm os.FileMode)

Source from the content-addressed store, hash-verified

52}
53
54func WriteFileWithOptionalSudo(name string, data []byte, perm os.FileMode) error {
55 if err := os.WriteFile(name, data, perm); err == nil {
56 return nil
57 } else if SudoHandleCmd() == "" {
58 return err
59 }
60 command := exec.Command("sudo", "-n", "tee", name)
61 command.Stdin = bytes.NewReader(data)
62 command.Stdout = io.Discard
63 return command.Run()
64}
65
66func Which(name string) bool {
67 _, err := exec.LookPath(name)

Callers

nothing calls this directly

Calls 3

WriteFileMethod · 0.80
SudoHandleCmdFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected