MCPcopy Create free account
hub / github.com/dagger/dagger / ChangeDir

Method ChangeDir

cmd/dagger/shell_fs.go:36–82  ·  view source on GitHub ↗

ChangeDir changes the current working directory

(ctx context.Context, path string)

Source from the content-addressed store, hash-verified

34
35// ChangeDir changes the current working directory
36func (h *shellCallHandler) ChangeDir(ctx context.Context, path string) error {
37 if h.Debug() {
38 shellDebug(ctx, "changeDir (before)", path, h.Workdir(), h.debugLoadedModules())
39
40 defer func() {
41 shellDebug(ctx, "changeDir (after)", path, h.Workdir(), h.debugLoadedModules())
42 }()
43 }
44
45 switch path {
46 case "":
47 h.mu.Lock()
48 defer h.mu.Unlock()
49 h.oldwd, h.wd = h.wd, h.initwd
50 return nil
51
52 case "-":
53 h.mu.Lock()
54 defer h.mu.Unlock()
55 h.oldwd, h.wd = h.wd, h.oldwd
56 return nil
57 }
58
59 var subpath string
60
61 def, cfg, err := h.maybeLoadModule(ctx, path, dagger.ModuleServeOpts{Entrypoint: true})
62 if err != nil {
63 return err
64 }
65 if cfg != nil {
66 subpath = cfg.Subpath
67 } else {
68 // if there's no module, pass original path to newWorkdir
69 subpath = path
70 }
71
72 wd, err := h.newWorkdir(ctx, def, subpath)
73 if err != nil {
74 return fmt.Errorf("change workdir: %w", err)
75 }
76
77 h.mu.Lock()
78 defer h.mu.Unlock()
79 h.oldwd, h.wd = h.wd, *wd
80
81 return nil
82}
83
84func (h *shellCallHandler) Workdir() shellWorkdir {
85 h.mu.RLock()

Callers 1

registerCommandsMethod · 0.95

Calls 6

DebugMethod · 0.95
WorkdirMethod · 0.95
debugLoadedModulesMethod · 0.95
maybeLoadModuleMethod · 0.95
newWorkdirMethod · 0.95
shellDebugFunction · 0.85

Tested by

no test coverage detected