backup - let discardAllBackups() delete backup folder for workspace again

This commit is contained in:
Benjamin Pasero
2020-01-22 13:59:37 +01:00
parent c3a5ac0820
commit b2663bd3e8
2 changed files with 12 additions and 1 deletions
@@ -278,9 +278,18 @@ class BackupFileServiceImpl extends Disposable implements IBackupFileService {
}
async discardAllBackups(): Promise<void> {
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<void> {
@@ -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);
});
});