diff --git a/internal/core/basis.go b/internal/core/basis.go index bf3b44f3e..23107d78d 100644 --- a/internal/core/basis.go +++ b/internal/core/basis.go @@ -3,6 +3,7 @@ package core import ( "context" "fmt" + "path/filepath" "strings" "sync" @@ -33,15 +34,16 @@ import ( // finished with the basis to properly clean // up any open resources. type Basis struct { - basis *vagrant_server.Basis - logger hclog.Logger - config *config.Config - plugins *plugin.Manager - projects map[string]*Project - mappers []*argmapper.Func - dir *datadir.Basis - ctx context.Context - statebag core.StateBag + basis *vagrant_server.Basis + logger hclog.Logger + config *config.Config + plugins *plugin.Manager + projects map[string]*Project + mappers []*argmapper.Func + dir *datadir.Basis + ctx context.Context + statebag core.StateBag + boxCollection *BoxCollection lookupCache map[string]interface{} @@ -200,6 +202,16 @@ func (b *Basis) State() *StateBag { return b.statebag.(*StateBag) } +func (b *Basis) Boxes() (bc *BoxCollection, err error) { + if b.boxCollection == nil { + b.boxCollection = &BoxCollection{ + basis: b, + directory: filepath.Join(b.dir.DataDir().String(), "boxes"), + } + } + return b.boxCollection, nil +} + func (b *Basis) countParents(host core.Host) (int, error) { numParents := 0 p, err := host.Parent() diff --git a/internal/core/project.go b/internal/core/project.go index ebd84227e..73ca2c525 100644 --- a/internal/core/project.go +++ b/internal/core/project.go @@ -62,6 +62,11 @@ func (p *Project) UI() (terminal.UI, error) { return p.ui, nil } +// Boxes implements core.Project +func (p *Project) Boxes() (bc core.BoxCollection, err error) { + return p.basis.Boxes() +} + // CWD implements core.Project func (p *Project) CWD() (path string, err error) { cwd, ok := os.LookupEnv("VAGRANT_CWD")