cc-viewer 1.6.256 → 1.6.259

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  // Workspace Registry - 工作区持久化管理
2
- import { readFileSync, writeFileSync, existsSync, mkdirSync, statSync, readdirSync, openSync, closeSync, renameSync, unlinkSync } from 'node:fs';
2
+ import { readFileSync, writeFileSync, existsSync, mkdirSync, statSync, readdirSync, openSync, closeSync, unlinkSync } from 'node:fs';
3
+ import { renameSyncWithRetry } from './lib/file-api.js';
3
4
  import { join, basename, resolve } from 'node:path';
4
5
  import { randomBytes } from 'node:crypto';
5
6
  import { LOG_DIR } from './findcc.js';
@@ -69,19 +70,9 @@ export function saveWorkspaces(list) {
69
70
  mkdirSync(LOG_DIR, { recursive: true });
70
71
  writeFileSync(tmpFile, JSON.stringify({ workspaces: list }, null, 2));
71
72
 
72
- // Windows 上 renameSync 可能会因为目标文件存在或被占用而失败
73
- // 简单的重试机制
74
- let retries = 3;
75
- while (retries > 0) {
76
- try {
77
- renameSync(tmpFile, getWorkspacesFile());
78
- break;
79
- } catch (err) {
80
- if (retries === 1) throw err;
81
- retries--;
82
- sleep(20);
83
- }
84
- }
73
+ // Windows 上 renameSync 可能会因为目标文件存在或被占用而失败。统一走 lib/file-api.js
74
+ // renameSyncWithRetry helper(同款重试策略,跟 interceptor / log-management 一致)。
75
+ renameSyncWithRetry(tmpFile, getWorkspacesFile());
85
76
  } catch (err) {
86
77
  console.error('[CC Viewer] Failed to save workspaces:', err.message);
87
78
  // 尝试清理临时文件
@@ -101,7 +92,10 @@ export function registerWorkspace(absolutePath) {
101
92
  const resolvedPath = resolve(absolutePath);
102
93
  const projectName = basename(resolvedPath).replace(/[^a-zA-Z0-9_\-\.]/g, '_');
103
94
  const list = loadWorkspaces();
104
- const existing = list.find(w => w.path === resolvedPath);
95
+ // Windows NTFS 不分大小写——`C:\App` `c:\app` 是同目录但 `===` 视为不同。
96
+ // 仅 Win 下小写化比较;POSIX 保持原样不引入回归。
97
+ const pathEq = (a, b) => process.platform === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b;
98
+ const existing = list.find(w => pathEq(w.path, resolvedPath));
105
99
  if (existing) {
106
100
  existing.lastUsed = new Date().toISOString();
107
101
  existing.projectName = projectName;