From 6aec1e72bd5c223833f5a501459fb3cfa5642a14 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 2 Dec 2016 15:49:51 -0800 Subject: [PATCH] Merge remove workspace funcs to removeBackupPathSync --- .../backup/electron-main/backupMainService.ts | 31 +++++-------------- .../electron-main/backupMainService.test.ts | 16 +++++----- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/src/vs/platform/backup/electron-main/backupMainService.ts b/src/vs/platform/backup/electron-main/backupMainService.ts index e3b6684d43e..e78fbfb7eeb 100644 --- a/src/vs/platform/backup/electron-main/backupMainService.ts +++ b/src/vs/platform/backup/electron-main/backupMainService.ts @@ -71,28 +71,16 @@ export class BackupMainService implements IBackupMainService { } } - protected removeWorkspaceBackupPathSync(workspace: Uri): void { - if (!this.backups.folderWorkspaces) { - return; - } - const index = this.backups.folderWorkspaces.indexOf(workspace.fsPath); - if (index === -1) { - return; - } - this.backups.folderWorkspaces.splice(index, 1); - this.saveSync(); - } - - // TODO: Test - private removeEmptyWorkspaceBackupFolder(backupFolder: string): void { - if (!this.backups.emptyWorkspaces) { + protected removeBackupPathSync(workspaceIdentifier: string, isEmptyWorkspace: boolean): void { + const array = isEmptyWorkspace ? this.backups.emptyWorkspaces : this.backups.folderWorkspaces; + if (!array) { return; } - const index = this.backups.emptyWorkspaces.indexOf(backupFolder); + const index = array.indexOf(workspaceIdentifier); if (index === -1) { return; } - this.backups.emptyWorkspaces.splice(index, 1); + array.splice(index, 1); this.saveSync(); } @@ -135,10 +123,9 @@ export class BackupMainService implements IBackupMainService { backups.folderWorkspaces.forEach(workspacePath => { const backupPath = path.join(this.backupHome, this.getWorkspaceHash(workspacePath)); - console.log('this.hasBackupsSync(backupPath) for ' + workspacePath + ' : ' + this.hasBackupsSync(backupPath)); if (!this.hasBackupsSync(backupPath)) { const backupWorkspace = this.sanitizePath(workspacePath); - staleBackupWorkspaces.push({ workspaceIdentifier: backupWorkspace, backupPath, isEmptyWorkspace: false }); + staleBackupWorkspaces.push({ workspaceIdentifier: Uri.file(backupWorkspace).fsPath, backupPath, isEmptyWorkspace: false }); } }); @@ -152,11 +139,7 @@ export class BackupMainService implements IBackupMainService { staleBackupWorkspaces.forEach(staleBackupWorkspace => { const {backupPath, workspaceIdentifier, isEmptyWorkspace} = staleBackupWorkspace; extfs.delSync(backupPath); - if (isEmptyWorkspace) { - this.removeEmptyWorkspaceBackupFolder(workspaceIdentifier); - } else { - this.removeWorkspaceBackupPathSync(Uri.file(workspaceIdentifier)); - } + this.removeBackupPathSync(workspaceIdentifier, isEmptyWorkspace); }); } 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 419c37aedb2..a17ad7761f1 100644 --- a/src/vs/platform/backup/test/electron-main/backupMainService.test.ts +++ b/src/vs/platform/backup/test/electron-main/backupMainService.test.ts @@ -28,8 +28,8 @@ class TestBackupMainService extends BackupMainService { this.loadSync(); } - public removeWorkspaceBackupPathSync(workspace: Uri): void { - return super.removeWorkspaceBackupPathSync(workspace); + public removeBackupPathSync(workspaceIdenfitier: string, isEmptyWorkspace: boolean): void { + return super.removeBackupPathSync(workspaceIdenfitier, isEmptyWorkspace); } public loadSync(): void { @@ -204,15 +204,15 @@ suite('BackupMainService', () => { }); }); - suite('removeWorkspaceBackupPathSync', () => { - test('removeWorkspaceBackupPathSync should remove workspaces from workspaces.json', done => { + suite('removeBackupPathSync', () => { + test('should remove workspaces from workspaces.json', done => { service.registerWindowForBackups(1, false, null, fooFile.fsPath); service.registerWindowForBackups(2, false, null, barFile.fsPath); - service.removeWorkspaceBackupPathSync(fooFile); + service.removeBackupPathSync(fooFile.fsPath, false); pfs.readFile(backupWorkspacesPath, 'utf-8').then(buffer => { const json = JSON.parse(buffer); assert.deepEqual(json.folderWorkspaces, [barFile.fsPath]); - service.removeWorkspaceBackupPathSync(barFile); + service.removeBackupPathSync(barFile.fsPath, false); pfs.readFile(backupWorkspacesPath, 'utf-8').then(content => { const json2 = JSON.parse(content); assert.deepEqual(json2.folderWorkspaces, []); @@ -221,10 +221,10 @@ suite('BackupMainService', () => { }); }); - test('removeWorkspaceBackupPathSync should fail gracefully when removing a path that doesn\'t exist', done => { + test('should fail gracefully when removing a path that doesn\'t exist', done => { const workspacesJson: IBackupWorkspacesFormat = { folderWorkspaces: [fooFile.fsPath], emptyWorkspaces: [] }; pfs.writeFile(backupWorkspacesPath, JSON.stringify(workspacesJson)).then(() => { - service.removeWorkspaceBackupPathSync(barFile); + service.removeBackupPathSync(barFile.fsPath, false); pfs.readFile(backupWorkspacesPath, 'utf-8').then(content => { const json = JSON.parse(content); assert.deepEqual(json.folderWorkspaces, [fooFile.fsPath]); -- GitLab