From b2663bd3e8b95dc792ee344f04eb97efdf91c305 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 22 Jan 2020 13:59:37 +0100 Subject: [PATCH] backup - let discardAllBackups() delete backup folder for workspace again --- .../services/backup/common/backupFileService.ts | 11 ++++++++++- .../test/electron-browser/backupFileService.test.ts | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/services/backup/common/backupFileService.ts b/src/vs/workbench/services/backup/common/backupFileService.ts index 07295be077e..d4c3416bfc8 100644 --- a/src/vs/workbench/services/backup/common/backupFileService.ts +++ b/src/vs/workbench/services/backup/common/backupFileService.ts @@ -278,9 +278,18 @@ class BackupFileServiceImpl extends Disposable implements IBackupFileService { } async discardAllBackups(): Promise { - const model = await this.ready; + // Discard each backup and clear model + // We go through the doDiscardBackup() + // method to benefit from the IO queue + const model = await this.ready; await Promise.all(model.get().map(backupResource => this.doDiscardBackup(backupResource))); + model.clear(); + + // Delete the backup home for this workspace + // It will automatically be populated again + // once another backup is made + await this.deleteIgnoreFileNotFound(this.backupWorkspacePath); } private async deleteIgnoreFileNotFound(resource: URI): Promise { diff --git a/src/vs/workbench/services/backup/test/electron-browser/backupFileService.test.ts b/src/vs/workbench/services/backup/test/electron-browser/backupFileService.test.ts index 00d91673e3b..e3e58acf7d9 100644 --- a/src/vs/workbench/services/backup/test/electron-browser/backupFileService.test.ts +++ b/src/vs/workbench/services/backup/test/electron-browser/backupFileService.test.ts @@ -292,6 +292,7 @@ suite('BackupFileService', () => { await service.discardAllBackups(); assert.equal(fs.existsSync(fooBackupPath), false); assert.equal(fs.existsSync(barBackupPath), false); + assert.equal(fs.existsSync(path.join(workspaceBackupPath, 'file')), false); }); test('untitled file', async () => { @@ -299,6 +300,7 @@ suite('BackupFileService', () => { assert.equal(fs.readdirSync(path.join(workspaceBackupPath, 'untitled')).length, 1); await service.discardAllBackups(); assert.equal(fs.existsSync(untitledBackupPath), false); + assert.equal(fs.existsSync(path.join(workspaceBackupPath, 'untitled')), false); }); });