提交 4fe260c6 编写于 作者: B Benjamin Pasero

💄

上级 ab9f0b74
...@@ -30,39 +30,47 @@ export class BackupFileService implements IBackupFileService { ...@@ -30,39 +30,47 @@ export class BackupFileService implements IBackupFileService {
this.workspacesJsonPath = environmentService.backupWorkspacesPath; this.workspacesJsonPath = environmentService.backupWorkspacesPath;
} }
private get backupEnabled(): boolean {
return this.currentWorkspace && !this.environmentService.isExtensionDevelopment; // Hot exit is disabled for empty workspaces and when doing extension development
}
public hasBackup(resource: Uri): TPromise<boolean> { public hasBackup(resource: Uri): TPromise<boolean> {
const backupResource = this.getBackupResource(resource); const backupResource = this.getBackupResource(resource);
if (!backupResource) { if (!backupResource) {
return TPromise.as(false); return TPromise.as(false);
} }
return pfs.exists(backupResource.fsPath); return pfs.exists(backupResource.fsPath);
} }
public getBackupResource(resource: Uri): Uri { private getBackupHash(resource: Uri): string {
// Hot exit is disabled for empty workspaces if (!this.backupEnabled) {
if (!this.currentWorkspace || this.environmentService.isExtensionDevelopment) {
return null; return null;
} }
// Only hash the file path if the file is not untitled // Only hash the file path if the file is not untitled
const backupName = resource.scheme === 'untitled' ? resource.fsPath : crypto.createHash('md5').update(resource.fsPath).digest('hex'); return resource.scheme === 'untitled' ? resource.fsPath : crypto.createHash('md5').update(resource.fsPath).digest('hex');
const backupPath = path.join(this.getWorkspaceBackupDirectory(), resource.scheme, backupName); }
public getBackupResource(resource: Uri): Uri {
const backupHash = this.getBackupHash(resource);
if (!backupHash) {
return null;
}
const backupPath = path.join(this.getWorkspaceBackupDirectory(), resource.scheme, backupHash);
return Uri.file(backupPath); return Uri.file(backupPath);
} }
private getWorkspaceBackupDirectory(): string { private getWorkspaceBackupDirectory(): string {
const workspaceHash = crypto.createHash('md5').update(this.currentWorkspace.fsPath).digest('hex'); const workspaceHash = crypto.createHash('md5').update(this.currentWorkspace.fsPath).digest('hex');
return path.join(this.backupHome, workspaceHash); return path.join(this.backupHome, workspaceHash);
} }
public backupResource(resource: Uri, content: string): TPromise<void> { public backupResource(resource: Uri, content: string): TPromise<void> {
if (this.environmentService.isExtensionDevelopment) {
return TPromise.as(void 0);
}
const backupResource = this.getBackupResource(resource); const backupResource = this.getBackupResource(resource);
// Hot exit is disabled for empty workspaces
if (!backupResource) { if (!backupResource) {
return TPromise.as(void 0); return TPromise.as(void 0);
} }
...@@ -71,13 +79,7 @@ export class BackupFileService implements IBackupFileService { ...@@ -71,13 +79,7 @@ export class BackupFileService implements IBackupFileService {
} }
public discardResourceBackup(resource: Uri): TPromise<void> { public discardResourceBackup(resource: Uri): TPromise<void> {
if (this.environmentService.isExtensionDevelopment) {
return TPromise.as(void 0);
}
const backupResource = this.getBackupResource(resource); const backupResource = this.getBackupResource(resource);
// Hot exit is disabled for empty workspaces
if (!backupResource) { if (!backupResource) {
return TPromise.as(void 0); return TPromise.as(void 0);
} }
...@@ -86,7 +88,7 @@ export class BackupFileService implements IBackupFileService { ...@@ -86,7 +88,7 @@ export class BackupFileService implements IBackupFileService {
} }
public discardAllWorkspaceBackups(): TPromise<void> { public discardAllWorkspaceBackups(): TPromise<void> {
if (this.environmentService.isExtensionDevelopment) { if (!this.backupEnabled) {
return TPromise.as(void 0); return TPromise.as(void 0);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册