Skip to content

Commit

Permalink
backups: stop lowercasing file paths (fixes #16591)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Mar 21, 2017
1 parent fcff9f9 commit 36731c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
6 changes: 1 addition & 5 deletions src/vs/workbench/services/backup/node/backupFileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import * as path from 'path';
import * as crypto from 'crypto';
import pfs = require('vs/base/node/pfs');
import * as platform from 'vs/base/common/platform';
import Uri from 'vs/base/common/uri';
import { Queue } from 'vs/base/common/async';
import { IBackupFileService, BACKUP_FILE_UPDATE_OPTIONS } from 'vs/workbench/services/backup/common/backup';
Expand Down Expand Up @@ -253,9 +252,6 @@ export class BackupFileService implements IBackupFileService {
}

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 crypto.createHash('md5').update(caseAwarePath).digest('hex');
return crypto.createHash('md5').update(resource.fsPath).digest('hex');
}
}
19 changes: 2 additions & 17 deletions src/vs/workbench/services/backup/test/backupFileService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const barFile = Uri.file(platform.isWindows ? 'c:\\bar' : '/bar');
const untitledFile = Uri.from({ scheme: 'untitled', path: 'Untitled-1' });
const fooBackupPath = path.join(workspaceBackupPath, 'file', crypto.createHash('md5').update(fooFile.fsPath).digest('hex'));
const barBackupPath = path.join(workspaceBackupPath, 'file', crypto.createHash('md5').update(barFile.fsPath).digest('hex'));
const untitledBackupPath = path.join(workspaceBackupPath, 'untitled', crypto.createHash('md5').update(platform.isLinux ? untitledFile.fsPath : untitledFile.fsPath.toLowerCase()).digest('hex'));
const untitledBackupPath = path.join(workspaceBackupPath, 'untitled', crypto.createHash('md5').update(untitledFile.fsPath).digest('hex'));

class TestBackupFileService extends BackupFileService {
constructor(workspace: Uri, backupHome: string, workspacesJsonPath: string) {
Expand Down Expand Up @@ -98,25 +98,10 @@ suite('BackupFileService', () => {
// Format should be: <backupHome>/<workspaceHash>/<scheme>/<filePath>
const backupResource = Uri.from({ scheme: 'untitled', path: 'Untitled-1' });
const workspaceHash = crypto.createHash('md5').update(workspaceResource.fsPath).digest('hex');
const filePathHash = crypto.createHash('md5').update(platform.isLinux ? backupResource.fsPath : backupResource.fsPath.toLowerCase()).digest('hex');
const filePathHash = crypto.createHash('md5').update(backupResource.fsPath).digest('hex');
const expectedPath = Uri.file(path.join(backupHome, workspaceHash, 'untitled', filePathHash)).fsPath;
assert.equal(service.getBackupResource(backupResource).fsPath, expectedPath);
});

test('should ignore case on Windows and Mac', () => {
// Skip test on Linux
if (platform.isLinux) {
return;
}

if (platform.isMacintosh) {
assert.equal(service.getBackupResource(Uri.file('/foo')).fsPath, service.getBackupResource(Uri.file('/FOO')).fsPath);
}

if (platform.isWindows) {
assert.equal(service.getBackupResource(Uri.file('c:\\foo')).fsPath, service.getBackupResource(Uri.file('C:\\FOO')).fsPath);
}
});
});

suite('hasBackup', () => {
Expand Down

0 comments on commit 36731c6

Please sign in to comment.