Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve edge cases with --tmpdir behavior #2000

Merged
merged 4 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/internal/packager/git/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path"
"strings"

"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/pkg/transform"
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/go-git/go-git/v5/plumbing"
Expand All @@ -18,7 +19,7 @@ import (
func (g *Git) DownloadRepoToTemp(gitURL string) error {
g.Spinner.Updatef("g.DownloadRepoToTemp(%s)", gitURL)

path, err := utils.MakeTempDir()
path, err := utils.MakeTempDir(config.CommonOptions.TempDirectory)
if err != nil {
return fmt.Errorf("unable to create tmpdir: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion src/internal/packager/helm/post-render.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (h *Helm) newRenderer() (*renderer, error) {

func (r *renderer) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, error) {
// This is very low cost and consistent for how we replace elsewhere, also good for debugging
tempDir, err := utils.MakeTempDir()
tempDir, err := utils.MakeTempDir(config.CommonOptions.TempDirectory)
if err != nil {
return nil, fmt.Errorf("unable to create tmpdir: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion src/pkg/oci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"path/filepath"
"strings"

"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/pkg/utils/helpers"
Expand Down Expand Up @@ -107,7 +108,7 @@ func DownloadPackageTarball(url, destinationTarball string, concurrency int) err
return err
}

tmp, err := utils.MakeTempDir()
tmp, err := utils.MakeTempDir(config.CommonOptions.TempDirectory)
if err != nil {
return err
}
Expand Down
14 changes: 4 additions & 10 deletions src/pkg/packager/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,11 @@ func isValidFileExtension(filename string) bool {
}

func createPaths(basePath string) (paths types.TempPaths, err error) {
if basePath == "" {
basePath, err = utils.MakeTempDir()
if err != nil {
return paths, err
}
} else {
if err := utils.CreateDirectory(basePath, 0700); err != nil {
return paths, fmt.Errorf("unable to create temp directory: %w", err)
}
basePath, err = utils.MakeTempDir(basePath)
if err != nil {
return paths, err
}
message.Debug("Using temporary directory:", basePath)

paths = types.TempPaths{
Base: basePath,

Expand Down
2 changes: 1 addition & 1 deletion src/pkg/packager/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ func (p *Packager) loadDifferentialData() error {
// Save the fact that this is a differential build into the build data of the package
p.cfg.Pkg.Build.Differential = true

tmpDir, _ := utils.MakeTempDir()
tmpDir, _ := utils.MakeTempDir(config.CommonOptions.TempDirectory)
defer os.RemoveAll(tmpDir)

// Load the package spec of the package we're using as a 'reference' for the differential build
Expand Down
11 changes: 8 additions & 3 deletions src/pkg/utils/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,14 @@ type TextTemplate struct {
}

// MakeTempDir creates a temp directory with the zarf- prefix.
func MakeTempDir() (string, error) {
tmp, err := os.MkdirTemp("", tmpPathPrefix)
message.Debugf("Creating temp path: '%s'", tmp)
func MakeTempDir(basePath string) (string, error) {
if basePath != "" {
if err := CreateDirectory(basePath, 0700); err != nil {
return "", err
}
}
tmp, err := os.MkdirTemp(basePath, tmpPathPrefix)
message.Debug("Using temporary directory:", basePath)
return tmp, err
}

Expand Down