mirror of
https://github.com/hashicorp/packer.git
synced 2026-04-08 18:48:56 -04:00
* Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl. * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package command
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func mustString(s string, e error) string {
|
|
if e != nil {
|
|
panic(e)
|
|
}
|
|
return s
|
|
}
|
|
|
|
func createFiles(dir string, content map[string]string) {
|
|
for relPath, content := range content {
|
|
contentPath := filepath.Join(dir, relPath)
|
|
if err := os.MkdirAll(filepath.Dir(contentPath), 0777); err != nil {
|
|
panic(err)
|
|
}
|
|
if err := ioutil.WriteFile(contentPath, []byte(content), 0666); err != nil {
|
|
panic(err)
|
|
}
|
|
log.Printf("created tmp file: %s", contentPath)
|
|
}
|
|
}
|
|
|
|
type configDirSingleton struct {
|
|
dirs map[string]string
|
|
}
|
|
|
|
// when you call dir twice with the same key, the result should be the same
|
|
func (c *configDirSingleton) dir(key string) string {
|
|
if v, exists := c.dirs[key]; exists {
|
|
return v
|
|
}
|
|
c.dirs[key] = mustString(ioutil.TempDir("", "pkr-test-cfg-dir-"+key))
|
|
return c.dirs[key]
|
|
}
|
|
|
|
// fileExists returns true if the filename is found
|
|
func fileExists(filename string) bool {
|
|
if _, err := os.Stat(filename); err == nil {
|
|
return true
|
|
}
|
|
return false
|
|
}
|