MCPcopy Index your code
hub / github.com/docker/docker-agent / writePlanFile

Function writePlanFile

pkg/tools/builtin/plan/plan.go:547–562  ·  view source on GitHub ↗

writePlanFile writes plan content to a file for export_plan_to_file. It creates any missing parent directories and writes atomically (temp + rename), so a reader never sees a partial export and the agent can point at a fresh path without first creating its directory.

(path, content string)

Source from the content-addressed store, hash-verified

545// so a reader never sees a partial export and the agent can point at a fresh
546// path without first creating its directory.
547func writePlanFile(path, content string) error {
548 clean := filepath.Clean(path)
549
550 if info, err := os.Stat(clean); err == nil && info.IsDir() {
551 return fmt.Errorf("path %q is a directory, not a file", path)
552 }
553 if dir := filepath.Dir(clean); dir != "" {
554 if err := os.MkdirAll(dir, 0o700); err != nil {
555 return fmt.Errorf("creating directory for plan file: %w", err)
556 }
557 }
558 if err := atomicfile.Write(clean, strings.NewReader(content), 0o600); err != nil {
559 return fmt.Errorf("writing plan file: %w", err)
560 }
561 return nil
562}
563
564func (t *ToolSet) Tools(context.Context) ([]tools.Tool, error) {
565 return []tools.Tool{

Callers 1

exportPlanToFileMethod · 0.85

Calls 2

WriteFunction · 0.92
DirMethod · 0.80

Tested by

no test coverage detected