Decompress archive before streaming the unpack in a chroot
Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Conflicts: pkg/archive/archive.go pkg/chrootarchive/archive.go
This commit is contained in:
parent
79b559bc05
commit
1036313f03
2 changed files with 41 additions and 39 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
@ -27,19 +28,14 @@ func chroot(path string) error {
|
|||
func untar() {
|
||||
runtime.LockOSThread()
|
||||
flag.Parse()
|
||||
|
||||
if err := syscall.Chroot(flag.Arg(0)); err != nil {
|
||||
if err := chroot(flag.Arg(0)); err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
if err := syscall.Chdir("/"); err != nil {
|
||||
var options *archive.TarOptions
|
||||
if err := json.NewDecoder(strings.NewReader(flag.Arg(1))).Decode(&options); err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
options := new(archive.TarOptions)
|
||||
dec := json.NewDecoder(strings.NewReader(flag.Arg(1)))
|
||||
if err := dec.Decode(options); err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
if err := archive.Untar(os.Stdin, "/", options); err != nil {
|
||||
if err := archive.Unpack(os.Stdin, "/", options); err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
os.Exit(0)
|
||||
|
@ -56,8 +52,10 @@ func Untar(tarArchive io.Reader, dest string, options *archive.TarOptions) error
|
|||
options.Excludes = []string{}
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
enc := json.NewEncoder(&buf)
|
||||
var (
|
||||
buf bytes.Buffer
|
||||
enc = json.NewEncoder(&buf)
|
||||
)
|
||||
if err := enc.Encode(options); err != nil {
|
||||
return fmt.Errorf("Untar json encode: %v", err)
|
||||
}
|
||||
|
@ -66,9 +64,15 @@ func Untar(tarArchive io.Reader, dest string, options *archive.TarOptions) error
|
|||
return err
|
||||
}
|
||||
}
|
||||
dest = filepath.Clean(dest)
|
||||
decompressedArchive, err := archive.DecompressStream(tarArchive)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer decompressedArchive.Close()
|
||||
|
||||
cmd := reexec.Command("docker-untar", dest, buf.String())
|
||||
cmd.Stdin = tarArchive
|
||||
cmd.Stdin = decompressedArchive
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Untar %s %s", err, out)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue