create parent dirs of target (#9452)
This commit is contained in:
parent
e951b3731a
commit
801c827058
|
@ -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 {
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
Loading…
Reference in New Issue