Skip to content

Commit 743dc97

Browse files
committed
fix: normalize path separators for cross-platform compatibility
- Ensure consistent cache keys across Windows and Unix systems - Replace backslashes with forward slashes in relative paths
1 parent a9b70e4 commit 743dc97

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/services/code-index/__tests__/cache-manager.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ describe("CacheManager", () => {
8080
relativePath = path.relative(homedir, mockWorkspacePath)
8181
}
8282

83-
const compositeKey = `${workspaceName}::${relativePath}`
83+
// Normalize path separators for consistency
84+
const normalizedRelativePath = relativePath.replace(/\\/g, "/")
85+
const compositeKey = `${workspaceName}::${normalizedRelativePath}`
8486
const expectedHash = createHash("sha256").update(compositeKey).digest("hex")
8587

8688
expect(vscode.Uri.joinPath).toHaveBeenCalledWith(

src/services/code-index/cache-manager.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ export class CacheManager implements ICacheManager {
5656
console.warn("Failed to get relative path from home directory:", error)
5757
}
5858

59-
// Create a composite key using workspace name and relative path
59+
// Normalize path separators to forward slashes for consistency across platforms
60+
// This ensures the same cache key is generated regardless of the OS
61+
const normalizedRelativePath = relativePath.replace(/\\/g, "/")
62+
63+
// Create a composite key using workspace name and normalized relative path
6064
// This should be more stable across SSH sessions where the absolute path might change
6165
// but the relative structure remains the same
62-
const compositeKey = `${workspaceName}::${relativePath}`
66+
const compositeKey = `${workspaceName}::${normalizedRelativePath}`
6367

6468
// Generate hash from the composite key
6569
return createHash("sha256").update(compositeKey).digest("hex")

0 commit comments

Comments
 (0)