diff --git a/internal/config/path.go b/internal/config/path.go index 8b8241032..1a85894c2 100644 --- a/internal/config/path.go +++ b/internal/config/path.go @@ -1,10 +1,10 @@ package config import ( - "fmt" "os" "github.com/hashicorp/vagrant-plugin-sdk/helper/path" + "github.com/hashicorp/vagrant-plugin-sdk/helper/paths" ) // Filename is the default filename for the Vagrant configuration. @@ -26,19 +26,9 @@ func GetVagrantfileName() string { // filename is empty, it will default to the Filename constant. func FindPath(dir path.Path, filename string) (p path.Path, err error) { if dir == nil { - cwd, ok := os.LookupEnv("VAGRANT_CWD") - if ok { - if _, err := os.Stat(cwd); os.IsNotExist(err) { - return nil, fmt.Errorf("VAGRANT_CWD set to path (%s) that does not exist", cwd) - } else { - dir = path.NewPath(cwd) - } - } else { - cwd, err := os.Getwd() - if err != nil { - return nil, err - } - dir = path.NewPath(cwd) + dir, err = paths.VagrantCwd() + if err != nil { + return nil, err } } diff --git a/internal/core/project.go b/internal/core/project.go index f12e4eced..81b407fb8 100644 --- a/internal/core/project.go +++ b/internal/core/project.go @@ -3,7 +3,6 @@ package core import ( "context" "errors" - "os" "strings" "sync" @@ -16,6 +15,7 @@ import ( "github.com/hashicorp/vagrant-plugin-sdk/core" "github.com/hashicorp/vagrant-plugin-sdk/datadir" "github.com/hashicorp/vagrant-plugin-sdk/helper/path" + "github.com/hashicorp/vagrant-plugin-sdk/helper/paths" "github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk" "github.com/hashicorp/vagrant-plugin-sdk/terminal" @@ -68,16 +68,11 @@ func (p *Project) Boxes() (bc core.BoxCollection, err error) { // CWD implements core.Project func (p *Project) CWD() (path string, err error) { - cwd, ok := os.LookupEnv("VAGRANT_CWD") - if ok { - if _, err := os.Stat(cwd); !os.IsNotExist(err) { - // cwd exists - return cwd, nil - } else { - return "", errors.New("VAGRANT_CWD set to path that does not exist") - } + cwd, err := paths.VagrantCwd() + if err != nil { + return "", err } - return os.Getwd() + return cwd.String(), nil } // DataDir implements core.Project