Update paths to use Path type instead of string
This commit is contained in:
parent
dc58438476
commit
25dfcd039f
@ -79,12 +79,12 @@ func (c *Info) Execute(trm terminal.UI, p plugincore.Project) int32 {
|
||||
defaultPrivateKeyPath, _ := p.DefaultPrivateKey()
|
||||
|
||||
trm.Output("\nEnvironment information")
|
||||
trm.Output("Working directory: " + cwd)
|
||||
trm.Output("Working directory: " + cwd.String())
|
||||
trm.Output("Data directory: " + datadir.DataDir().String())
|
||||
trm.Output("Vagrantfile name: " + vagrantfileName)
|
||||
trm.Output("Home directory: " + home)
|
||||
trm.Output("Local data directory: " + localDataPath)
|
||||
trm.Output("Default private key path: " + defaultPrivateKeyPath)
|
||||
trm.Output("Home directory: " + home.String())
|
||||
trm.Output("Local data directory: " + localDataPath.String())
|
||||
trm.Output("Default private key path: " + defaultPrivateKeyPath.String())
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -116,14 +116,14 @@ func (c *Command) ExecuteInfo(trm terminal.UI, p plugincore.Project) int32 {
|
||||
defaultPrivateKeyPath, _ := p.DefaultPrivateKey()
|
||||
|
||||
trm.Output("\nEnvironment information")
|
||||
trm.Output("Working directory: " + cwd)
|
||||
trm.Output("Working directory: " + cwd.String())
|
||||
if datadir != nil && datadir.DataDir() != nil {
|
||||
trm.Output("Data directory: " + datadir.DataDir().String())
|
||||
}
|
||||
trm.Output("Vagrantfile name: " + vagrantfileName)
|
||||
trm.Output("Home directory: " + home)
|
||||
trm.Output("Local data directory: " + localDataPath)
|
||||
trm.Output("Default private key path: " + defaultPrivateKeyPath)
|
||||
trm.Output("Home directory: " + home.String())
|
||||
trm.Output("Local data directory: " + localDataPath.String())
|
||||
trm.Output("Default private key path: " + defaultPrivateKeyPath.String())
|
||||
|
||||
ptrm, err := p.UI()
|
||||
if err != nil {
|
||||
|
||||
@ -239,12 +239,8 @@ func (b *Basis) Config() *vagrant_plugin_sdk.Vagrantfile_Vagrantfile {
|
||||
return b.basis.Configuration
|
||||
}
|
||||
|
||||
func (p *Basis) CWD() (path string, err error) {
|
||||
cwd, err := paths.VagrantCwd()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return cwd.String(), nil
|
||||
func (p *Basis) CWD() (path path.Path, err error) {
|
||||
return paths.VagrantCwd()
|
||||
}
|
||||
|
||||
// Basis UI is the "default" UI with no prefix modifications
|
||||
@ -258,9 +254,8 @@ func (b *Basis) DataDir() (*datadir.Basis, error) {
|
||||
}
|
||||
|
||||
// DefaultPrivateKey implements core.Basis
|
||||
func (b *Basis) DefaultPrivateKey() (path string, err error) {
|
||||
defaultPrivateKeyPath := b.dir.DataDir().Join("insecure_private_key")
|
||||
return defaultPrivateKeyPath.String(), nil
|
||||
func (b *Basis) DefaultPrivateKey() (path path.Path, err error) {
|
||||
return b.dir.DataDir().Join("insecure_private_key"), nil
|
||||
}
|
||||
|
||||
// Implements core.Basis
|
||||
|
||||
@ -17,6 +17,7 @@ import (
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/hashicorp/go-version"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/core"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/helper/path"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
|
||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
@ -232,8 +233,8 @@ func (b *Box) Destroy() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (b *Box) Directory() (path string, err error) {
|
||||
return b.box.Directory, nil
|
||||
func (b *Box) Directory() (path.Path, error) {
|
||||
return path.NewPath(b.box.Directory), nil
|
||||
}
|
||||
|
||||
// Checks if the box has an update and returns the metadata, version,
|
||||
@ -345,11 +346,11 @@ func (b *Box) Provider() (name string, err error) {
|
||||
}
|
||||
|
||||
// This repackages this box and outputs it to the given path.
|
||||
func (b *Box) Repackage(outputPath string) (err error) {
|
||||
func (b *Box) Repackage(outputPath path.Path) (err error) {
|
||||
b.logger.Trace("repackaging box", b.box.Name,
|
||||
"to", outputPath)
|
||||
|
||||
tarFile, err := os.Create(outputPath)
|
||||
tarFile, err := os.Create(outputPath.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
"github.com/hashicorp/go-getter"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/core"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/helper/path"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
|
||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
@ -45,9 +46,9 @@ func NewBoxCollection(basis *Basis, dir string, logger hclog.Logger) (bc *BoxCol
|
||||
// * BoxProviderDoesntMatch - If the given box provider doesn't match the
|
||||
// actual box provider in the untarred box.
|
||||
// * BoxUnpackageFailure - An invalid tar file.
|
||||
func (b *BoxCollection) Add(path, name, version, metadataURL string, force bool, providers ...string) (box core.Box, err error) {
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
return nil, fmt.Errorf("Could not add box, unable to find path %s", path)
|
||||
func (b *BoxCollection) Add(p path.Path, name, version, metadataURL string, force bool, providers ...string) (box core.Box, err error) {
|
||||
if _, err := os.Stat(p.String()); err != nil {
|
||||
return nil, fmt.Errorf("Could not add box, unable to find path %s", p.String())
|
||||
}
|
||||
exists, err := b.Find(name, version, providers...)
|
||||
if err != nil {
|
||||
@ -70,7 +71,7 @@ func (b *BoxCollection) Add(path, name, version, metadataURL string, force bool,
|
||||
} // delete tempdir when finished
|
||||
defer os.RemoveAll(tempDir)
|
||||
b.logger.Debug("Unpacking box")
|
||||
boxFile, err := os.Open(path)
|
||||
boxFile, err := os.Open(p.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -86,7 +87,7 @@ func (b *BoxCollection) Add(path, name, version, metadataURL string, force bool,
|
||||
ext = "tar.gz"
|
||||
}
|
||||
decompressor := getter.Decompressors[ext]
|
||||
err = decompressor.Decompress(tempDir, path, true, os.ModeDir)
|
||||
err = decompressor.Decompress(tempDir, p.String(), true, os.ModeDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -112,7 +113,7 @@ func (b *BoxCollection) Add(path, name, version, metadataURL string, force bool,
|
||||
}
|
||||
}
|
||||
if !foundProvider {
|
||||
return nil, fmt.Errorf("could not add box %s, provider '%s' does not match the expected providers %s", path, provider, providers)
|
||||
return nil, fmt.Errorf("could not add box %s, provider '%s' does not match the expected providers %s", p.String(), provider, providers)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -84,12 +84,8 @@ func (b *Project) Config() (*vagrant_plugin_sdk.Vagrantfile_Vagrantfile, error)
|
||||
}
|
||||
|
||||
// CWD implements core.Project
|
||||
func (p *Project) CWD() (path string, err error) {
|
||||
cwd, err := paths.VagrantCwd()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return cwd.String(), nil
|
||||
func (p *Project) CWD() (path path.Path, err error) {
|
||||
return paths.VagrantCwd()
|
||||
}
|
||||
|
||||
// DataDir implements core.Project
|
||||
@ -98,7 +94,7 @@ func (p *Project) DataDir() (*datadir.Project, error) {
|
||||
}
|
||||
|
||||
// DefaultPrivateKey implements core.Project
|
||||
func (p *Project) DefaultPrivateKey() (path string, err error) {
|
||||
func (p *Project) DefaultPrivateKey() (path path.Path, err error) {
|
||||
return p.basis.DefaultPrivateKey()
|
||||
}
|
||||
|
||||
@ -109,8 +105,8 @@ func (p *Project) DefaultProvider() (name string, err error) {
|
||||
}
|
||||
|
||||
// Home implements core.Project
|
||||
func (p *Project) Home() (path string, err error) {
|
||||
return p.project.Path, nil
|
||||
func (p *Project) Home() (dir path.Path, err error) {
|
||||
return path.NewPath(p.project.Path), nil
|
||||
}
|
||||
|
||||
// Host implements core.Project
|
||||
@ -119,8 +115,8 @@ func (p *Project) Host() (host core.Host, err error) {
|
||||
}
|
||||
|
||||
// LocalData implements core.Project
|
||||
func (p *Project) LocalData() (path string, err error) {
|
||||
return p.dir.DataDir().String(), nil
|
||||
func (p *Project) LocalData() (d path.Path, err error) {
|
||||
return p.dir.DataDir(), nil
|
||||
}
|
||||
|
||||
// PrimaryTargetName implements core.Project
|
||||
@ -135,7 +131,7 @@ func (p *Project) ResourceId() (string, error) {
|
||||
}
|
||||
|
||||
// RootPath implements core.Project
|
||||
func (p *Project) RootPath() (path string, err error) {
|
||||
func (p *Project) RootPath() (path path.Path, err error) {
|
||||
// TODO: need vagrantfile loading to be completed in order to implement
|
||||
return
|
||||
}
|
||||
@ -190,8 +186,8 @@ func (p *Project) TargetNames() ([]string, error) {
|
||||
}
|
||||
|
||||
// Tmp implements core.Project
|
||||
func (p *Project) Tmp() (path string, err error) {
|
||||
return p.dir.TempDir().String(), nil
|
||||
func (p *Project) Tmp() (path path.Path, err error) {
|
||||
return p.dir.TempDir(), nil
|
||||
}
|
||||
|
||||
// UI implements core.Project
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user