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 <kaz@fly.io>
This commit is contained in:
kaz 2023-10-06 09:20:08 -07:00 committed by Kazuyoshi Kato
parent 34378ec9b4
commit 535916d1d0

View File

@ -303,27 +303,24 @@ func cmdStream(cmd *exec.Cmd, in io.Reader) (io.ReadCloser, error) {
} }
func detectCommand(path, disableEnvName string) string { 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) path, err := exec.LookPath(path)
if err != nil { if err != nil {
log.L.WithError(err).Debugf("%s not found", path) log.L.WithError(err).Debugf("%s not found", path)
return "" 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 return path
} }