diff --git a/chrootarchive/archive.go b/chrootarchive/archive.go index f9108c5..0077f93 100644 --- a/chrootarchive/archive.go +++ b/chrootarchive/archive.go @@ -6,7 +6,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "os" "path/filepath" "runtime" @@ -40,9 +39,7 @@ func untar() { fatal(err) } // fully consume stdin in case it is zero padded - if _, err := ioutil.ReadAll(os.Stdin); err != nil { - fatal(err) - } + flush(os.Stdin) os.Exit(0) } diff --git a/chrootarchive/archive_test.go b/chrootarchive/archive_test.go index 8477c06..0fe3d64 100644 --- a/chrootarchive/archive_test.go +++ b/chrootarchive/archive_test.go @@ -83,3 +83,19 @@ func TestChrootUntarEmptyArchiveFromSlowReader(t *testing.T) { t.Fatal(err) } } + +func TestChrootApplyEmptyArchiveFromSlowReader(t *testing.T) { + tmpdir, err := ioutil.TempDir("", "docker-TestChrootApplyEmptyArchiveFromSlowReader") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpdir) + dest := filepath.Join(tmpdir, "dest") + if err := os.MkdirAll(dest, 0700); err != nil { + t.Fatal(err) + } + stream := &slowEmptyTarReader{size: 10240, chunkSize: 1024} + if err := ApplyLayer(dest, stream); err != nil { + t.Fatal(err) + } +} diff --git a/chrootarchive/diff.go b/chrootarchive/diff.go index 0fdb3b2..d4e9529 100644 --- a/chrootarchive/diff.go +++ b/chrootarchive/diff.go @@ -34,6 +34,8 @@ func applyLayer() { if err != nil { fatal(err) } + os.RemoveAll(tmpDir) + flush(os.Stdin) os.Exit(0) } diff --git a/chrootarchive/init.go b/chrootarchive/init.go index b548e9f..4116026 100644 --- a/chrootarchive/init.go +++ b/chrootarchive/init.go @@ -2,6 +2,8 @@ package chrootarchive import ( "fmt" + "io" + "io/ioutil" "os" "github.com/docker/docker/pkg/reexec" @@ -16,3 +18,9 @@ func fatal(err error) { fmt.Fprint(os.Stderr, err) os.Exit(1) } + +// flush consumes all the bytes from the reader discarding +// any errors +func flush(r io.Reader) { + io.Copy(ioutil.Discard, r) +}