(name string, data []byte, perm os.FileMode)
| 52 | } |
| 53 | |
| 54 | func 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 | |
| 66 | func Which(name string) bool { |
| 67 | _, err := exec.LookPath(name) |
nothing calls this directly
no test coverage detected