From 5df47c885638159f9f0163980cc0fd81014906b0 Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 25 Jul 2022 13:05:48 -0500 Subject: [PATCH] Check for existence of metatdata.json to determine if a box is v1 --- internal/core/box_collection.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/core/box_collection.go b/internal/core/box_collection.go index 354d8399a..78011cbfb 100644 --- a/internal/core/box_collection.go +++ b/internal/core/box_collection.go @@ -10,7 +10,6 @@ import ( "os" "path/filepath" "strings" - "time" "github.com/h2non/filetype" "github.com/hashicorp/go-getter" @@ -284,10 +283,16 @@ func validateNewPath(path string, parentPath string) (newPath string, err error) // Checks is the given directory represents a V1 box func (b *BoxCollection) isV1Box(dir string) bool { + // If there is a box.ovf file then there is a good chance that this is a V1 box boxOvfPath := filepath.Join(dir, "box.ovf") if _, err := os.Stat(boxOvfPath); errors.Is(err, os.ErrNotExist) { return false } + // If a metadata.json file exists then this is not a V1 box + metadataPath := filepath.Join(dir, "metadata.json") + if _, err := os.Stat(metadataPath); err == nil { + return false + } return true } @@ -295,11 +300,7 @@ func (b *BoxCollection) isV1Box(dir string) bool { // in order to build the new box. The provider for the new box will // be defaulted to be virtualbox. func (b *BoxCollection) upgradeV1Box(dir string) (newDir string, err error) { - newDir = filepath.Join( - b.basis.dir.TempDir().String(), - fmt.Sprintf("box-update-%d", time.Now().UnixNano()), - ) - err = os.MkdirAll(newDir, os.ModePerm) + newDir, err = ioutil.TempDir(b.basis.dir.TempDir().String(), "box-update") if err != nil { return "", err }