Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 989ad1d

Browse files
committed
fix: fix mount bugs
1 parent f1acb8f commit 989ad1d

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/util/common.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ import (
3838
"time"
3939
)
4040

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+
)
4246

4347
var versionMap = map[string]string{
4448
"12.5": "12.4",
@@ -88,8 +92,6 @@ func GetDeviceByUdId(udId string) (device giDevice.Device) {
8892
return
8993
}
9094

91-
const RemoteInfoFilePath = ".sib/connect.txt"
92-
9395
func ReadRemote() (remoteDevList map[string]giDevice.Device, err error) {
9496
defer func() {
9597

@@ -157,13 +159,14 @@ func downloadZip(url, version string) (string, error) {
157159
if versionMap[version] != "" {
158160
vm = versionMap[version]
159161
}
160-
f, err := os.Stat(".sib")
162+
f, err := os.Stat(baseDir)
161163
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)
164166
}
165167
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)
167170
if errT != nil {
168171
client := http.Client{
169172
Timeout: DownLoadTimeOut,
@@ -174,11 +177,11 @@ func downloadZip(url, version string) (string, error) {
174177
}
175178
defer res.Body.Close()
176179
r := bufio.NewReaderSize(res.Body, 32*1024)
177-
newFile, err := os.Create(fmt.Sprintf(".sib/%s.zip", version))
180+
newFile, err := os.Create(filePath)
178181
w := bufio.NewWriter(newFile)
179182
io.Copy(w, r)
180183
abs, _ := filepath.Abs(newFile.Name())
181-
errZip := unzip(abs, ".sib", version)
184+
errZip := unzip(abs, baseDir, version)
182185
if errZip != nil {
183186
os.Remove(newFile.Name())
184187
return "", errZip
@@ -199,7 +202,7 @@ func unzip(zipFile, destDir, version string) error {
199202
if strings.HasPrefix(f.Name, version) && f.FileInfo().IsDir() {
200203
fpath = filepath.Join(destDir, version)
201204
} else {
202-
fpath = filepath.Join(destDir, version+"/"+path.Base(f.Name))
205+
fpath = filepath.Join(destDir, version+string(filepath.Separator)+path.Base(f.Name))
203206
}
204207
if f.FileInfo().IsDir() {
205208
os.MkdirAll(fpath, os.ModePerm)

0 commit comments

Comments
 (0)