From 535916d1d0a586acad617ceb37f07be487a09847 Mon Sep 17 00:00:00 2001 From: kaz Date: Fri, 6 Oct 2023 09:20:08 -0700 Subject: [PATCH] Skip exec.LookPath if a specific gzip implementation is disabled Both pigz and igzip can be disabled via the environment variables. If disabled, calling exec.LookPath and logging "not found" message is, even in the debug level, doesn't make much sense. Signed-off-by: Kazuyoshi Kato --- archive/compression/compression.go | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/archive/compression/compression.go b/archive/compression/compression.go index b69efcd7e..0caf710ae 100644 --- a/archive/compression/compression.go +++ b/archive/compression/compression.go @@ -303,27 +303,24 @@ func cmdStream(cmd *exec.Cmd, in io.Reader) (io.ReadCloser, error) { } func detectCommand(path, disableEnvName string) string { + // Check if this command is disabled via the env variable + value := os.Getenv(disableEnvName) + if value != "" { + disable, err := strconv.ParseBool(value) + if err != nil { + log.L.WithError(err).Warnf("could not parse %s: %s", disableEnvName, value) + } + + if disable { + return "" + } + } + path, err := exec.LookPath(path) if err != nil { log.L.WithError(err).Debugf("%s not found", path) return "" } - // Check if this command is disabled via the env variable - value := os.Getenv(disableEnvName) - if value == "" { - return path - } - - disable, err := strconv.ParseBool(value) - if err != nil { - log.L.WithError(err).Warnf("could not parse %s: %s", disableEnvName, value) - return path - } - - if disable { - return "" - } - return path }