From eaf76618cb59cda46043c07cc3df543dd3d16c43 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 19 Dec 2013 09:16:57 -0800 Subject: [PATCH] post-processor/vagrant: compression_level is an int --- post-processor/vagrant/virtualbox.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/post-processor/vagrant/virtualbox.go b/post-processor/vagrant/virtualbox.go index 8232fc444..88bdc16af 100644 --- a/post-processor/vagrant/virtualbox.go +++ b/post-processor/vagrant/virtualbox.go @@ -13,7 +13,6 @@ import ( "os" "path/filepath" "regexp" - "strconv" ) type VBoxBoxConfig struct { @@ -21,7 +20,7 @@ type VBoxBoxConfig struct { OutputPath string `mapstructure:"output"` VagrantfileTemplate string `mapstructure:"vagrantfile_template"` - CompressionLevel string `mapstructure:"compression_level"` + CompressionLevel int `mapstructure:"compression_level"` tpl *packer.ConfigTemplate } @@ -46,13 +45,26 @@ func (p *VBoxBoxPostProcessor) Configure(raws ...interface{}) error { } p.config.tpl.UserVars = p.config.PackerUserVars + // Defaults + found := false + for _, k := range md.Keys { + println(k) + if k == "compression_level" { + found = true + break + } + } + + if !found { + p.config.CompressionLevel = flate.DefaultCompression + } + // Accumulate any errors errs := common.CheckUnusedConfig(md) validates := map[string]*string{ "output": &p.config.OutputPath, "vagrantfile_template": &p.config.VagrantfileTemplate, - "compression_level": &p.config.CompressionLevel, } for n, ptr := range validates { @@ -145,14 +157,6 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac vf.Write([]byte(vagrantfileContents)) vf.Close() - var level int = flate.DefaultCompression - if p.config.CompressionLevel != "" { - level, err = strconv.Atoi(p.config.CompressionLevel) - if err != nil { - return nil, false, err - } - } - // Create the metadata metadata := map[string]string{"provider": "virtualbox"} if err := WriteMetadata(dir, metadata); err != nil { @@ -167,7 +171,7 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac // Compress the directory to the given output path ui.Message(fmt.Sprintf("Compressing box...")) - if err := DirToBox(outputPath, dir, ui, level); err != nil { + if err := DirToBox(outputPath, dir, ui, p.config.CompressionLevel); err != nil { return nil, false, err }