MCPcopy
hub / github.com/keploy/keploy / runSudoChownNonInteractive

Function runSudoChownNonInteractive

utils/permissions_unix.go:258–270  ·  view source on GitHub ↗

runSudoChownNonInteractive runs sudo chown using cached credentials (non-interactive).

(ctx context.Context, username string, recursive bool, path string)

Source from the content-addressed store, hash-verified

256
257// runSudoChownNonInteractive runs sudo chown using cached credentials (non-interactive).
258func 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.

Callers 1

Calls 1

RunMethod · 0.65

Tested by

no test coverage detected