Windows: Undo 908db518 for Windows daemon
Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
parent
f7309796db
commit
b973596a91
1 changed files with 63 additions and 26 deletions
|
@ -30,10 +30,16 @@ func untar() {
|
||||||
|
|
||||||
var options *archive.TarOptions
|
var options *archive.TarOptions
|
||||||
|
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
//read the options from the pipe "ExtraFiles"
|
//read the options from the pipe "ExtraFiles"
|
||||||
if err := json.NewDecoder(os.NewFile(3, "options")).Decode(&options); err != nil {
|
if err := json.NewDecoder(os.NewFile(3, "options")).Decode(&options); err != nil {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if err := json.Unmarshal([]byte(os.Getenv("OPT")), &options); err != nil {
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := chroot(flag.Arg(0)); err != nil {
|
if err := chroot(flag.Arg(0)); err != nil {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
|
@ -68,19 +74,41 @@ func Untar(tarArchive io.Reader, dest string, options *archive.TarOptions) error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var data []byte
|
||||||
|
var r, w *os.File
|
||||||
defer decompressedArchive.Close()
|
defer decompressedArchive.Close()
|
||||||
|
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
// We can't pass a potentially large exclude list directly via cmd line
|
// We can't pass a potentially large exclude list directly via cmd line
|
||||||
// because we easily overrun the kernel's max argument/environment size
|
// because we easily overrun the kernel's max argument/environment size
|
||||||
// when the full image list is passed (e.g. when this is used by
|
// when the full image list is passed (e.g. when this is used by
|
||||||
// `docker load`). We will marshall the options via a pipe to the
|
// `docker load`). We will marshall the options via a pipe to the
|
||||||
// child
|
// child
|
||||||
r, w, err := os.Pipe()
|
|
||||||
|
// This solution won't work on Windows as it will fail in golang
|
||||||
|
// exec_windows.go as at the lowest layer because attr.Files > 3
|
||||||
|
r, w, err = os.Pipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Untar pipe failure: %v", err)
|
return fmt.Errorf("Untar pipe failure: %v", err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// We can't pass the exclude list directly via cmd line
|
||||||
|
// because we easily overrun the shell max argument list length
|
||||||
|
// when the full image list is passed (e.g. when this is used
|
||||||
|
// by `docker load`). Instead we will add the JSON marshalled
|
||||||
|
// and placed in the env, which has significantly larger
|
||||||
|
// max size
|
||||||
|
data, err = json.Marshal(options)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Untar json encode: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cmd := reexec.Command("docker-untar", dest)
|
cmd := reexec.Command("docker-untar", dest)
|
||||||
cmd.Stdin = decompressedArchive
|
cmd.Stdin = decompressedArchive
|
||||||
|
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
cmd.ExtraFiles = append(cmd.ExtraFiles, r)
|
cmd.ExtraFiles = append(cmd.ExtraFiles, r)
|
||||||
output := bytes.NewBuffer(nil)
|
output := bytes.NewBuffer(nil)
|
||||||
cmd.Stdout = output
|
cmd.Stdout = output
|
||||||
|
@ -99,6 +127,15 @@ func Untar(tarArchive io.Reader, dest string, options *archive.TarOptions) error
|
||||||
return fmt.Errorf("Untar re-exec error: %v: output: %s", err, output)
|
return fmt.Errorf("Untar re-exec error: %v: output: %s", err, output)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
} else {
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("OPT=%s", data))
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Untar %s %s", err, out)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TarUntar(src, dst string) error {
|
func TarUntar(src, dst string) error {
|
||||||
|
|
Loading…
Reference in a new issue