Merge pull request #973 from grouville/fix/bug-infinite-loop

fix/bug: infinite loop non-existent input dir path
This commit is contained in:
Sam Alba 2021-09-14 08:44:33 -07:00 committed by GitHub
commit 8dbfdaca1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package input package input
import ( import (
"os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -31,6 +32,11 @@ var dirCmd = &cobra.Command{
lg.Fatal().Err(err).Str("path", args[1]).Msg("unable to resolve path") 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) workspace := common.CurrentWorkspace(ctx)
if !strings.HasPrefix(p, workspace.Path) { if !strings.HasPrefix(p, workspace.Path) {
lg.Fatal().Err(err).Str("path", args[1]).Msg("dir is outside the workspace") lg.Fatal().Err(err).Str("path", args[1]).Msg("dir is outside the workspace")

View File

@ -317,6 +317,10 @@ setup() {
assert_output '{ assert_output '{
"foo": "bar" "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" { @test "dagger input dir: ignore .dagger" {