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

Method metaFileContents

core/container_exec.go:2261–2308  ·  view source on GitHub ↗
(ctx context.Context, filePath string)

Source from the content-addressed store, hash-verified

2259}
2260
2261func (container *Container) metaFileContents(ctx context.Context, filePath string) (string, error) {
2262 if err := container.Evaluate(ctx); err != nil {
2263 return "", err
2264 }
2265
2266 if container.MetaSnapshot == nil {
2267 return "", ErrNoCommand
2268 }
2269 metaSnapshot, ok := container.MetaSnapshot.Peek()
2270 if !ok || metaSnapshot == nil {
2271 return "", ErrNoCommand
2272 }
2273
2274 query, err := CurrentQuery(ctx)
2275 if err != nil {
2276 return "", err
2277 }
2278 reopened, err := query.SnapshotManager().GetBySnapshotID(ctx, metaSnapshot.SnapshotID(), bkcache.NoUpdateLastUsed)
2279 if err != nil {
2280 return "", err
2281 }
2282 defer func() {
2283 _ = reopened.Release(context.WithoutCancel(ctx))
2284 }()
2285
2286 var content []byte
2287 err = MountRef(ctx, reopened, func(root string, _ *ctrdmount.Mount) error {
2288 fullPath, err := containerdfs.RootPath(root, filePath)
2289 if err != nil {
2290 return err
2291 }
2292 content, err = os.ReadFile(fullPath)
2293 if err != nil {
2294 return TrimErrPathPrefix(err, root)
2295 }
2296 return nil
2297 }, mountRefAsReadOnly)
2298 if err != nil {
2299 if errors.Is(err, errEmptyResultRef) {
2300 return "", ErrNoCommand
2301 }
2302 if errors.Is(err, os.ErrNotExist) {
2303 return "", ErrNoCommand
2304 }
2305 return "", err
2306 }
2307 return string(content), nil
2308}

Callers 4

StdoutMethod · 0.95
StderrMethod · 0.95
CombinedOutputMethod · 0.95
ExitCodeMethod · 0.95

Calls 11

EvaluateMethod · 0.95
CurrentQueryFunction · 0.85
TrimErrPathPrefixFunction · 0.85
PeekMethod · 0.80
IsMethod · 0.80
MountRefFunction · 0.70
GetBySnapshotIDMethod · 0.65
SnapshotManagerMethod · 0.65
SnapshotIDMethod · 0.65
ReleaseMethod · 0.65
ReadFileMethod · 0.65

Tested by

no test coverage detected