diff --git a/actions/pack_action.go b/actions/pack_action.go index 0e869c63..fbe9a10b 100644 --- a/actions/pack_action.go +++ b/actions/pack_action.go @@ -26,6 +26,7 @@ import ( "log" "path" "strings" + "os/exec" "github.com/go-debos/debos" ) @@ -68,11 +69,29 @@ func (pf *PackAction) Verify(context *debos.DebosContext) error { func (pf *PackAction) Run(context *debos.DebosContext) error { pf.LogStart() + usePigz := false + if pf.Compression == "gz" { + if _,err := exec.LookPath("pigz"); err == nil { + usePigz = true + } + } outfile := path.Join(context.Artifactdir, pf.File) - var tarOpt = "cf" + tarOpts[pf.Compression] + command := []string{"tar"} + if usePigz == true { + command = append(command, "cf") + } else { + command = append(command, "cf" + tarOpts[pf.Compression]) + } + command = append(command, outfile) + command = append(command, "--xattrs") + command = append(command, "--xattrs-include=*.*") + if usePigz == true { + command = append(command, "--use-compress-program=pigz") + } + command = append(command, "-C", context.Rootdir) + command = append(command, ".") + log.Printf("Compressing to %s\n", outfile) - return debos.Command{}.Run("Packing", "tar", tarOpt, outfile, - "--xattrs", "--xattrs-include=*.*", - "-C", context.Rootdir, ".") + return debos.Command{}.Run("Packing", command...) } diff --git a/archiver.go b/archiver.go index c54f89c0..5844df5d 100644 --- a/archiver.go +++ b/archiver.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" "strings" + "os/exec" ) type ArchiveType int @@ -92,6 +93,12 @@ func tarOptions(compression string) string { func (tar *ArchiveTar) Unpack(destination string) error { command := []string{"tar"} + usePigz := false + if compression, ok := tar.options["tarcompression"]; ok && compression == "gz" { + if _, err := exec.LookPath("pigz"); err == nil { + usePigz = true + } + } if options, ok := tar.options["taroptions"].([]string); ok { for _, option := range options { command = append(command, option) @@ -104,7 +111,11 @@ func (tar *ArchiveTar) Unpack(destination string) error { if compression, ok := tar.options["tarcompression"]; ok { if unpackTarOpt := tarOptions(compression.(string)); len(unpackTarOpt) > 0 { - command = append(command, unpackTarOpt) + if usePigz == true { + command = append(command, "--use-compress-program=pigz") + } else { + command = append(command, unpackTarOpt) + } } } command = append(command, "-f", tar.file)