ChangeDir changes the current working directory
(ctx context.Context, path string)
| 34 | |
| 35 | // ChangeDir changes the current working directory |
| 36 | func (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 | |
| 84 | func (h *shellCallHandler) Workdir() shellWorkdir { |
| 85 | h.mu.RLock() |
no test coverage detected