From a414e7cdb958ff1a3b5f2e542bad19664fe02b6a Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Tue, 14 Jul 2020 15:47:55 -0700 Subject: [PATCH] convert relative to absolute path in prepare --- builder/vagrant/builder.go | 16 ++++++++++++---- .../builder/vagrant/Config-not-required.mdx | 3 ++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/builder/vagrant/builder.go b/builder/vagrant/builder.go index 5692383bc..8bd38c379 100644 --- a/builder/vagrant/builder.go +++ b/builder/vagrant/builder.go @@ -106,7 +106,8 @@ type Config struct { // `{{ .BoxName }}`, `{{ .SyncedFolder }}`, and `{{.InsertKey}}`, which // correspond to the Packer options box_name, synced_folder, and insert_key. Template string `mapstructure:"template" required:"false"` - + // Path to the folder to be synced to the guest. The path can be absolute + // or relative to the directory Packer is being run from. SyncedFolder string `mapstructure:"synced_folder"` // Don't call "vagrant add" to add the box to your local environment; this // is necessary if you want to launch a box that is already added to your @@ -242,9 +243,16 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { } } - if _, err := os.Stat(b.config.SyncedFolder); err != nil { - errs = packer.MultiErrorAppend(errs, - fmt.Errorf("synced_folder \"%s\" does not exist on the Packer host.", b.config.SyncedFolder)) + if b.config.SyncedFolder != "" { + b.config.SyncedFolder, err = filepath.Abs(b.config.SyncedFolder) + if err != nil { + errs = packer.MultiErrorAppend(errs, + fmt.Errorf("unable to determine absolute path for synced_folder: %s", b.config.SyncedFolder)) + } + if _, err := os.Stat(b.config.SyncedFolder); err != nil { + errs = packer.MultiErrorAppend(errs, + fmt.Errorf("synced_folder \"%s\" does not exist on the Packer host.", b.config.SyncedFolder)) + } } if errs != nil && len(errs.Errors) > 0 { diff --git a/website/pages/partials/builder/vagrant/Config-not-required.mdx b/website/pages/partials/builder/vagrant/Config-not-required.mdx index 146655af7..4889f1d3e 100644 --- a/website/pages/partials/builder/vagrant/Config-not-required.mdx +++ b/website/pages/partials/builder/vagrant/Config-not-required.mdx @@ -51,7 +51,8 @@ `{{ .BoxName }}`, `{{ .SyncedFolder }}`, and `{{.InsertKey}}`, which correspond to the Packer options box_name, synced_folder, and insert_key. -- `synced_folder` (string) - Synced Folder +- `synced_folder` (string) - Path to the folder to be synced to the guest. The path can be absolute + or relative to the directory Packer is being run from. - `skip_add` (bool) - Don't call "vagrant add" to add the box to your local environment; this is necessary if you want to launch a box that is already added to your