From a8b054781f9c18165e985de801500f31d87a88a8 Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Fri, 30 Jan 2026 09:17:55 -0500 Subject: [PATCH] fix(sync): prevent duplicate backup folders on Windows On Windows, symlinks often fail so copyFallback() copies directories instead. Previously, subsequent `ccs sync` runs would see the copied folder, fail the isOurSymlink() check, and create a new .backup-{date} folder every time. This fix adds Windows copy detection in installItem() before calling backupItem(). When a valid CCS copy is detected, it refreshes the content instead of backing up. Fixes #409 --- src/utils/claude-symlink-manager.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/utils/claude-symlink-manager.ts b/src/utils/claude-symlink-manager.ts index 4bc2d92f..50233981 100644 --- a/src/utils/claude-symlink-manager.ts +++ b/src/utils/claude-symlink-manager.ts @@ -154,7 +154,23 @@ export class ClaudeSymlinkManager { return true; // Already correct, counts as success } - // Backup existing file/directory + // On Windows, check if it's a valid copy (symlink fallback from previous sync) + // This prevents creating duplicate backups on every sync + if (process.platform === 'win32' && this.isCopiedItem(targetPath, sourcePath, item.type)) { + // Remove existing copy and refresh with latest source content + try { + if (item.type === 'directory') { + fs.rmSync(targetPath, { recursive: true, force: true }); + } else { + fs.unlinkSync(targetPath); + } + } catch { + // If removal fails, proceed to copy which will overwrite + } + return this.copyFallback(sourcePath, targetPath, item, silent); + } + + // Backup existing file/directory (only for non-CCS items) this.backupItem(targetPath, silent); }