diff --git a/src/vs/test/utils/servicesTestUtils.ts b/src/vs/test/utils/servicesTestUtils.ts index 1d4ff6c1ab927c69d21869c0cc0ce8ba5998fb86..836d2f9f02bc7d0a0b7addb00f817b723f37ff10 100644 --- a/src/vs/test/utils/servicesTestUtils.ts +++ b/src/vs/test/utils/servicesTestUtils.ts @@ -677,11 +677,7 @@ export class TestBackupFileService implements IBackupFileService { return TPromise.as(void 0); } - public getWorkspaceTextFileBackups(): TPromise { - return TPromise.as([]); - } - - public getWorkspaceUntitledFileBackups(): TPromise { + public getWorkspaceFileBackups(scheme: string): TPromise { return TPromise.as([]); } diff --git a/src/vs/workbench/services/backup/common/backup.ts b/src/vs/workbench/services/backup/common/backup.ts index e1769a7cd243472f2165e42b7b07a8fce0e1293c..c141966a4007f79ca0f01102dc0a37afd485cc4d 100644 --- a/src/vs/workbench/services/backup/common/backup.ts +++ b/src/vs/workbench/services/backup/common/backup.ts @@ -57,18 +57,12 @@ export interface IBackupFileService { backupResource(resource: Uri, content: string, versionId?: number): TPromise; /** - * Gets a list of text file backups for the current workspace. + * Gets a list of file backups for the current workspace. * + * @param scheme The scheme of the backup. * @return The list of backups. */ - getWorkspaceTextFileBackups(): TPromise; - - /** - * Gets a list of untitled backups for the current workspace. - * - * @return The list of backups. - */ - getWorkspaceUntitledFileBackups(): TPromise; + getWorkspaceFileBackups(scheme: string): TPromise; /** * Parses backup raw text content into the content, removing the metadata that is also stored diff --git a/src/vs/workbench/services/backup/node/backupFileService.ts b/src/vs/workbench/services/backup/node/backupFileService.ts index 17b797ffd9953282895890ec1eb254fd0a3d38bf..5a53754d599df05b5d1211440f00303358782fb1 100644 --- a/src/vs/workbench/services/backup/node/backupFileService.ts +++ b/src/vs/workbench/services/backup/node/backupFileService.ts @@ -182,10 +182,10 @@ export class BackupFileService implements IBackupFileService { }); } - public getWorkspaceTextFileBackups(): TPromise { + public getWorkspaceFileBackups(scheme: string): TPromise { return this.ready.then(model => { let readPromises: TPromise[] = []; - model.getFilesByScheme('file').forEach(textFile => { + model.getFilesByScheme(scheme).forEach(textFile => { readPromises.push(new TPromise((c, e) => { readToMatchingString(textFile.fsPath, '\n', 2000, 10000, (error, result) => { if (result === null) { @@ -199,12 +199,6 @@ export class BackupFileService implements IBackupFileService { }); } - public getWorkspaceUntitledFileBackups(): TPromise { - return this.ready.then(model => { - return model.getFilesByScheme('untitled'); - }); - } - public parseBackupContent(rawText: IRawTextContent): string { return rawText.value.lines.slice(1).join('\n'); } @@ -214,8 +208,7 @@ export class BackupFileService implements IBackupFileService { return null; } - // Only hash the file path if the file is not untitled - const backupName = resource.scheme === 'untitled' ? resource.fsPath : crypto.createHash('md5').update(resource.fsPath).digest('hex'); + const backupName = crypto.createHash('md5').update(resource.fsPath).digest('hex'); const backupPath = path.join(this.backupWorkspacePath, resource.scheme, backupName); return Uri.file(backupPath); diff --git a/src/vs/workbench/services/backup/test/backupFileService.test.ts b/src/vs/workbench/services/backup/test/backupFileService.test.ts index 16b3b6d4a06d01add69b39efc9148093fcad86a0..cece47a0955689b8dc3938e065da3a4354af8579 100644 --- a/src/vs/workbench/services/backup/test/backupFileService.test.ts +++ b/src/vs/workbench/services/backup/test/backupFileService.test.ts @@ -57,7 +57,7 @@ suite('BackupFileService', () => { 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', untitledFile.fsPath); + const untitledBackupPath = path.join(workspaceBackupPath, 'untitled', crypto.createHash('md5').update(untitledFile.fsPath).digest('hex')); let service: TestBackupFileService; @@ -91,7 +91,8 @@ suite('BackupFileService', () => { // Format should be: /// const backupResource = Uri.from({ scheme: 'untitled', path: 'Untitled-1' }); const workspaceHash = crypto.createHash('md5').update(workspaceResource.fsPath).digest('hex'); - const expectedPath = Uri.file(path.join(backupHome, workspaceHash, 'untitled', backupResource.fsPath)).fsPath; + 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); }); @@ -172,12 +173,12 @@ suite('BackupFileService', () => { }); }); - test('getWorkspaceTextFileBackups - text file', done => { + test('getWorkspaceFileBackups("file") - text file', done => { service.backupResource(fooFile, `test`).then(() => { - service.getWorkspaceTextFileBackups().then(textFiles => { + service.getWorkspaceFileBackups('file').then(textFiles => { assert.deepEqual(textFiles.map(f => f.fsPath), [fooFile.fsPath]); service.backupResource(barFile, `test`).then(() => { - service.getWorkspaceTextFileBackups().then(textFiles => { + service.getWorkspaceFileBackups('file').then(textFiles => { assert.deepEqual(textFiles.map(f => f.fsPath), [fooFile.fsPath, barFile.fsPath]); done(); }); @@ -186,19 +187,19 @@ suite('BackupFileService', () => { }); }); - test('getWorkspaceTextFileBackups - untitled file', done => { + test('getWorkspaceFileBackups("file") - untitled file', done => { service.backupResource(untitledFile, `test`).then(() => { - service.getWorkspaceTextFileBackups().then(textFiles => { + service.getWorkspaceFileBackups('file').then(textFiles => { assert.deepEqual(textFiles, []); done(); }); }); }); - test('getWorkspaceUntitledFileBackups - text file', done => { + test('getWorkspaceFileBackups("untitled") - text file', done => { service.backupResource(fooFile, `test`).then(() => { service.backupResource(barFile, `test`).then(() => { - service.getWorkspaceUntitledFileBackups().then(textFiles => { + service.getWorkspaceFileBackups('untitled').then(textFiles => { assert.deepEqual(textFiles, []); done(); }); @@ -206,10 +207,10 @@ suite('BackupFileService', () => { }); }); - test('getWorkspaceUntitledFileBackups - untitled file', done => { + test('getWorkspaceFileBackups("untitled") - untitled file', done => { service.backupResource(untitledFile, `test`).then(() => { - service.getWorkspaceUntitledFileBackups().then(textFiles => { - assert.deepEqual(textFiles.map(f => f.fsPath), [untitledBackupPath]); + service.getWorkspaceFileBackups('untitled').then(textFiles => { + assert.deepEqual(textFiles.map(f => f.fsPath), ['Untitled-1']); done(); }); });