From a7ca7e11bab57e22ca2dcd5c60a8e13d59620c94 Mon Sep 17 00:00:00 2001 From: Guillaume de Rouville Date: Sun, 26 Sep 2021 20:50:37 +0200 Subject: [PATCH] Fix/dagger edit: wrong dir Path leads to infinite loop Signed-off-by: Guillaume de Rouville --- cmd/dagger/cmd/input/dir.go | 2 +- state/input.go | 5 +++++ tests/cli.bats | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/dagger/cmd/input/dir.go b/cmd/dagger/cmd/input/dir.go index 18b60799..7af9cbb7 100644 --- a/cmd/dagger/cmd/input/dir.go +++ b/cmd/dagger/cmd/input/dir.go @@ -34,7 +34,7 @@ var dirCmd = &cobra.Command{ // Check that directory exists if _, err := os.Stat(p); os.IsNotExist(err) { - lg.Fatal().Err(err).Str("path", args[1]).Msg("dir doesn't exists") + lg.Fatal().Err(err).Str("path", args[1]).Msg("dir doesn't exist") } project := common.CurrentProject(ctx) diff --git a/state/input.go b/state/input.go index 1b074d28..58fa6c6f 100644 --- a/state/input.go +++ b/state/input.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "io/ioutil" + "os" "path" "path/filepath" "strings" @@ -113,6 +114,10 @@ func (dir dirInput) Compile(_ string, state *State) (*compiler.Value, error) { if !strings.HasPrefix(p, state.Project) { return nil, fmt.Errorf("%q is outside the project", dir.Path) } + // Check that directory exists + if _, err := os.Stat(p); os.IsNotExist(err) { + return nil, fmt.Errorf("%q dir doesn't exist", dir.Path) + } llb := fmt.Sprintf( `#up: [{do:"local",dir:"%s", include:%s, exclude:%s}]`, diff --git a/tests/cli.bats b/tests/cli.bats index 5b7f123b..aad00418 100644 --- a/tests/cli.bats +++ b/tests/cli.bats @@ -320,7 +320,7 @@ setup() { run "$DAGGER" input dir src xxx -e "input" assert_failure - assert_output --partial "dir doesn't exists" + assert_output --partial "dir doesn't exist" } @test "dagger input dir: ignore .dagger" {