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

Method moduleSourceWithSourceSubpath

core/schema/modulesource.go:1177–1220  ·  view source on GitHub ↗
(
	ctx context.Context,
	src *core.ModuleSource,
	args struct {
		Path string
	},
)

Source from the content-addressed store, hash-verified

1175}
1176
1177func (s *moduleSourceSchema) moduleSourceWithSourceSubpath(
1178 ctx context.Context,
1179 src *core.ModuleSource,
1180 args struct {
1181 Path string
1182 },
1183) (*core.ModuleSource, error) {
1184 src = src.Clone()
1185 src.SourceSubpath = filepath.Join(src.SourceRootSubpath, args.Path)
1186
1187 contextRootPath := "/"
1188 if src.Kind == core.ModuleSourceKindLocal {
1189 contextRootPath = src.Local.ContextDirectoryPath
1190 }
1191
1192 relPath, err := pathutil.LexicalRelativePath(
1193 filepath.Join(contextRootPath, src.SourceRootSubpath),
1194 filepath.Join(contextRootPath, src.SourceSubpath),
1195 )
1196 if err != nil {
1197 return nil, fmt.Errorf("failed to get relative path from source root to source subpath: %w", err)
1198 }
1199 if !filepath.IsLocal(relPath) {
1200 return nil, fmt.Errorf("local module source subpath %q escapes source root %q", relPath, src.SourceRootSubpath)
1201 }
1202
1203 // reload context since the subpath impacts what we implicitly include in the load
1204 err = s.loadModuleSourceContext(ctx, src)
1205 switch {
1206 case err == nil:
1207 case codes.NotFound == status.Code(err) && src.Kind == core.ModuleSourceKindLocal:
1208 // corner case: dagger init can be called on a context dir that doesn't exist yet
1209 // (e.g. called outside a .git context and the source root dir doesn't exist because
1210 // it's expected to be created when exporting the generated context dir)
1211 // we tolerate a not found error in this case
1212 default:
1213 return nil, fmt.Errorf("failed to reload module source context: %w", err)
1214 }
1215
1216 if err := src.LoadUserDefaults(ctx); err != nil {
1217 return nil, fmt.Errorf("load user defaults: %w", err)
1218 }
1219 return src, nil
1220}
1221
1222func (s *moduleSourceSchema) moduleSourceAsString(
1223 ctx context.Context,

Callers

nothing calls this directly

Calls 5

LexicalRelativePathFunction · 0.92
LoadUserDefaultsMethod · 0.80
CloneMethod · 0.65
CodeMethod · 0.45

Tested by

no test coverage detected