@@ -13,6 +13,7 @@ import (
1313 "net/http"
1414 "os"
1515 "path/filepath"
16+ "runtime"
1617 "strings"
1718
1819 "com.lc.go.codepush/client/constants"
@@ -111,7 +112,10 @@ func FileMD5(filePath string) (string, error) {
111112}
112113
113114func Zip (src_dir string , zip_file_name string ) {
114-
115+ prefix := `/`
116+ if runtime .GOOS == "windows" {
117+ prefix = `\`
118+ }
115119 // 预防:旧文件无法覆盖
116120 os .RemoveAll (zip_file_name )
117121
@@ -123,7 +127,7 @@ func Zip(src_dir string, zip_file_name string) {
123127 archive := zip .NewWriter (zipfile )
124128 defer archive .Close ()
125129
126- nowSrc := strings .Replace (src_dir , "./" , "" , 1 )
130+ nowSrc := strings .ReplaceAll ( strings . Replace (src_dir , "./" , "" , 1 ), " \\ \\ " , " \\ " )
127131 // 遍历路径信息
128132 filepath .Walk (src_dir , func (path string , info os.FileInfo , _ error ) error {
129133
@@ -134,16 +138,14 @@ func Zip(src_dir string, zip_file_name string) {
134138
135139 // 获取:文件头信息
136140 header , _ := zip .FileInfoHeader (info )
137- header .Name = strings .TrimPrefix (path , nowSrc + `/` )
138-
141+ header .Name = strings .TrimPrefix (path , nowSrc + prefix )
139142 // 判断:文件是不是文件夹
140143 if info .IsDir () {
141- header .Name += `/`
144+ header .Name += prefix
142145 } else {
143146 // 设置:zip的文件压缩算法
144147 header .Method = zip .Deflate
145148 }
146-
147149 // 创建:压缩包头部信息
148150 writer , _ := archive .CreateHeader (header )
149151 if ! info .IsDir () {
0 commit comments