From f3a2aeeff9d2be59d4c2275e58811acf396b8b7a Mon Sep 17 00:00:00 2001 From: Ross Smith II Date: Mon, 18 Nov 2013 10:38:19 -0800 Subject: [PATCH] Skip gzip compression if compression_level=0 --- CHANGELOG.md | 1 + post-processor/vagrant/util.go | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a12e211a..02b4002df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ FEATURES: IMPROVEMENTS: +* Vagrant post-processor skips gzip compression when compression_level=0 * builder/amazon/all: Can now specify a list of multiple security group IDs to apply. [GH-499] * builder/amazon/all: AWS API requests are now retried when a temporary diff --git a/post-processor/vagrant/util.go b/post-processor/vagrant/util.go index 6b9b53fe1..d53dc3a07 100644 --- a/post-processor/vagrant/util.go +++ b/post-processor/vagrant/util.go @@ -2,6 +2,7 @@ package vagrant import ( "archive/tar" + "compress/flate" "compress/gzip" "encoding/json" "fmt" @@ -52,13 +53,22 @@ func DirToBox(dst, dir string, ui packer.Ui, level int) error { } defer dstF.Close() - gzipWriter, err := gzip.NewWriterLevel(dstF, level) - if err != nil { - return err - } - defer gzipWriter.Close() + var tarOrGzipWriter io.Writer - tarWriter := tar.NewWriter(gzipWriter) + if level != flate.NoCompression { + log.Printf("Compressing with gzip compression level %v", level) + gzipWriter, err := gzip.NewWriterLevel(dstF, level) + if err != nil { + return err + } + defer gzipWriter.Close() + tarOrGzipWriter = gzipWriter + } else { + log.Printf("Skipping gzip compression") + tarOrGzipWriter = dstF + } + + tarWriter := tar.NewWriter(tarOrGzipWriter) defer tarWriter.Close() // This is the walk func that tars each of the files in the dir