From 52b932081ce7c6e2d76d260f4702be50f0bb5956 Mon Sep 17 00:00:00 2001 From: Jeffrey Frey Date: Tue, 29 Nov 2022 14:40:06 -0500 Subject: [PATCH] Scoping issue with `err` Use of := inside conditional body overrode scope of return value `err` --- internal/pkg/util/util.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/pkg/util/util.go b/internal/pkg/util/util.go index 62ac0c89..ab2d67cc 100644 --- a/internal/pkg/util/util.go +++ b/internal/pkg/util/util.go @@ -596,7 +596,7 @@ func FileGz( compressor, err := exec.LookPath("pigz") if err != nil { wwlog.Verbose("Could not locate PIGZ") - compressor, err := exec.LookPath("gzip") + compressor, err = exec.LookPath("gzip") if err != nil { wwlog.Verbose("Could not locate GZIP") return errors.Wrapf(err, "No compressor program for image file: %s", file_gz) @@ -612,12 +612,15 @@ func FileGz( out, err := proc.CombinedOutput() if len(out) > 0 { - if err != nil && strings.HasSuffix(compressor, "gzip") && strings.Contains(out, "unrecognized option") { + outStr := string(out[:]) + if err != nil && strings.HasSuffix(compressor, "gzip") && strings.Contains(outStr, "unrecognized option") { + var gzippedFile *os.File + /* Older version of gzip, try it another way: */ wwlog.Verbose("%s does not recognize the --keep flag, trying piped stdout", compressor) /* Open the output file for writing: */ - gzippedFile, err := os.Create(file_gz) + gzippedFile, err = os.Create(file_gz) if err != nil { return errors.Wrapf(err, "Unable to open compressed image file for writing: %s", file_gz) }