Skip to content

Commit 4968e0a

Browse files
author
Benjamin Pasero
committed
1 parent 88e570c commit 4968e0a

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

src/vs/workbench/services/backup/common/backupFileService.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,10 @@ export class BackupFileService implements IBackupFileService {
111111
private impl: IBackupFileService;
112112

113113
constructor(
114-
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService,
115-
@IFileService fileService: IFileService
114+
@IWorkbenchEnvironmentService private environmentService: IWorkbenchEnvironmentService,
115+
@IFileService protected fileService: IFileService
116116
) {
117-
const backupWorkspaceResource = environmentService.configuration.backupWorkspaceResource;
118-
if (backupWorkspaceResource) {
119-
this.impl = new BackupFileServiceImpl(backupWorkspaceResource, this.hashPath, fileService);
120-
} else {
121-
this.impl = new InMemoryBackupFileService(this.hashPath);
122-
}
117+
this.initialize();
123118
}
124119

125120
protected hashPath(resource: URI): string {
@@ -128,9 +123,25 @@ export class BackupFileService implements IBackupFileService {
128123
return hash(str).toString(16);
129124
}
130125

131-
initialize(backupWorkspaceResource: URI): void {
126+
private initialize(): void {
127+
const backupWorkspaceResource = this.environmentService.configuration.backupWorkspaceResource;
128+
if (backupWorkspaceResource) {
129+
this.impl = new BackupFileServiceImpl(backupWorkspaceResource, this.hashPath, this.fileService);
130+
} else {
131+
this.impl = new InMemoryBackupFileService(this.hashPath);
132+
}
133+
}
134+
135+
reinitialize(): void {
136+
137+
// Re-init implementation (unless we are running in-memory)
132138
if (this.impl instanceof BackupFileServiceImpl) {
133-
this.impl.initialize(backupWorkspaceResource);
139+
const backupWorkspaceResource = this.environmentService.configuration.backupWorkspaceResource;
140+
if (backupWorkspaceResource) {
141+
this.impl.initialize(backupWorkspaceResource);
142+
} else {
143+
this.impl = new InMemoryBackupFileService(this.hashPath);
144+
}
134145
}
135146
}
136147

src/vs/workbench/services/workspace/electron-browser/workspaceEditingService.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,15 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
397397

398398
const result = await this.windowService.enterWorkspace(path);
399399
if (result) {
400+
401+
// Migrate storage to new workspace
400402
await this.migrateStorage(result.workspace);
401403

402404
// Reinitialize backup service
405+
this.environmentService.configuration.backupPath = result.backupPath;
406+
this.environmentService.configuration.backupWorkspaceResource = result.backupPath ? toBackupWorkspaceResource(result.backupPath, this.environmentService) : undefined;
403407
if (this.backupFileService instanceof BackupFileService) {
404-
this.backupFileService.initialize(toBackupWorkspaceResource(result.backupPath!, this.environmentService));
408+
this.backupFileService.reinitialize();
405409
}
406410
}
407411

0 commit comments

Comments
 (0)