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
This commit is contained in:
kaitranntt
2026-01-30 09:17:55 -05:00
parent 63946eb5bc
commit a8b054781f
+17 -1
View File
@@ -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);
}