Skip to content

Commit 2afdef4

Browse files
Update remote-debugger.go
1 parent 6c3e340 commit 2afdef4

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

luna_utils/remote-debugger.go

+31-5
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import (
55
"github.com/musiclover789/luna/log"
66
"github.com/musiclover789/luna/reverse_proxy"
77
"log"
8+
"math/rand"
89
"net"
910
"net/url"
1011
"os"
1112
"os/exec"
1213
"path/filepath"
1314
"strconv"
1415
"strings"
16+
"sync"
1517
"time"
1618
)
1719

@@ -102,15 +104,39 @@ var StartChromiumWithUserDataDir = func(chromiumPath, userDataDirFullPath string
102104
return port, proxyServer
103105
}
104106

107+
var mutex sync.Mutex
105108
var CreateCacheDirInSubDir = func(basePath string) string {
106-
// 组装完整的随机文件夹路径
107-
randFolderName := fmt.Sprintf("chromium_user_data_%d", time.Now().UnixNano())
109+
rand.Seed(time.Now().UnixNano())
110+
111+
// 生成随机字母
112+
letters := make([]rune, 3)
113+
for i := 0; i < 3; i++ {
114+
letters[i] = rune('a' + rand.Intn(26))
115+
}
116+
117+
// 获取当前时间戳的中间 9 到 16 位数字
118+
timestamp := time.Now().UnixNano()
119+
middleDigits := (timestamp / 1e6) % 1e8
120+
121+
randFolderName := fmt.Sprintf("user_%08d%s", middleDigits, string(letters))
122+
123+
// 加锁
124+
mutex.Lock()
125+
defer mutex.Unlock()
126+
108127
cacheDirFullPath := filepath.Join(basePath, randFolderName)
109-
// 创建随机文件夹
110-
if err := os.MkdirAll(cacheDirFullPath, 0700); err != nil {
111-
fmt.Printf("创建缓存目录失败:", err)
128+
129+
// 检查文件夹是否已存在
130+
if _, err := os.Stat(cacheDirFullPath); err == nil {
131+
return cacheDirFullPath
132+
}
133+
134+
if err := os.MkdirAll(cacheDirFullPath, 0777); err != nil {
135+
fmt.Printf("创建缓存目录失败: %v\n", err)
112136
return ""
113137
}
138+
time.Sleep(time.Millisecond * 10)
139+
fmt.Println("当前缓存目录为:", cacheDirFullPath)
114140
return cacheDirFullPath
115141
}
116142

0 commit comments

Comments
 (0)