Skip to content

Commit

Permalink
Fix/dagger edit: wrong dir Path leads to infinite loop
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume de Rouville <guillaume.derouville@gmail.com>
  • Loading branch information
grouville committed Sep 26, 2021
1 parent 2249eab commit a7ca7e1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/dagger/cmd/input/dir.go
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions state/input.go
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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}]`,
Expand Down
2 changes: 1 addition & 1 deletion tests/cli.bats
Expand Up @@ -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" {
Expand Down

0 comments on commit a7ca7e1

Please sign in to comment.