create parent dirs of target (#9452)

This commit is contained in:
Megan Marsh 2020-06-18 01:25:04 -07:00 committed by GitHub
parent e951b3731a
commit 801c827058
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import (
"io"
"io/ioutil"
"os"
"path/filepath"
"github.com/hashicorp/hcl/v2/hcldec"
"github.com/hashicorp/packer/helper/multistep"
@ -39,6 +40,14 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
artifact := new(FileArtifact)
// Create all directories leading to target
dir := filepath.Dir(b.config.Target)
if dir != "." {
if err := os.MkdirAll(dir, 0755); err != nil {
return nil, err
}
}
if b.config.Source != "" {
source, err := os.Open(b.config.Source)
if err != nil {

View File

@ -60,8 +60,8 @@ Any [communicator](/docs/templates/communicator) defined is ignored.
### Required:
- `target` (string) - The path for a file which will be copied as the
artifact.
- `target` (string) - The path for the artifact file that will be created. If
the path contains directories that don't exist, Packer will create them, too.
### Optional: