From 9e484995b2dafd6fff9381d1294f97be3b529e3a Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Wed, 21 Sep 2016 03:09:22 -0700 Subject: [PATCH] Discard backups on exit --- src/vs/platform/files/common/files.ts | 10 +++++++++- src/vs/workbench/parts/files/common/textFileService.ts | 7 ++++++- .../services/files/electron-browser/fileService.ts | 5 ++++- src/vs/workbench/services/files/node/fileService.ts | 5 +++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/vs/platform/files/common/files.ts b/src/vs/platform/files/common/files.ts index 3c5fccdce77..425c8759ea1 100644 --- a/src/vs/platform/files/common/files.ts +++ b/src/vs/platform/files/common/files.ts @@ -104,9 +104,17 @@ export interface IFileService { */ del(resource: URI, useTrash?: boolean): TPromise; - // TODO: doc + /** + * Backs up the provided file to a temporary directory to be used by the hot + * exit feature and crash recovery. + */ backupFile(resource: URI, content: string): TPromise; + /** + * Discards all backups associated with this session. + */ + discardBackups(): TPromise; + /** * Imports the file to the parent identified by the resource. */ diff --git a/src/vs/workbench/parts/files/common/textFileService.ts b/src/vs/workbench/parts/files/common/textFileService.ts index d41dae47108..fc663c97eb3 100644 --- a/src/vs/workbench/parts/files/common/textFileService.ts +++ b/src/vs/workbench/parts/files/common/textFileService.ts @@ -119,7 +119,8 @@ export abstract class TextFileService implements ITextFileService { if (this.getDirty().length) { // If hot exit is enabled then save the dirty files in the workspace and then exit if (this.configuredHotExit) { - // TODO: Do last minute backup if needed + // TODO: Do a last minute backup if required + // TODO: If this is the only instance opened, perform hot exit } // If auto save is enabled, save all files and then check again for dirty files @@ -129,6 +130,7 @@ export abstract class TextFileService implements ITextFileService { return this.confirmBeforeShutdown(); // we still have dirty files around, so confirm normally } + this.fileService.discardBackups(); return false; // all good, no veto }); } @@ -137,6 +139,7 @@ export abstract class TextFileService implements ITextFileService { return this.confirmBeforeShutdown(); } + this.fileService.discardBackups(); return false; // no veto } @@ -150,12 +153,14 @@ export abstract class TextFileService implements ITextFileService { return true; // veto if some saves failed } + this.fileService.discardBackups(); return false; // no veto }); } // Don't Save else if (confirm === ConfirmResult.DONT_SAVE) { + this.fileService.discardBackups(); return false; // no veto } diff --git a/src/vs/workbench/services/files/electron-browser/fileService.ts b/src/vs/workbench/services/files/electron-browser/fileService.ts index c37132a54d7..50fb8bc05d9 100644 --- a/src/vs/workbench/services/files/electron-browser/fileService.ts +++ b/src/vs/workbench/services/files/electron-browser/fileService.ts @@ -233,10 +233,13 @@ export class FileService implements IFileService { } public backupFile(resource: uri, content: string): TPromise { - // TODO: Use this.environmentService.userDataPath as backup path return this.raw.backupFile(resource, content); } + public discardBackups(): TPromise { + return this.raw.discardBackups(); + } + private doMoveItemToTrash(resource: uri): TPromise { const workspace = this.contextService.getWorkspace(); if (!workspace) { diff --git a/src/vs/workbench/services/files/node/fileService.ts b/src/vs/workbench/services/files/node/fileService.ts index 8160b33dec8..f7d45003d13 100644 --- a/src/vs/workbench/services/files/node/fileService.ts +++ b/src/vs/workbench/services/files/node/fileService.ts @@ -441,9 +441,14 @@ export class FileService implements IFileService { var backupPath = paths.join(this.environmentService.userDataPath, 'File Backups', FileService.SESSION_BACKUP_ID, backupName); let backupResource = uri.file(backupPath); + console.log(`Backing up to ${backupResource.fsPath}`); return this.updateContent(backupResource, content); } + public discardBackups(): TPromise { + return this.del(uri.file(paths.join(this.environmentService.userDataPath, 'File Backups', FileService.SESSION_BACKUP_ID))); + } + // Helpers private toAbsolutePath(arg1: uri | IFileStat): string { -- GitLab