fs: don't panic when handling scratch output results

Fixes #22

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-01-14 15:38:46 -08:00
parent 6d008cafb8
commit 9e0bb85a1b

View File

@ -2,6 +2,7 @@ package dagger
import (
"context"
"os"
"path"
"github.com/moby/buildkit/client/llb"
@ -47,6 +48,12 @@ func (fs FS) ReadFile(ctx context.Context, filename string) ([]byte, error) {
if err := (&fs).solve(ctx); err != nil {
return nil, err
}
// NOTE: llb.Scratch is represented by a `nil` reference. If solve result is
// Scratch, then `fs.output` is `nil`.
if fs.output == nil {
return nil, os.ErrNotExist
}
return fs.output.ReadFile(ctx, bkgw.ReadRequest{Filename: filename})
}
@ -55,6 +62,12 @@ func (fs FS) ReadDir(ctx context.Context, dir string) ([]Stat, error) {
if err := (&fs).solve(ctx); err != nil {
return nil, err
}
// NOTE: llb.Scratch is represented by a `nil` reference. If solve result is
// Scratch, then `fs.output` is `nil`.
if fs.output == nil {
return []Stat{}, nil
}
st, err := fs.output.ReadDir(ctx, bkgw.ReadDirRequest{
Path: dir,
})