Private
Public Access
1
0

修复:审查发现的高优先问题(竞态/初始化/碰撞)

- app.go: profileSvc移入App struct,用a.mu保护
- sqlite.go: InitFast加sync.Once防并发双重初始化
- client.go: Manager.Connect加sync.Mutex防竞态泄漏SSH
- service.go: 临时文件用os.CreateTemp防时间戳碰撞
- connection-manager: 密码缺失时不再塞入假WailsTransport
This commit is contained in:
2026-05-04 15:40:04 +08:00
parent 6bee55b96f
commit ee4b1f5ac1
5 changed files with 52 additions and 51 deletions

View File

@@ -22,6 +22,7 @@ type Client struct {
// Manager 全局 SFTP 连接管理器(以 host:port 为 key 的连接池)
type Manager struct {
clients sync.Map // map[string]*Client
mu sync.Mutex
}
var globalManager = &Manager{}
@@ -35,6 +36,9 @@ func GetManager() *Manager {
func (m *Manager) Connect(config *Config) (*Client, error) {
key := fmt.Sprintf("%s:%d", config.Host, config.Port)
m.mu.Lock()
defer m.mu.Unlock()
if existing, ok := m.clients.Load(key); ok {
c := existing.(*Client)
if c.IsHealthy() {

View File

@@ -279,8 +279,12 @@ func (s *Service) DownloadToTemp(connID string, remotePath string) (string, erro
}
tmpDir := os.TempDir()
// 用时间戳+随机数避免同名文件覆盖
localPath := filepath.Join(tmpDir, fmt.Sprintf("udesk-sftp-preview-%d-%s", time.Now().UnixNano(), filepath.Base(remotePath)))
tmpFile, e := os.CreateTemp(tmpDir, "udesk-sftp-*-"+filepath.Base(remotePath))
if e != nil {
return "", fmt.Errorf("创建临时文件失败: %w", e)
}
localPath := tmpFile.Name()
tmpFile.Close()
err = c.WithRetry(func(sc *sftpclient.Client) error {
src, e := sc.Open(remotePath)