Skip to content

Commit 3d2a2e5

Browse files
author
Benjamin Pasero
committed
multi root - migrate hot exit to new workspace id
1 parent d3d1029 commit 3d2a2e5

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

src/vs/platform/backup/electron-main/backupMainService.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
1414
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1515
import { IFilesConfiguration, HotExitConfiguration } from 'vs/platform/files/common/files';
1616
import { ILogService } from 'vs/platform/log/common/log';
17-
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, IWorkspacesMainService } from 'vs/platform/workspaces/common/workspaces';
17+
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, IWorkspacesMainService, isSingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
1818

1919
export class BackupMainService implements IBackupMainService {
2020

@@ -149,7 +149,7 @@ export class BackupMainService implements IBackupMainService {
149149
}
150150

151151
private sanitizeId(workspaceIdentifier: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier): string {
152-
if (typeof workspaceIdentifier === 'string') {
152+
if (isSingleFolderWorkspaceIdentifier(workspaceIdentifier)) {
153153
return this.sanitizePath(workspaceIdentifier);
154154
}
155155

@@ -220,10 +220,26 @@ export class BackupMainService implements IBackupMainService {
220220
// Validate Workspace and Folder Backups
221221
workspaceAndFolders.forEach(workspaceOrFolder => {
222222
const workspaceId = workspaceOrFolder.workspaceIdentifier;
223-
const workspacePath = typeof workspaceId === 'string' ? workspaceId : workspaceId.configPath;
224-
const backupPath = path.join(this.backupHome, typeof workspaceId === 'string' ? this.getFolderHash(workspaceId) : workspaceId.id);
223+
const workspacePath = isSingleFolderWorkspaceIdentifier(workspaceId) ? workspaceId : workspaceId.configPath;
224+
const backupPath = path.join(this.backupHome, isSingleFolderWorkspaceIdentifier(workspaceId) ? this.getFolderHash(workspaceId) : workspaceId.id);
225225
const hasBackups = this.hasBackupsSync(backupPath);
226-
const missingWorkspace = hasBackups && (!fs.existsSync(workspacePath) || workspaceId !== this.workspacesService.getWorkspaceId(workspacePath) /* TODO@Ben migration to new workspace id */);
226+
const missingWorkspace = hasBackups && !fs.existsSync(workspacePath);
227+
228+
// TODO@Ben migration from old workspace ID to new
229+
if (hasBackups && !missingWorkspace && !isSingleFolderWorkspaceIdentifier(workspaceId) && workspaceId.id !== this.workspacesService.getWorkspaceId(workspacePath)) {
230+
staleBackupWorkspaces.push({ workspaceIdentifier: workspaceId, backupPath, target: workspaceOrFolder.target });
231+
232+
const identifier = { id: this.workspacesService.getWorkspaceId(workspacePath), configPath: workspacePath } as IWorkspaceIdentifier;
233+
this.pushBackupPathsSync(identifier, this.backups.rootWorkspaces);
234+
const newWorkspaceBackupPath = path.join(this.backupHome, identifier.id);
235+
try {
236+
fs.renameSync(backupPath, newWorkspaceBackupPath);
237+
} catch (ex) {
238+
this.logService.error(`Backup: Could not rename backup folder for legacy workspace: ${ex.toString()}`);
239+
240+
this.removeBackupPathSync(identifier, this.backups.rootWorkspaces);
241+
}
242+
}
227243

228244
// If the workspace/folder has no backups, make sure to delete it
229245
// If the workspace/folder has backups, but the target workspace is missing, convert backups to empty ones
@@ -233,7 +249,7 @@ export class BackupMainService implements IBackupMainService {
233249
if (missingWorkspace) {
234250
const identifier = this.getRandomEmptyWindowId();
235251
this.pushBackupPathsSync(identifier, this.backups.emptyWorkspaces);
236-
const newEmptyWindowBackupPath = path.join(path.dirname(backupPath), identifier);
252+
const newEmptyWindowBackupPath = path.join(this.backupHome, identifier);
237253
try {
238254
fs.renameSync(backupPath, newEmptyWindowBackupPath);
239255
} catch (ex) {

0 commit comments

Comments
 (0)