Merge pull request #1371 from alevkin/master

post-processor/vagrant: Change creating boxes for customizing metadata.json
This commit is contained in:
Mitchell Hashimoto 2014-09-02 09:53:06 -07:00
commit 986394292f
1 changed files with 10 additions and 7 deletions

View File

@ -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
}