runSudoChownNonInteractive runs sudo chown using cached credentials (non-interactive).
(ctx context.Context, username string, recursive bool, path string)
| 256 | |
| 257 | // runSudoChownNonInteractive runs sudo chown using cached credentials (non-interactive). |
| 258 | func runSudoChownNonInteractive(ctx context.Context, username string, recursive bool, path string) error { |
| 259 | args := []string{"-n", "chown"} // -n = non-interactive, fail if password needed |
| 260 | if recursive { |
| 261 | args = append(args, "-R") |
| 262 | } |
| 263 | args = append(args, username, path) |
| 264 | |
| 265 | cmd := exec.CommandContext(ctx, "sudo", args...) |
| 266 | cmd.Stdout = os.Stdout |
| 267 | cmd.Stderr = os.Stderr |
| 268 | |
| 269 | return cmd.Run() |
| 270 | } |
| 271 | |
| 272 | // runSudoChown runs sudo chown with proper terminal handling. |
| 273 | // It resets the terminal to sane mode before running sudo to ensure password input works correctly. |
no test coverage detected