Fixing hang in archive.CopyWithTar with invalid dst
Signed-off-by: Stefan J. Wernli <swernli@microsoft.com>
This commit is contained in:
parent
831c2e7a7b
commit
f05813a1ea
2 changed files with 27 additions and 1 deletions
|
@ -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
|
// CopyFileWithTar emulates the behavior of the 'cp' command-line
|
||||||
|
|
|
@ -3,10 +3,32 @@
|
||||||
package archive
|
package archive
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"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) {
|
func TestCanonicalTarNameForPath(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
in, expected string
|
in, expected string
|
||||||
|
|
Loading…
Reference in a new issue