backup - more tweaks to backup on shutdown

This commit is contained in:
Benjamin Pasero 2020-01-23 08:38:56 +01:00
parent 071a77f223
commit d09537cc8f
2 changed files with 14 additions and 11 deletions

View file

@ -70,20 +70,17 @@ export class NativeBackupTracker extends BackupTracker implements IWorkbenchCont
private async handleDirtyBeforeShutdown(workingCopies: IWorkingCopy[], reason: ShutdownReason): Promise<boolean> {
// Trigger backup if configured
let didBackup: boolean | undefined = undefined;
let backupError: Error | undefined = undefined;
if (this.filesConfigurationService.isHotExitEnabled) {
try {
didBackup = await this.backupBeforeShutdown(workingCopies, reason);
if (await this.backupBeforeShutdown(workingCopies, reason)) {
return this.noVeto({ discardAllBackups: false }); // no veto (backup was successful)
}
} catch (error) {
backupError = error;
}
}
if (didBackup) {
return this.noVeto({ discardAllBackups: false }); // no veto (backup was successful)
}
// we ran a backup but received an error that we show to the user
if (backupError) {
this.showErrorDialog(localize('backupTrackerBackupFailed', "One or many editors that are dirty could not be saved to the backup location."), backupError);
@ -169,7 +166,7 @@ export class NativeBackupTracker extends BackupTracker implements IWorkbenchCont
await this.doSaveAllBeforeShutdown(true /* includeUntitled */, SaveReason.EXPLICIT);
if (this.workingCopyService.hasDirty) {
return true; // veto if any save failed or was canceled
return true; // veto (save failed or was canceled)
}
return this.noVeto({ discardAllBackups: true }); // no veto (dirty saved)
@ -194,10 +191,11 @@ export class NativeBackupTracker extends BackupTracker implements IWorkbenchCont
// First save through the editor service to benefit
// from some extras like switching to untitled dirty
// editors before saving.
await this.editorService.saveAll({ includeUntitled, ...saveOptions });
const result = await this.editorService.saveAll({ includeUntitled, ...saveOptions });
// If we still have dirty working copies, save those directly
if (this.workingCopyService.hasDirty) {
// unless the save was not successful (e.g. cancelled)
if (result) {
await Promise.all(this.workingCopyService.dirtyWorkingCopies.map(async workingCopy => {
if (!includeUntitled && (workingCopy.capabilities & WorkingCopyCapabilities.Untitled)) {
return; // skip untitled unless explicitly included
@ -214,10 +212,11 @@ export class NativeBackupTracker extends BackupTracker implements IWorkbenchCont
const revertOptions = { soft: true };
// First revert through the editor service
await this.editorService.revertAll(revertOptions);
const result = await this.editorService.revertAll(revertOptions);
// If we still have dirty working copies, revert those directly
if (this.workingCopyService.hasDirty) {
// unless the revert operation was not successful (e.g. cancelled)
if (result) {
await Promise.all(this.workingCopyService.dirtyWorkingCopies.map(workingCopy => workingCopy.revert(revertOptions)));
}
}

View file

@ -28,6 +28,10 @@ export interface IBackupFileService {
/**
* Finds out if the provided resource with the given version is backed up.
*
* Note: if the backup service has not been initialized yet, this may return
* the wrong result. Always use `resolve()` if you can do a long running
* operation.
*/
hasBackupSync(resource: URI, versionId?: number): boolean;