Merge pull request #8276 from alrs/fix-post-processor-compress-errors

post-processor/compress: fix dropped errors
This commit is contained in:
Adrien Delorme 2019-10-29 12:23:08 +01:00 committed by GitHub
commit 3eef8f15c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 1 deletions

View File

@ -101,7 +101,11 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
return nil return nil
} }
func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, bool, error) { func (p *PostProcessor) PostProcess(
ctx context.Context,
ui packer.Ui,
artifact packer.Artifact,
) (packer.Artifact, bool, bool, error) {
// These are extra variables that will be made available for interpolation. // These are extra variables that will be made available for interpolation.
p.config.ctx.Data = map[string]string{ p.config.ctx.Data = map[string]string{
@ -132,26 +136,40 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact
// Setup output interface. If we're using compression, output is a // Setup output interface. If we're using compression, output is a
// compression writer. Otherwise it's just a file. // compression writer. Otherwise it's just a file.
var output io.WriteCloser var output io.WriteCloser
errTmpl := "error creating %s writer: %s"
switch p.config.Algorithm { switch p.config.Algorithm {
case "bgzf": case "bgzf":
ui.Say(fmt.Sprintf("Using bgzf compression with %d cores for %s", ui.Say(fmt.Sprintf("Using bgzf compression with %d cores for %s",
runtime.GOMAXPROCS(-1), target)) runtime.GOMAXPROCS(-1), target))
output, err = makeBGZFWriter(outputFile, p.config.CompressionLevel) output, err = makeBGZFWriter(outputFile, p.config.CompressionLevel)
if err != nil {
return nil, false, false, fmt.Errorf(errTmpl, p.config.Algorithm, err)
}
defer output.Close() defer output.Close()
case "lz4": case "lz4":
ui.Say(fmt.Sprintf("Using lz4 compression with %d cores for %s", ui.Say(fmt.Sprintf("Using lz4 compression with %d cores for %s",
runtime.GOMAXPROCS(-1), target)) runtime.GOMAXPROCS(-1), target))
output, err = makeLZ4Writer(outputFile, p.config.CompressionLevel) output, err = makeLZ4Writer(outputFile, p.config.CompressionLevel)
if err != nil {
return nil, false, false, fmt.Errorf(errTmpl, p.config.Algorithm, err)
}
defer output.Close() defer output.Close()
case "xz": case "xz":
ui.Say(fmt.Sprintf("Using xz compression with 1 core for %s (library does not support MT)", ui.Say(fmt.Sprintf("Using xz compression with 1 core for %s (library does not support MT)",
target)) target))
output, err = makeXZWriter(outputFile) output, err = makeXZWriter(outputFile)
if err != nil {
return nil, false, false, fmt.Errorf(errTmpl, p.config.Algorithm, err)
}
defer output.Close() defer output.Close()
case "pgzip": case "pgzip":
ui.Say(fmt.Sprintf("Using pgzip compression with %d cores for %s", ui.Say(fmt.Sprintf("Using pgzip compression with %d cores for %s",
runtime.GOMAXPROCS(-1), target)) runtime.GOMAXPROCS(-1), target))
output, err = makePgzipWriter(outputFile, p.config.CompressionLevel) output, err = makePgzipWriter(outputFile, p.config.CompressionLevel)
if err != nil {
return nil, false, false,
fmt.Errorf(errTmpl, p.config.Algorithm, err)
}
defer output.Close() defer output.Close()
default: default:
output = outputFile output = outputFile