Merge pull request #1979 from marcosnils/fix/fs_read_file
Fixes hang errors when incorrectly using files as dagger.#FS on client filesystem
This commit is contained in:
commit
d00fbff9d5
@ -18,8 +18,7 @@ func init() {
|
||||
Register("ClientFilesystemRead", func() Task { return &clientFilesystemReadTask{} })
|
||||
}
|
||||
|
||||
type clientFilesystemReadTask struct {
|
||||
}
|
||||
type clientFilesystemReadTask struct{}
|
||||
|
||||
func (t clientFilesystemReadTask) PreRun(_ context.Context, pctx *plancontext.Context, v *compiler.Value) error {
|
||||
path, err := t.parsePath(v)
|
||||
@ -27,8 +26,15 @@ func (t clientFilesystemReadTask) PreRun(_ context.Context, pctx *plancontext.Co
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
|
||||
isFS := plancontext.IsFSValue(v.Lookup("contents"))
|
||||
|
||||
switch pi, err := os.Stat(path); {
|
||||
case errors.Is(err, os.ErrNotExist):
|
||||
return fmt.Errorf("path %q does not exist", path)
|
||||
case !pi.IsDir() && isFS:
|
||||
return fmt.Errorf("path %q is not a directory", path)
|
||||
case pi.IsDir() && !isFS:
|
||||
return fmt.Errorf("path %q cannot be a directory", path)
|
||||
}
|
||||
|
||||
if plancontext.IsFSValue(v.Lookup("contents")) {
|
||||
|
@ -84,6 +84,24 @@ setup() {
|
||||
assert_output --partial 'path "/foobar" does not exist'
|
||||
}
|
||||
|
||||
|
||||
@test "plan/client/filesystem/read/fs/invalid_fs_input" {
|
||||
cd "$TESTDIR/plan/client/filesystem/read/fs/invalid_fs_input"
|
||||
|
||||
run "$DAGGER" "do" -p . test
|
||||
assert_failure
|
||||
assert_output --partial 'test.txt" is not a directory'
|
||||
}
|
||||
|
||||
|
||||
@test "plan/client/filesystem/read/fs/invalid_fs_type" {
|
||||
cd "$TESTDIR/plan/client/filesystem/read/fs/invalid_fs_type"
|
||||
|
||||
run "$DAGGER" "do" -p . test
|
||||
assert_failure
|
||||
assert_output --partial 'rootfs" cannot be a directory'
|
||||
}
|
||||
|
||||
@test "plan/client/filesystem/read/fs/relative" {
|
||||
cd "$TESTDIR/plan/client/filesystem/read/fs/relative"
|
||||
|
||||
@ -221,4 +239,4 @@ setup() {
|
||||
# Run with invalid platform
|
||||
run "$DAGGER" "do" -p./plan/platform/config_platform_failure_invalid_platform.cue verify
|
||||
assert_failure
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
// Reading a file into a dagger.#FS should not be possbile
|
||||
client: filesystem: "../rootfs/test.txt": read: contents: dagger.#FS
|
||||
actions: test: {
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/core"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
// Reading a directory into a non-fs should fail
|
||||
client: filesystem: "../rootfs": read: contents: string
|
||||
actions: {
|
||||
image: core.#Pull & {
|
||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||
}
|
||||
test: core.#Exec & {
|
||||
input: image.output
|
||||
args: ["test", client.filesystem."../rootfs".read.contents]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user