mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix #1162 - Remove bufio from Untar
This commit is contained in:
parent
fd97190ee7
commit
08a87d4b3b
2 changed files with 17 additions and 10 deletions
24
archive.go
24
archive.go
|
@ -2,7 +2,6 @@ package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
"bufio"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
|
@ -26,10 +25,6 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func DetectCompression(source []byte) Compression {
|
func DetectCompression(source []byte) Compression {
|
||||||
for _, c := range source[:10] {
|
|
||||||
utils.Debugf("%x", c)
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceLen := len(source)
|
sourceLen := len(source)
|
||||||
for compression, m := range map[Compression][]byte{
|
for compression, m := range map[Compression][]byte{
|
||||||
Bzip2: {0x42, 0x5A, 0x68},
|
Bzip2: {0x42, 0x5A, 0x68},
|
||||||
|
@ -110,17 +105,26 @@ func Untar(archive io.Reader, path string) error {
|
||||||
if archive == nil {
|
if archive == nil {
|
||||||
return fmt.Errorf("Empty archive")
|
return fmt.Errorf("Empty archive")
|
||||||
}
|
}
|
||||||
bufferedArchive := bufio.NewReaderSize(archive, 10)
|
|
||||||
buf, err := bufferedArchive.Peek(10)
|
buf := make([]byte, 10)
|
||||||
if err != nil {
|
totalN := 0
|
||||||
return err
|
for totalN < 10 {
|
||||||
|
if n, err := archive.Read(buf[totalN:]); err != nil {
|
||||||
|
if err == io.EOF {
|
||||||
|
return fmt.Errorf("Tarball too short")
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
totalN += n
|
||||||
|
utils.Debugf("[tar autodetect] n: %d", n)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
compression := DetectCompression(buf)
|
compression := DetectCompression(buf)
|
||||||
|
|
||||||
utils.Debugf("Archive compression detected: %s", compression.Extension())
|
utils.Debugf("Archive compression detected: %s", compression.Extension())
|
||||||
|
|
||||||
cmd := exec.Command("tar", "--numeric-owner", "-f", "-", "-C", path, "-x"+compression.Flag())
|
cmd := exec.Command("tar", "--numeric-owner", "-f", "-", "-C", path, "-x"+compression.Flag())
|
||||||
cmd.Stdin = bufferedArchive
|
cmd.Stdin = io.MultiReader(bytes.NewReader(buf), archive)
|
||||||
// Hardcode locale environment for predictable outcome regardless of host configuration.
|
// Hardcode locale environment for predictable outcome regardless of host configuration.
|
||||||
// (see https://github.com/dotcloud/docker/issues/355)
|
// (see https://github.com/dotcloud/docker/issues/355)
|
||||||
cmd.Env = []string{"LANG=en_US.utf-8", "LC_ALL=en_US.utf-8"}
|
cmd.Env = []string{"LANG=en_US.utf-8", "LC_ALL=en_US.utf-8"}
|
||||||
|
|
3
image.go
3
image.go
|
@ -94,9 +94,12 @@ func StoreImage(img *Image, layerData Archive, root string, store bool) error {
|
||||||
}
|
}
|
||||||
// If layerData is not nil, unpack it into the new layer
|
// If layerData is not nil, unpack it into the new layer
|
||||||
if layerData != nil {
|
if layerData != nil {
|
||||||
|
start := time.Now()
|
||||||
|
utils.Debugf("Start untar layer")
|
||||||
if err := Untar(layerData, layer); err != nil {
|
if err := Untar(layerData, layer); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
utils.Debugf("Untar time: %vs\n", time.Now().Sub(start).Seconds())
|
||||||
}
|
}
|
||||||
|
|
||||||
return StoreSize(img, root)
|
return StoreSize(img, root)
|
||||||
|
|
Loading…
Reference in a new issue