fix/bug: infinite loop non-existent input dir path

Signed-off-by: Guillaume de Rouville <guillaume.derouville@gmail.com>
This commit is contained in:
Guillaume de Rouville
2021-09-14 16:17:05 +02:00
parent 4d45e269e0
commit 0273fead4d
2 changed files with 10 additions and 0 deletions

View File

@@ -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")