From 0273fead4d5a9fcdedf69592dd52988f36a5f3f3 Mon Sep 17 00:00:00 2001 From: Guillaume de Rouville Date: Tue, 14 Sep 2021 16:17:05 +0200 Subject: [PATCH] fix/bug: infinite loop non-existent input dir path Signed-off-by: Guillaume de Rouville --- cmd/dagger/cmd/input/dir.go | 6 ++++++ tests/cli.bats | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/cmd/dagger/cmd/input/dir.go b/cmd/dagger/cmd/input/dir.go index 0f404bb7..a64f45d7 100644 --- a/cmd/dagger/cmd/input/dir.go +++ b/cmd/dagger/cmd/input/dir.go @@ -1,6 +1,7 @@ package input import ( + "os" "path/filepath" "strings" @@ -31,6 +32,11 @@ var dirCmd = &cobra.Command{ lg.Fatal().Err(err).Str("path", args[1]).Msg("unable to resolve path") } + // 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") + } + workspace := common.CurrentWorkspace(ctx) if !strings.HasPrefix(p, workspace.Path) { lg.Fatal().Err(err).Str("path", args[1]).Msg("dir is outside the workspace") diff --git a/tests/cli.bats b/tests/cli.bats index 1dc18b8e..7878f3db 100644 --- a/tests/cli.bats +++ b/tests/cli.bats @@ -317,6 +317,10 @@ setup() { assert_output '{ "foo": "bar" }' + + run "$DAGGER" input dir src xxx -e "input" + assert_failure + assert_output --partial "dir doesn't exists" } @test "dagger input dir: ignore .dagger" {