Switch to centralized VagrantCWD implementation

Now depends on https://github.com/hashicorp/vagrant-plugin-sdk/pull/104
This commit is contained in:
Paul Hinze 2021-12-20 17:16:10 -06:00
parent 9bda64f78d
commit 2460961749
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
2 changed files with 9 additions and 24 deletions

View File

@ -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
}
}

View File

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