fs: don't panic when handling scratch output results
Fixes #22 Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
6d008cafb8
commit
9e0bb85a1b
13
dagger/fs.go
13
dagger/fs.go
@ -2,6 +2,7 @@ package dagger
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
"github.com/moby/buildkit/client/llb"
|
"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 {
|
if err := (&fs).solve(ctx); err != nil {
|
||||||
return nil, err
|
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})
|
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 {
|
if err := (&fs).solve(ctx); err != nil {
|
||||||
return nil, err
|
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{
|
st, err := fs.output.ReadDir(ctx, bkgw.ReadDirRequest{
|
||||||
Path: dir,
|
Path: dir,
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user