Skip to content

Commit

Permalink
Add progress bar for bundle extraction (only in a terminal)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumerose committed Jun 30, 2020
1 parent 5d7340c commit 76f4dc3
Show file tree
Hide file tree
Showing 279 changed files with 51,091 additions and 37,033 deletions.
6 changes: 4 additions & 2 deletions go.mod
Expand Up @@ -9,11 +9,13 @@ require (
github.com/YourFin/binappend v0.0.0-20181105185800-0add4bf0b9ad
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a
github.com/cavaliercoder/grab v2.0.0+incompatible
github.com/cheggaaa/pb/v3 v3.0.4
github.com/code-ready/clicumber v0.0.0-20190801094041-02a92c8f7ece
github.com/code-ready/machine v0.0.0-20191115055627-b284f794e910
github.com/docker/go-units v0.4.0
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mattn/go-colorable v0.0.9
github.com/mattn/go-colorable v0.1.2
github.com/mattn/go-isatty v0.0.12
github.com/pborman/uuid v1.2.0
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
github.com/pkg/errors v0.8.1
Expand All @@ -23,7 +25,7 @@ require (
github.com/spf13/viper v1.3.2
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7
golang.org/x/sys v0.0.0-20200116001909-b77594299b42
golang.org/x/text v0.3.0
gopkg.in/AlecAivazis/survey.v1 v1.8.5
howett.net/plist v0.0.0-20181124034731-591f970eefbb
Expand Down
23 changes: 21 additions & 2 deletions go.sum
Expand Up @@ -6,6 +6,8 @@ github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3Q
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc=
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
github.com/YourFin/binappend v0.0.0-20181105185800-0add4bf0b9ad h1:OUogh+sUEo6yRwGEkqifcr3MfXNi0AtdCSwh7H8yTUM=
github.com/YourFin/binappend v0.0.0-20181105185800-0add4bf0b9ad/go.mod h1:QhzJSct0NZ/q7HOtQrw867061u93HYPWa4KTotzdzls=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
Expand All @@ -15,6 +17,8 @@ github.com/bugsnag/bugsnag-go v1.5.1/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqR
github.com/bugsnag/panicwrap v1.2.0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
github.com/cavaliercoder/grab v2.0.0+incompatible h1:wZHbBQx56+Yxjx2TCGDcenhh3cJn7cCLMfkEPmySTSE=
github.com/cavaliercoder/grab v2.0.0+incompatible/go.mod h1:tTBkfNqSBfuMmMBFaO2phgyhdYhiZQ/+iXCZDzcDsMI=
github.com/cheggaaa/pb/v3 v3.0.4 h1:QZEPYOj2ix6d5oEg63fbHmpolrnNiwjUsk+h74Yt4bM=
github.com/cheggaaa/pb/v3 v3.0.4/go.mod h1:7rgWxLrAUcFMkvJuv09+DYi7mMUYi8nO9iOWcvGJPfw=
github.com/code-ready/clicumber v0.0.0-20190801094041-02a92c8f7ece h1:ZuvFtsdv+H0JlBkKU+M6zGZOH0JcH7hnIvVNy5PQZro=
github.com/code-ready/clicumber v0.0.0-20190801094041-02a92c8f7ece/go.mod h1:bjcKpFX8OebrlwSDgDAf0KAqpdVPGQssQk+IcVwlcog=
github.com/code-ready/machine v0.0.0-20191115055627-b284f794e910 h1:roFnY4xZrCGYgzxymOxCONENB6VOZICijEPsN+2x5zw=
Expand All @@ -27,6 +31,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
Expand Down Expand Up @@ -59,8 +65,17 @@ github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDe
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
Expand Down Expand Up @@ -111,10 +126,14 @@ golang.org/x/sys v0.0.0-20180606202747-9527bec2660b/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190529164535-6a60838ec259/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 h1:LepdCS8Gf/MVejFIt8lsiexZATdoGVyp5bcyS+rYoUI=
golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX0Az1Bw5HF7PDraD+qU=
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/AlecAivazis/survey.v1 v1.8.5 h1:QoEEmn/d5BbuPIL2qvXwzJdttFFhRQFkaq+tEKb7SMI=
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/cache/cache.go
Expand Up @@ -71,7 +71,7 @@ func (c *Cache) CacheBinary() error {
}

// Extract the tarball and put it the cache directory.
extractedFiles, err := extract.UncompressWithFilter(assetTmpFile, tmpDir,
extractedFiles, err := extract.UncompressWithFilter(assetTmpFile, tmpDir, false,
func(filename string) bool { return filepath.Base(filename) == c.binaryName })
if err != nil {
return errors.Wrapf(err, "Cannot uncompress '%s'", assetTmpFile)
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/machine/bundle/metadata.go
Expand Up @@ -95,7 +95,7 @@ func (bundle *CrcBundleInfo) resolvePath(filename string) string {
}

func Extract(sourcepath string) (*CrcBundleInfo, error) {
_, err := extract.Uncompress(sourcepath, constants.MachineCacheDir)
_, err := extract.Uncompress(sourcepath, constants.MachineCacheDir, true)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/preflight/preflight_check_tray_darwin.go
Expand Up @@ -210,7 +210,7 @@ func downloadOrExtractTrayApp() error {
if err != nil && !goos.IsExist(err) {
return errors.Wrap(err, "Cannot create the target directory.")
}
_, err = extract.Uncompress(archivePath, outputPath)
_, err = extract.Uncompress(archivePath, outputPath, false)
if err != nil {
return errors.Wrapf(err, "Cannot uncompress '%s'", archivePath)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/preflight/preflight_checks_tray_windows.go
Expand Up @@ -123,7 +123,7 @@ func fixTrayBinaryExists() error {
}
}
archivePath := filepath.Join(tmpArchivePath, filepath.Base(constants.GetCRCWindowsTrayDownloadURL()))
_, err = extract.Uncompress(archivePath, constants.TrayBinaryDir)
_, err = extract.Uncompress(archivePath, constants.TrayBinaryDir, false)
if err != nil {
return fmt.Errorf("Cannot uncompress '%s': %v", archivePath, err)
}
Expand Down
23 changes: 17 additions & 6 deletions pkg/extract/extract.go
Expand Up @@ -10,19 +10,21 @@ import (
"path/filepath"
"strings"

"github.com/cheggaaa/pb/v3"
"github.com/code-ready/crc/pkg/crc/logging"
"github.com/mattn/go-isatty"
"github.com/xi2/xz"
)

func UncompressWithFilter(tarball, targetDir string, fileFilter func(string) bool) ([]string, error) {
return uncompress(tarball, targetDir, fileFilter)
func UncompressWithFilter(tarball, targetDir string, showProgress bool, fileFilter func(string) bool) ([]string, error) {
return uncompress(tarball, targetDir, fileFilter, showProgress)
}

func Uncompress(tarball, targetDir string) ([]string, error) {
return uncompress(tarball, targetDir, nil)
func Uncompress(tarball, targetDir string, showProgress bool) ([]string, error) {
return uncompress(tarball, targetDir, nil, showProgress)
}

func uncompress(tarball, targetDir string, fileFilter func(string) bool) ([]string, error) {
func uncompress(tarball, targetDir string, fileFilter func(string) bool, showProgress bool) ([]string, error) {
logging.Debugf("Uncompressing %s to %s", tarball, targetDir)

if strings.HasSuffix(tarball, ".zip") {
Expand Down Expand Up @@ -117,9 +119,18 @@ func untarFile(tarReader *tar.Reader, header *tar.Header, path string) error {
}
defer file.Close()

var reader io.Reader
reader = tarReader
if isatty.IsTerminal(os.Stdout.Fd()) && header.FileInfo().Size() >= 1_000_000_000 {
bar := pb.Simple.Start64(header.FileInfo().Size())
bar.Set("prefix", fmt.Sprintf("%s: ", filepath.Base(header.Name)))
defer bar.Finish()
reader = bar.NewProxyReader(tarReader)
}

// copy over contents
// #nosec G110
_, err = io.Copy(file, tarReader)
_, err = io.Copy(file, reader)
return err
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/extract/extract_test.go
Expand Up @@ -99,9 +99,9 @@ func testUncompress(archiveName string, fileFilter func(string) bool, files File

var fileList []string
if fileFilter != nil {
fileList, err = UncompressWithFilter(archiveName, destDir, fileFilter)
fileList, err = UncompressWithFilter(archiveName, destDir, false, fileFilter)
} else {
fileList, err = Uncompress(archiveName, destDir)
fileList, err = Uncompress(archiveName, destDir, false)
}
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions vendor/github.com/VividCortex/ewma/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/VividCortex/ewma/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

140 changes: 140 additions & 0 deletions vendor/github.com/VividCortex/ewma/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 76f4dc3

Please sign in to comment.