提交 10aa7095 编写于 作者: D Daniel Imms

Disable hot exit on empty workspaces, fix uncaught exceptions

上级 c280e0ca
...@@ -32,9 +32,17 @@ export class BackupService implements IBackupService { ...@@ -32,9 +32,17 @@ export class BackupService implements IBackupService {
@IWorkspaceContextService contextService?: IWorkspaceContextService @IWorkspaceContextService contextService?: IWorkspaceContextService
) { ) {
// IWorkspaceContextService will not exist on the main process // IWorkspaceContextService will not exist on the main process
if (contextService) { if (!contextService) {
this.workspaceResource = contextService.getWorkspace().resource; return;
} }
// Hot exit is disabled for empty workspaces
const workspace = contextService.getWorkspace();
if (!workspace) {
return;
}
this.workspaceResource = workspace.resource;
} }
public getWorkspaceBackupPaths(): string[] { public getWorkspaceBackupPaths(): string[] {
...@@ -52,6 +60,10 @@ export class BackupService implements IBackupService { ...@@ -52,6 +60,10 @@ export class BackupService implements IBackupService {
public pushWorkspaceBackupPaths(workspaces: string[]): void { public pushWorkspaceBackupPaths(workspaces: string[]): void {
this.load(); this.load();
workspaces.forEach(workspace => { workspaces.forEach(workspace => {
// Hot exit is disabled for empty workspaces
if (!workspace) {
return;
}
if (!this.fileContent.folderWorkspaces[workspace]) { if (!this.fileContent.folderWorkspaces[workspace]) {
this.fileContent.folderWorkspaces[workspace] = []; this.fileContent.folderWorkspaces[workspace] = [];
} }
...@@ -74,6 +86,11 @@ export class BackupService implements IBackupService { ...@@ -74,6 +86,11 @@ export class BackupService implements IBackupService {
} }
public getWorkspaceUntitledFileBackups(workspace: string): string[] { public getWorkspaceUntitledFileBackups(workspace: string): string[] {
// Hot exit is disabled for empty workspaces
if (!this.workspaceResource) {
return;
}
const workspaceHash = crypto.createHash('md5').update(this.workspaceResource.fsPath).digest('hex'); const workspaceHash = crypto.createHash('md5').update(this.workspaceResource.fsPath).digest('hex');
const untitledDir = path.join(this.environmentService.backupHome, workspaceHash, 'untitled'); const untitledDir = path.join(this.environmentService.backupHome, workspaceHash, 'untitled');
try { try {
...@@ -87,6 +104,10 @@ export class BackupService implements IBackupService { ...@@ -87,6 +104,10 @@ export class BackupService implements IBackupService {
} }
public getBackupResource(resource: Uri): Uri { public getBackupResource(resource: Uri): Uri {
// Hot exit is disabled for empty workspaces
if (!this.workspaceResource) {
return;
}
const workspaceHash = crypto.createHash('md5').update(this.workspaceResource.fsPath).digest('hex'); const workspaceHash = crypto.createHash('md5').update(this.workspaceResource.fsPath).digest('hex');
const backupName = crypto.createHash('md5').update(resource.fsPath).digest('hex'); const backupName = crypto.createHash('md5').update(resource.fsPath).digest('hex');
...@@ -96,6 +117,11 @@ export class BackupService implements IBackupService { ...@@ -96,6 +117,11 @@ export class BackupService implements IBackupService {
} }
public registerResourceForBackup(resource: Uri): void { public registerResourceForBackup(resource: Uri): void {
// Hot exit is disabled for empty workspaces
if (!this.workspaceResource) {
return;
}
this.load(); this.load();
if (arrays.contains(this.fileContent.folderWorkspaces[this.workspaceResource.fsPath], resource.fsPath)) { if (arrays.contains(this.fileContent.folderWorkspaces[this.workspaceResource.fsPath], resource.fsPath)) {
return; return;
...@@ -105,6 +131,11 @@ export class BackupService implements IBackupService { ...@@ -105,6 +131,11 @@ export class BackupService implements IBackupService {
} }
public deregisterResourceForBackup(resource: Uri): void { public deregisterResourceForBackup(resource: Uri): void {
// Hot exit is disabled for empty workspaces
if (!this.workspaceResource) {
return;
}
this.load(); this.load();
this.fileContent.folderWorkspaces[this.workspaceResource.fsPath] = this.fileContent.folderWorkspaces[this.workspaceResource.fsPath].filter(value => value !== resource.fsPath); this.fileContent.folderWorkspaces[this.workspaceResource.fsPath] = this.fileContent.folderWorkspaces[this.workspaceResource.fsPath].filter(value => value !== resource.fsPath);
this.save(); this.save();
......
...@@ -172,20 +172,22 @@ export class Workbench implements IPartService { ...@@ -172,20 +172,22 @@ export class Workbench implements IPartService {
serviceCollection serviceCollection
}; };
// Restore any backups if they exist // Restore any backups if they exist for this workspace (empty workspaces are not supported yet)
options.filesToRestore = this.backupService.getWorkspaceTextFilesWithBackups(workspace.resource.fsPath).map(filePath => { if (workspace) {
return { resource: Uri.file(filePath), options: { pinned: true } }; options.filesToRestore = this.backupService.getWorkspaceTextFilesWithBackups(workspace.resource.fsPath).map(filePath => {
}); return { resource: Uri.file(filePath), options: { pinned: true } };
options.untitledFilesToRestore = this.backupService.getWorkspaceUntitledFileBackups(workspace.resource.fsPath).map(untitledFilePath => { });
return { resource: Uri.file(untitledFilePath), options: { pinned: true } }; options.untitledFilesToRestore = this.backupService.getWorkspaceUntitledFileBackups(workspace.resource.fsPath).map(untitledFilePath => {
}); return { resource: Uri.file(untitledFilePath), options: { pinned: true } };
});
}
this.hasFilesToCreateOpenOrDiff = this.hasFilesToCreateOpenOrDiff =
(options.filesToCreate && options.filesToCreate.length > 0) || (options.filesToCreate && options.filesToCreate.length > 0) ||
(options.filesToOpen && options.filesToOpen.length > 0) || (options.filesToOpen && options.filesToOpen.length > 0) ||
(options.filesToDiff && options.filesToDiff.length > 0) || (options.filesToDiff && options.filesToDiff.length > 0) ||
(options.filesToRestore.length > 0) || (options.filesToRestore && options.filesToRestore.length > 0) ||
(options.untitledFilesToRestore.length > 0); (options.untitledFilesToRestore && options.untitledFilesToRestore.length > 0);
this.toDispose = []; this.toDispose = [];
this.toShutdown = []; this.toShutdown = [];
......
...@@ -463,17 +463,36 @@ export class FileService implements IFileService { ...@@ -463,17 +463,36 @@ export class FileService implements IFileService {
this.backupService.registerResourceForBackup(resource); this.backupService.registerResourceForBackup(resource);
} }
const backupResource = this.getBackupPath(resource); const backupResource = this.getBackupPath(resource);
// Hot exit is disabled for empty workspaces
if (!backupResource) {
return TPromise.as(null);
}
console.log(`Backing up to ${backupResource.fsPath}`); console.log(`Backing up to ${backupResource.fsPath}`);
return this.updateContent(backupResource, content); return this.updateContent(backupResource, content);
} }
public discardBackup(resource: uri): TPromise<void> { public discardBackup(resource: uri): TPromise<void> {
this.backupService.deregisterResourceForBackup(resource); this.backupService.deregisterResourceForBackup(resource);
return this.del(this.getBackupPath(resource)); const backupResource = this.getBackupPath(resource);
// Hot exit is disabled for empty workspaces
if (!backupResource) {
return TPromise.as(null);
}
return this.del(backupResource);
} }
public discardBackups(): TPromise<void> { public discardBackups(): TPromise<void> {
return this.del(uri.file(this.getBackupRoot())); // Hot exit is disabled for empty workspaces
const backupRootPath = this.getBackupRootPath();
if (!backupRootPath) {
return TPromise.as(void 0);
}
return this.del(uri.file(backupRootPath));
} }
public isHotExitEnabled(): boolean { public isHotExitEnabled(): boolean {
...@@ -483,13 +502,25 @@ export class FileService implements IFileService { ...@@ -483,13 +502,25 @@ export class FileService implements IFileService {
// Helpers // Helpers
private getBackupPath(resource: uri): uri { private getBackupPath(resource: uri): uri {
// Hot exit is disabled for empty workspaces
const backupRootPath = this.getBackupRootPath();
if (!backupRootPath) {
return null;
}
const backupName = crypto.createHash('md5').update(resource.fsPath).digest('hex'); const backupName = crypto.createHash('md5').update(resource.fsPath).digest('hex');
const backupPath = paths.join(this.getBackupRoot(), resource.scheme, backupName); const backupPath = paths.join(backupRootPath, resource.scheme, backupName);
return uri.file(backupPath); return uri.file(backupPath);
} }
private getBackupRoot(): string { private getBackupRootPath(): string {
let workspaceHash = crypto.createHash('md5').update(this.contextService.getWorkspace().resource.fsPath).digest('hex'); // Hot exit is disabled for empty workspaces
const workspace = this.contextService.getWorkspace();
if (!workspace) {
return null;
}
const workspaceHash = crypto.createHash('md5').update(workspace.resource.fsPath).digest('hex');
return paths.join(this.environmentService.userDataPath, 'Backups', workspaceHash); return paths.join(this.environmentService.userDataPath, 'Backups', workspaceHash);
} }
......
...@@ -231,7 +231,8 @@ export abstract class TextFileService implements ITextFileService { ...@@ -231,7 +231,8 @@ export abstract class TextFileService implements ITextFileService {
this.saveAll().done(null, errors.onUnexpectedError); this.saveAll().done(null, errors.onUnexpectedError);
} }
this.configuredHotExit = configuration && configuration.files && configuration.files.hotExit; // Hot exit is disabled for empty workspaces
this.configuredHotExit = this.contextService.getWorkspace() && configuration && configuration.files && configuration.files.hotExit;
// Check for change in files associations // Check for change in files associations
const filesAssociation = configuration && configuration.files && configuration.files.associations; const filesAssociation = configuration && configuration.files && configuration.files.associations;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册