1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix bug on compression detection when chunck < 10bytes

This commit is contained in:
Guillaume J. Charmes 2013-06-17 18:11:58 -07:00
parent abf85b2508
commit 02c291d13b

View file

@ -1,7 +1,7 @@
package docker package docker
import ( import (
"bytes" "bufio"
"errors" "errors"
"fmt" "fmt"
"github.com/dotcloud/docker/utils" "github.com/dotcloud/docker/utils"
@ -85,17 +85,17 @@ func Tar(path string, compression Compression) (io.Reader, error) {
func Untar(archive io.Reader, path string) error { func Untar(archive io.Reader, path string) error {
buf := make([]byte, 10) bufferedArchive := bufio.NewReaderSize(archive, 10)
if _, err := archive.Read(buf); err != nil { buf, err := bufferedArchive.Peek(10)
if err != nil {
return err return err
} }
compression := DetectCompression(buf) compression := DetectCompression(buf)
archive = io.MultiReader(bytes.NewReader(buf), archive)
utils.Debugf("Archive compression detected: %s", compression.Extension()) utils.Debugf("Archive compression detected: %s", compression.Extension())
cmd := exec.Command("tar", "-f", "-", "-C", path, "-x"+compression.Flag()) cmd := exec.Command("tar", "-f", "-", "-C", path, "-x"+compression.Flag())
cmd.Stdin = archive cmd.Stdin = bufferedArchive
// 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"}