From dc555d6b5bd6355183b8983ade529577b586534a Mon Sep 17 00:00:00 2001 From: Andrey Levkin Date: Thu, 24 Jul 2014 15:16:57 +0400 Subject: [PATCH 1/2] Change creating boxes for customizing metadata.json. --- post-processor/vagrant/post-processor.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/post-processor/vagrant/post-processor.go b/post-processor/vagrant/post-processor.go index 8fb486edb..25275bc24 100644 --- a/post-processor/vagrant/post-processor.go +++ b/post-processor/vagrant/post-processor.go @@ -101,16 +101,6 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac } defer os.RemoveAll(dir) - // Copy all of the includes files into the temporary directory - for _, src := range config.Include { - ui.Message(fmt.Sprintf("Copying from include: %s", src)) - dst := filepath.Join(dir, filepath.Base(src)) - if err := CopyContents(dst, src); err != nil { - err = fmt.Errorf("Error copying include file: %s\n\n%s", src, err) - return nil, false, err - } - } - // Run the provider processing step vagrantfile, metadata, err := provider.Process(ui, artifact, dir) if err != nil { @@ -122,6 +112,16 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac return nil, false, err } + // Copy all of the includes files into the temporary directory + for _, src := range config.Include { + ui.Message(fmt.Sprintf("Copying from include: %s", src)) + dst := filepath.Join(dir, filepath.Base(src)) + if err := CopyContents(dst, src); err != nil { + err = fmt.Errorf("Error copying include file: %s\n\n%s", src, err) + return nil, false, err + } + } + // Write our Vagrantfile var customVagrantfile string if config.VagrantfileTemplate != "" { From e0c628508892ffcac9de49869097b0c9ef9a5adc Mon Sep 17 00:00:00 2001 From: Andrey Levkin Date: Thu, 24 Jul 2014 17:39:21 +0400 Subject: [PATCH 2/2] Change creating boxes for customizing metadata.json --- post-processor/vagrant/post-processor.go | 20 ++++++++++---------- post-processor/vagrant/util.go | 17 ++++++++++------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/post-processor/vagrant/post-processor.go b/post-processor/vagrant/post-processor.go index 25275bc24..8fb486edb 100644 --- a/post-processor/vagrant/post-processor.go +++ b/post-processor/vagrant/post-processor.go @@ -101,6 +101,16 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac } defer os.RemoveAll(dir) + // Copy all of the includes files into the temporary directory + for _, src := range config.Include { + ui.Message(fmt.Sprintf("Copying from include: %s", src)) + dst := filepath.Join(dir, filepath.Base(src)) + if err := CopyContents(dst, src); err != nil { + err = fmt.Errorf("Error copying include file: %s\n\n%s", src, err) + return nil, false, err + } + } + // Run the provider processing step vagrantfile, metadata, err := provider.Process(ui, artifact, dir) if err != nil { @@ -112,16 +122,6 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac return nil, false, err } - // Copy all of the includes files into the temporary directory - for _, src := range config.Include { - ui.Message(fmt.Sprintf("Copying from include: %s", src)) - dst := filepath.Join(dir, filepath.Base(src)) - if err := CopyContents(dst, src); err != nil { - err = fmt.Errorf("Error copying include file: %s\n\n%s", src, err) - return nil, false, err - } - } - // Write our Vagrantfile var customVagrantfile string if config.VagrantfileTemplate != "" { diff --git a/post-processor/vagrant/util.go b/post-processor/vagrant/util.go index db695289a..6c558a1c4 100644 --- a/post-processor/vagrant/util.go +++ b/post-processor/vagrant/util.go @@ -130,12 +130,15 @@ func DirToBox(dst, dir string, ui packer.Ui, level int) error { // WriteMetadata writes the "metadata.json" file for a Vagrant box. func WriteMetadata(dir string, contents interface{}) error { - f, err := os.Create(filepath.Join(dir, "metadata.json")) - if err != nil { - return err - } - defer f.Close() + if _, err := os.Stat(filepath.Join(dir, "metadata.json")); os.IsNotExist(err) { + f, err := os.Create(filepath.Join(dir, "metadata.json")) + if err != nil { + return err + } + defer f.Close() - enc := json.NewEncoder(f) - return enc.Encode(contents) + enc := json.NewEncoder(f) + return enc.Encode(contents) + } + return nil }