Report error if FS is incorrectly handled on client filesystem read
Signed-off-by: Marcos Lilljedahl <marcosnils@gmail.com>
This commit is contained in:
parent
66153c6194
commit
7ffbef33b5
@ -26,10 +26,15 @@ func (t clientFilesystemReadTask) PreRun(_ context.Context, pctx *plancontext.Co
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if pi, 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)
|
return fmt.Errorf("path %q does not exist", path)
|
||||||
} else if !pi.IsDir() && plancontext.IsFSValue(v.Lookup("contents")) {
|
case !pi.IsDir() && isFS:
|
||||||
return fmt.Errorf("path %q is not a directory", path)
|
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")) {
|
if plancontext.IsFSValue(v.Lookup("contents")) {
|
||||||
|
@ -85,14 +85,23 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@test "plan/client/filesystem/read/fs/invalid" {
|
@test "plan/client/filesystem/read/fs/invalid_fs_input" {
|
||||||
cd "$TESTDIR/plan/client/filesystem/read/fs/invalid"
|
cd "$TESTDIR/plan/client/filesystem/read/fs/invalid_fs_input"
|
||||||
|
|
||||||
run "$DAGGER" "do" -p . test
|
run "$DAGGER" "do" -p . test
|
||||||
assert_failure
|
assert_failure
|
||||||
assert_output --partial 'test.txt" is not a directory'
|
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" {
|
@test "plan/client/filesystem/read/fs/relative" {
|
||||||
cd "$TESTDIR/plan/client/filesystem/read/fs/relative"
|
cd "$TESTDIR/plan/client/filesystem/read/fs/relative"
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
dagger.#Plan & {
|
dagger.#Plan & {
|
||||||
|
// Reading a file into a dagger.#FS should not be possbile
|
||||||
client: filesystem: "../rootfs/test.txt": read: contents: dagger.#FS
|
client: filesystem: "../rootfs/test.txt": read: contents: dagger.#FS
|
||||||
actions: test: {
|
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