@@ -13,6 +13,7 @@ import (
13
13
"net/http"
14
14
"os"
15
15
"path/filepath"
16
+ "runtime"
16
17
"strings"
17
18
18
19
"com.lc.go.codepush/client/constants"
@@ -111,7 +112,10 @@ func FileMD5(filePath string) (string, error) {
111
112
}
112
113
113
114
func Zip (src_dir string , zip_file_name string ) {
114
-
115
+ prefix := `/`
116
+ if runtime .GOOS == "windows" {
117
+ prefix = `\`
118
+ }
115
119
// 预防:旧文件无法覆盖
116
120
os .RemoveAll (zip_file_name )
117
121
@@ -123,7 +127,7 @@ func Zip(src_dir string, zip_file_name string) {
123
127
archive := zip .NewWriter (zipfile )
124
128
defer archive .Close ()
125
129
126
- nowSrc := strings .Replace (src_dir , "./" , "" , 1 )
130
+ nowSrc := strings .ReplaceAll ( strings . Replace (src_dir , "./" , "" , 1 ), " \\ \\ " , " \\ " )
127
131
// 遍历路径信息
128
132
filepath .Walk (src_dir , func (path string , info os.FileInfo , _ error ) error {
129
133
@@ -134,16 +138,14 @@ func Zip(src_dir string, zip_file_name string) {
134
138
135
139
// 获取:文件头信息
136
140
header , _ := zip .FileInfoHeader (info )
137
- header .Name = strings .TrimPrefix (path , nowSrc + `/` )
138
-
141
+ header .Name = strings .TrimPrefix (path , nowSrc + prefix )
139
142
// 判断:文件是不是文件夹
140
143
if info .IsDir () {
141
- header .Name += `/`
144
+ header .Name += prefix
142
145
} else {
143
146
// 设置:zip的文件压缩算法
144
147
header .Method = zip .Deflate
145
148
}
146
-
147
149
// 创建:压缩包头部信息
148
150
writer , _ := archive .CreateHeader (header )
149
151
if ! info .IsDir () {
0 commit comments