Browse code

Fixing hang in archive.CopyWithTar with invalid dst

Signed-off-by: Stefan J. Wernli <swernli@microsoft.com>

Stefan J. Wernli authored on 2015/10/15 08:25:03
Showing 2 changed files
... ...
@@ -910,7 +910,11 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
910 910
 		}
911 911
 	}()
912 912
 
913
-	return archiver.Untar(r, filepath.Dir(dst), nil)
913
+	err = archiver.Untar(r, filepath.Dir(dst), nil)
914
+	if err != nil {
915
+		r.CloseWithError(err)
916
+	}
917
+	return err
914 918
 }
915 919
 
916 920
 // CopyFileWithTar emulates the behavior of the 'cp' command-line
... ...
@@ -3,10 +3,32 @@
3 3
 package archive
4 4
 
5 5
 import (
6
+	"io/ioutil"
6 7
 	"os"
8
+	"path/filepath"
7 9
 	"testing"
8 10
 )
9 11
 
12
+func TestCopyFileWithInvalidDest(t *testing.T) {
13
+	folder, err := ioutil.TempDir("", "docker-archive-test")
14
+	if err != nil {
15
+		t.Fatal(err)
16
+	}
17
+	defer os.RemoveAll(folder)
18
+	dest := "c:dest"
19
+	srcFolder := filepath.Join(folder, "src")
20
+	src := filepath.Join(folder, "src", "src")
21
+	err = os.MkdirAll(srcFolder, 0740)
22
+	if err != nil {
23
+		t.Fatal(err)
24
+	}
25
+	ioutil.WriteFile(src, []byte("content"), 0777)
26
+	err = CopyWithTar(src, dest)
27
+	if err == nil {
28
+		t.Fatalf("archiver.CopyWithTar should throw an error on invalid dest.")
29
+	}
30
+}
31
+
10 32
 func TestCanonicalTarNameForPath(t *testing.T) {
11 33
 	cases := []struct {
12 34
 		in, expected string