MCPcopy Create free account
hub / github.com/docker/docker-agent / setupWorkingDirectory

Function setupWorkingDirectory

cmd/root/flags.go:47–70  ·  view source on GitHub ↗
(workingDir string)

Source from the content-addressed store, hash-verified

45}
46
47func setupWorkingDirectory(workingDir string) error {
48 if workingDir == "" {
49 return nil
50 }
51
52 absWd, err := filepath.Abs(workingDir)
53 if err != nil {
54 return fmt.Errorf("invalid working directory: %w", err)
55 }
56
57 info, err := os.Stat(absWd)
58 if err != nil || !info.IsDir() {
59 return fmt.Errorf("working directory does not exist or is not a directory: %s", absWd)
60 }
61
62 if err := os.Chdir(absWd); err != nil {
63 return fmt.Errorf("failed to change working directory: %w", err)
64 }
65
66 _ = os.Setenv("PWD", absWd)
67 slog.Debug("Working directory set", "path", absWd)
68
69 return nil
70}
71
72func canonize(endpoint string) string {
73 return strings.TrimSuffix(strings.TrimSpace(endpoint), "/")

Callers 1

addGatewayFlagsFunction · 0.85

Calls 1

DebugMethod · 0.80

Tested by

no test coverage detected