diff --git a/src/vs/platform/backup/test/electron-main/backupMainService.test.ts b/src/vs/platform/backup/test/electron-main/backupMainService.test.ts index 390711d12d3fea3543a8ca21f61c6635fcf6b42e..2bcd927d2f081d1df939a5adfd582df9ee88517a 100644 --- a/src/vs/platform/backup/test/electron-main/backupMainService.test.ts +++ b/src/vs/platform/backup/test/electron-main/backupMainService.test.ts @@ -160,4 +160,19 @@ suite('BackupMainService', () => { done(); }); + + test('toBackupPath ignores case on Windows and Mac', () => { + // Skip test on Linux + if (platform.isLinux) { + return; + } + + if (platform.isMacintosh) { + assert.equal(service.toBackupPath('/foo'), service.toBackupPath('/FOO')); + } + + if (platform.isWindows) { + assert.equal(service.toBackupPath('c:\\foo'), service.toBackupPath('C:\\FOO')); + } + }); }); \ No newline at end of file diff --git a/src/vs/workbench/services/backup/node/backupFileService.ts b/src/vs/workbench/services/backup/node/backupFileService.ts index ab01d62c614df674e9d41d10e06f31add54ee929..3357fcf43e07c1a2b56870bba89fb11114a25b0d 100644 --- a/src/vs/workbench/services/backup/node/backupFileService.ts +++ b/src/vs/workbench/services/backup/node/backupFileService.ts @@ -101,8 +101,7 @@ export class BackupFileService implements IBackupFileService { this.workspacesJsonPath = environmentService.backupWorkspacesPath; if (this.currentWorkspace) { - const workspaceHash = crypto.createHash('md5').update(this.currentWorkspace.fsPath).digest('hex'); - this.backupWorkspacePath = path.join(this.backupHome, workspaceHash); + this.backupWorkspacePath = path.join(this.backupHome, this.hashPath(this.currentWorkspace)); } this.ready = this.init(); @@ -213,12 +212,13 @@ export class BackupFileService implements IBackupFileService { return null; } - // Windows and Mac paths are case insensitive, we want backups to be too - const pathCaseFix = platform.isWindows || platform.isMacintosh ? resource.fsPath.toLowerCase() : resource.fsPath; + return Uri.file(path.join(this.backupWorkspacePath, resource.scheme, this.hashPath(resource))); + } - const backupName = crypto.createHash('md5').update(pathCaseFix).digest('hex'); - const backupPath = path.join(this.backupWorkspacePath, resource.scheme, backupName); + private hashPath(resource: Uri): string { + // Windows and Mac paths are case insensitive, we want backups to be too + const caseAwarePath = platform.isWindows || platform.isMacintosh ? resource.fsPath.toLowerCase() : resource.fsPath; - return Uri.file(backupPath); + return crypto.createHash('md5').update(caseAwarePath).digest('hex'); } } \ No newline at end of file