Browse Source

修复 rar 解压问题

Signed-off-by: 716 <[email protected]>
716 4 years ago
parent
commit
77af97b9f8
2 changed files with 8 additions and 7 deletions
  1. 6 6
      model/unarchiveFile.go
  2. 2 1
      model/unarchiveFile_test.go

+ 6 - 6
model/unarchiveFile.go

@@ -55,6 +55,7 @@ func UnArchiveFile(fileFullPath, desRootPath string) error {
 			ContinueOnError:        false,
 			OverwriteExisting:      false,
 			ImplicitTopLevelFolder: false,
+			StripComponents: 1,
 		}
 		err := z.Walk(fileFullPath, func(f archiver.File) error {
 			if f.IsDir() == true {
@@ -78,18 +79,17 @@ func UnArchiveFile(fileFullPath, desRootPath string) error {
 			ContinueOnError:        false,
 			OverwriteExisting:      false,
 			ImplicitTopLevelFolder: false,
+			StripComponents: 1,
 		}
 		err := z.Walk(fileFullPath, func(f archiver.File) error {
 			if f.IsDir() == true {
 				return nil
 			}
-			zfh, ok := f.Header.(tar.Header)
-			if ok {
-				err := processOneFile(f, utf8.Valid([]byte(zfh.Name)), desRootPath)
-				if err != nil {
-					return err
-				}
+			err := processOneFile(f, false, desRootPath)
+			if err != nil {
+				return err
 			}
+
 			return nil
 		})
 		if err != nil {

+ 2 - 1
model/unarchiveFile_test.go

@@ -8,7 +8,8 @@ func TestUnArchiveFile(t *testing.T) {
 
 	desRoot := "C:\\Tmp"
 	//file := "C:\\Tmp\\[subhd]_0_162236051219240.zip"
-	file := "C:\\Tmp\\123.zip"
+	//file := "C:\\Tmp\\123.zip"
+	file := "C:\\Tmp\\456.rar"
 	//file := "C:\\Tmp\\Tmp.7z"
 	//file := "C:\\Tmp\\[zimuku]_0_[zmk.pw]奥斯陆.Oslo.[WEB.1080P]中英文字幕.zip"