MCPcopy Index your code
hub / github.com/dagger/dagger / newWorkdir

Method newWorkdir

cmd/dagger/shell_fs.go:403–479  ·  view source on GitHub ↗
(ctx context.Context, def *moduleDef, subpath string)

Source from the content-addressed store, hash-verified

401}
402
403func (h *shellCallHandler) newWorkdir(ctx context.Context, def *moduleDef, subpath string) (rwd *shellWorkdir, rerr error) {
404 var context moduleContext
405 var digest string
406 var err error
407
408 if def != nil && def.SourceDigest != h.modDigest() {
409 context, err = newModuleContext(ctx, def)
410 if err != nil {
411 return nil, err
412 }
413 digest = def.SourceDigest
414 } else {
415 h.mu.RLock()
416 context = h.wd.Context
417 digest = h.wd.Module
418 h.mu.RUnlock()
419 }
420
421 // initial context, without a loaded module (core API only)
422 if context == nil {
423 // a few quick checks first
424 root, err := pathutil.Abs(subpath)
425 if err != nil {
426 return nil, err
427 }
428 info, err := os.Stat(root)
429 if err != nil {
430 return nil, err
431 }
432 if !info.IsDir() {
433 return nil, fmt.Errorf("%q is not a directory", root)
434 }
435
436 if !h.noModule {
437 // ask API where the context dir is (.git)
438 ctx, span := Tracer().Start(ctx, "looking for context directory", telemetry.Internal())
439 defer telemetry.EndWithCause(span, &rerr)
440
441 src := h.dag.ModuleSource(root, dagger.ModuleSourceOpts{
442 DisableFindUp: true,
443 AllowNotExists: true,
444 })
445 root, err = src.LocalContextDirectoryPath(ctx)
446 if err != nil {
447 return nil, err
448 }
449 subpath, err = src.SourceRootSubpath(ctx)
450 if err != nil {
451 return nil, err
452 }
453 }
454 return &shellWorkdir{
455 Context: localSourceContext{
456 Root: root,
457 },
458 Path: filepath.Join("/", subpath),
459 }, nil
460 }

Callers 2

InitializeMethod · 0.95
ChangeDirMethod · 0.95

Calls 14

modDigestMethod · 0.95
contextAbsPathMethod · 0.95
DirectoryMethod · 0.95
AbsFunction · 0.92
newModuleContextFunction · 0.85
InternalMethod · 0.80
TracerFunction · 0.70
StatMethod · 0.65
StartMethod · 0.65
SyncMethod · 0.65
IsDirMethod · 0.45
ModuleSourceMethod · 0.45

Tested by

no test coverage detected