From f05813a1ea1f8dfb370f1477cc41afbdbd6dfcfb Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Wed, 14 Oct 2015 16:25:03 -0700 Subject: [PATCH] Fixing hang in archive.CopyWithTar with invalid dst Signed-off-by: Stefan J. Wernli --- archive/archive.go | 6 +++++- archive/archive_windows_test.go | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/archive/archive.go b/archive/archive.go index 69b7bee..9ffd228 100644 --- a/archive/archive.go +++ b/archive/archive.go @@ -910,7 +910,11 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) { } }() - return archiver.Untar(r, filepath.Dir(dst), nil) + err = archiver.Untar(r, filepath.Dir(dst), nil) + if err != nil { + r.CloseWithError(err) + } + return err } // CopyFileWithTar emulates the behavior of the 'cp' command-line diff --git a/archive/archive_windows_test.go b/archive/archive_windows_test.go index 72bc71e..b7abc40 100644 --- a/archive/archive_windows_test.go +++ b/archive/archive_windows_test.go @@ -3,10 +3,32 @@ package archive import ( + "io/ioutil" "os" + "path/filepath" "testing" ) +func TestCopyFileWithInvalidDest(t *testing.T) { + folder, err := ioutil.TempDir("", "docker-archive-test") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(folder) + dest := "c:dest" + srcFolder := filepath.Join(folder, "src") + src := filepath.Join(folder, "src", "src") + err = os.MkdirAll(srcFolder, 0740) + if err != nil { + t.Fatal(err) + } + ioutil.WriteFile(src, []byte("content"), 0777) + err = CopyWithTar(src, dest) + if err == nil { + t.Fatalf("archiver.CopyWithTar should throw an error on invalid dest.") + } +} + func TestCanonicalTarNameForPath(t *testing.T) { cases := []struct { in, expected string