mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #40941 from cpuguy83/down_with_the_func_init
Don't use init() to set unpigz path
This commit is contained in:
commit
d4b7b4b0a7
1 changed files with 19 additions and 19 deletions
|
@ -27,17 +27,6 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var unpigzPath string
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
if path, err := exec.LookPath("unpigz"); err != nil {
|
|
||||||
logrus.Debug("unpigz binary not found in PATH, falling back to go gzip library")
|
|
||||||
} else {
|
|
||||||
logrus.Debugf("Using unpigz binary found at path %s", path)
|
|
||||||
unpigzPath = path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// Compression is the state represents if compressed or not.
|
// Compression is the state represents if compressed or not.
|
||||||
Compression int
|
Compression int
|
||||||
|
@ -158,18 +147,29 @@ func xzDecompress(ctx context.Context, archive io.Reader) (io.ReadCloser, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func gzDecompress(ctx context.Context, buf io.Reader) (io.ReadCloser, error) {
|
func gzDecompress(ctx context.Context, buf io.Reader) (io.ReadCloser, error) {
|
||||||
if unpigzPath == "" {
|
noPigzEnv := os.Getenv("MOBY_DISABLE_PIGZ")
|
||||||
|
var noPigz bool
|
||||||
|
|
||||||
|
if noPigzEnv != "" {
|
||||||
|
var err error
|
||||||
|
noPigz, err = strconv.ParseBool(noPigzEnv)
|
||||||
|
if err != nil {
|
||||||
|
logrus.WithError(err).Warn("invalid value in MOBY_DISABLE_PIGZ env var")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if noPigz {
|
||||||
|
logrus.Debugf("Use of pigz is disabled due to MOBY_DISABLE_PIGZ=%s", noPigzEnv)
|
||||||
return gzip.NewReader(buf)
|
return gzip.NewReader(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
disablePigzEnv := os.Getenv("MOBY_DISABLE_PIGZ")
|
unpigzPath, err := exec.LookPath("unpigz")
|
||||||
if disablePigzEnv != "" {
|
if err != nil {
|
||||||
if disablePigz, err := strconv.ParseBool(disablePigzEnv); err != nil {
|
logrus.Debugf("unpigz binary not found, falling back to go gzip library")
|
||||||
return nil, err
|
|
||||||
} else if disablePigz {
|
|
||||||
return gzip.NewReader(buf)
|
return gzip.NewReader(buf)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
logrus.Debugf("Using %s to decompress", unpigzPath)
|
||||||
|
|
||||||
return cmdStream(exec.CommandContext(ctx, unpigzPath, "-d", "-c"), buf)
|
return cmdStream(exec.CommandContext(ctx, unpigzPath, "-d", "-c"), buf)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue