Fix unzip empty dir bug

This commit is contained in:
Liang Ding 2015-11-20 09:38:29 +08:00
parent bf7ebfd618
commit 84cdbe88b3
2 changed files with 43 additions and 4 deletions

View File

@ -176,6 +176,11 @@ func cloneZipItem(f *zip.File, dest string) error {
}
if f.FileInfo().IsDir() {
err = os.Mkdir(path, os.ModeDir|os.ModePerm)
if nil != err {
return err
}
return nil
}
@ -188,7 +193,7 @@ func cloneZipItem(f *zip.File, dest string) error {
defer rc.Close()
// use os.Create() since Zip don't store file permissions.
// use os.Create() since Zip don't store file permissions
fileCopy, err := os.Create(path)
if nil != err {
return err

View File

@ -56,21 +56,24 @@ func TestUnzip(t *testing.T) {
}
func TestEmptyDir(t *testing.T) {
err := os.MkdirAll(packageName+"/dir/subDir1", 644)
dir1 := "/dir/subDir1"
dir2 := "/dir/subDir2"
err := os.MkdirAll(packageName+dir1, 644)
if nil != err {
t.Error(err)
return
}
err = os.MkdirAll(packageName+"/dir/subDir2", 644)
err = os.MkdirAll(packageName+dir2, 644)
if nil != err {
t.Error(err)
return
}
f, err := os.Create(packageName + "/dir/subDir2/file")
f, err := os.Create(packageName + dir2 + "/file")
if nil != err {
t.Error(err)
@ -98,6 +101,37 @@ func TestEmptyDir(t *testing.T) {
return
}
err = Zip.Unzip(packageName+"/dir.zip", packageName+"/unzipDir")
if nil != err {
t.Error(err)
return
}
if !File.IsExist(packageName+"/unzipDir") || !File.IsDir(packageName+"/unzipDir") {
t.Error("Unzip failed")
return
}
if !File.IsExist(packageName+"/unzipDir"+dir1) || !File.IsDir(packageName+"/unzipDir"+dir1) {
t.Error("Unzip failed")
return
}
if !File.IsExist(packageName+"/unzipDir"+dir2) || !File.IsDir(packageName+"/unzipDir"+dir2) {
t.Error("Unzip failed")
return
}
if !File.IsExist(packageName+"/unzipDir"+dir2+"/file") || File.IsDir(packageName+"/unzipDir"+dir2+"/file") {
t.Error("Unzip failed")
return
}
}
func TestMain(m *testing.M) {