Skip to content

Commit 7f399ce

Browse files
committed
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.
1 parent 34378ec commit 7f399ce

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

archive/compression/compression.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -303,25 +303,22 @@ func cmdStream(cmd *exec.Cmd, in io.Reader) (io.ReadCloser, error) {
303303
}
304304

305305
func detectCommand(path, disableEnvName string) string {
306-
path, err := exec.LookPath(path)
307-
if err != nil {
308-
log.L.WithError(err).Debugf("%s not found", path)
309-
return ""
310-
}
311-
312306
// Check if this command is disabled via the env variable
313307
value := os.Getenv(disableEnvName)
314-
if value == "" {
315-
return path
316-
}
308+
if value != "" {
309+
disable, err := strconv.ParseBool(value)
310+
if err != nil {
311+
log.L.WithError(err).Warnf("could not parse %s: %s", disableEnvName, value)
312+
}
317313

318-
disable, err := strconv.ParseBool(value)
319-
if err != nil {
320-
log.L.WithError(err).Warnf("could not parse %s: %s", disableEnvName, value)
321-
return path
314+
if disable {
315+
return ""
316+
}
322317
}
323318

324-
if disable {
319+
path, err := exec.LookPath(path)
320+
if err != nil {
321+
log.L.WithError(err).Debugf("%s not found", path)
325322
return ""
326323
}
327324

0 commit comments

Comments
 (0)