@@ -38,7 +38,11 @@ import (
38
38
"time"
39
39
)
40
40
41
- const DownLoadTimeOut = 30 * time .Second
41
+ const (
42
+ DownLoadTimeOut = 30 * time .Second
43
+ baseDir = ".sib"
44
+ RemoteInfoFilePath = baseDir + string (filepath .Separator ) + "connect.txt"
45
+ )
42
46
43
47
var versionMap = map [string ]string {
44
48
"12.5" : "12.4" ,
@@ -88,8 +92,6 @@ func GetDeviceByUdId(udId string) (device giDevice.Device) {
88
92
return
89
93
}
90
94
91
- const RemoteInfoFilePath = ".sib/connect.txt"
92
-
93
95
func ReadRemote () (remoteDevList map [string ]giDevice.Device , err error ) {
94
96
defer func () {
95
97
@@ -157,13 +159,14 @@ func downloadZip(url, version string) (string, error) {
157
159
if versionMap [version ] != "" {
158
160
vm = versionMap [version ]
159
161
}
160
- f , err := os .Stat (".sib" )
162
+ f , err := os .Stat (baseDir )
161
163
if err != nil {
162
- os .MkdirAll (".sib" , os .ModePerm )
163
- f , err = os .Stat (".sib" )
164
+ os .MkdirAll (baseDir , os .ModePerm )
165
+ f , err = os .Stat (baseDir )
164
166
}
165
167
localAbs , _ := filepath .Abs (f .Name ())
166
- _ , errT := os .Stat (fmt .Sprintf (".sib/%s.zip" , version ))
168
+ filePath := fmt .Sprintf ("%s.zip" , baseDir + string (filepath .Separator )+ version )
169
+ _ , errT := os .Stat (filePath )
167
170
if errT != nil {
168
171
client := http.Client {
169
172
Timeout : DownLoadTimeOut ,
@@ -174,11 +177,11 @@ func downloadZip(url, version string) (string, error) {
174
177
}
175
178
defer res .Body .Close ()
176
179
r := bufio .NewReaderSize (res .Body , 32 * 1024 )
177
- newFile , err := os .Create (fmt . Sprintf ( ".sib/%s.zip" , version ) )
180
+ newFile , err := os .Create (filePath )
178
181
w := bufio .NewWriter (newFile )
179
182
io .Copy (w , r )
180
183
abs , _ := filepath .Abs (newFile .Name ())
181
- errZip := unzip (abs , ".sib" , version )
184
+ errZip := unzip (abs , baseDir , version )
182
185
if errZip != nil {
183
186
os .Remove (newFile .Name ())
184
187
return "" , errZip
@@ -199,7 +202,7 @@ func unzip(zipFile, destDir, version string) error {
199
202
if strings .HasPrefix (f .Name , version ) && f .FileInfo ().IsDir () {
200
203
fpath = filepath .Join (destDir , version )
201
204
} else {
202
- fpath = filepath .Join (destDir , version + "/" + path .Base (f .Name ))
205
+ fpath = filepath .Join (destDir , version + string ( filepath . Separator ) + path .Base (f .Name ))
203
206
}
204
207
if f .FileInfo ().IsDir () {
205
208
os .MkdirAll (fpath , os .ModePerm )
0 commit comments