Skip to content

Commit

Permalink
Respect TART_HOME (#50)
Browse files Browse the repository at this point in the history
Fixes #38
  • Loading branch information
fkorotkov authored Feb 27, 2023
1 parent ab20fcc commit 4c69620
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
3 changes: 1 addition & 2 deletions builder/tart/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,5 @@ func (a *TartVMArtifact) Destroy() error {
}

func (a *TartVMArtifact) vmDirPath() string {
home, _ := os.UserHomeDir()
return path.Join(home, ".tart", "vms", a.VMName)
return PathInTartHome("vms", a.VMName)
}
10 changes: 10 additions & 0 deletions builder/tart/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ import (
"bytes"
"fmt"
"log"
"os"
"os/exec"
"path"
"strings"
)

func PathInTartHome(elem ...string) string {
if home := os.Getenv("TART_HOME"); home != "" {
return path.Join(home, path.Join(elem...))
}
userHome, _ := os.UserHomeDir()
return path.Join(userHome, ".tart", path.Join(elem...))
}

func TartExec(args ...string) (string, error) {
var out bytes.Buffer

Expand Down
12 changes: 2 additions & 10 deletions builder/tart/step_disk_file_prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"os"
"path"
)

type stepDiskFilePrepare struct {
Expand All @@ -21,17 +20,10 @@ func (s *stepDiskFilePrepare) Run(ctx context.Context, state multistep.StateBag)

ui.Say("Inspecting machine disk image...")

homeDir, err := os.UserHomeDir()

if err != nil {
ui.Error(err.Error())
return multistep.ActionHalt
}

diskImagePath := path.Join(homeDir, ".tart", "vms", config.VMName, "disk.img")
diskImagePath := PathInTartHome("vms", config.VMName, "disk.img")

if config.DiskSizeGb > 0 {
err = growDisk(config.DiskSizeGb, diskImagePath)
err := growDisk(config.DiskSizeGb, diskImagePath)

if err != nil {
ui.Error(err.Error())
Expand Down

0 comments on commit 4c69620

Please sign in to comment.