From 3d2a2e5ecd4867665088edaf3b73e0170d3ee9a2 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Sat, 26 Aug 2017 13:54:29 +0200 Subject: [PATCH] multi root - migrate hot exit to new workspace id --- .../backup/electron-main/backupMainService.ts | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/vs/platform/backup/electron-main/backupMainService.ts b/src/vs/platform/backup/electron-main/backupMainService.ts index 5376e4ea318..c1794d53c3b 100644 --- a/src/vs/platform/backup/electron-main/backupMainService.ts +++ b/src/vs/platform/backup/electron-main/backupMainService.ts @@ -14,7 +14,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment' import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IFilesConfiguration, HotExitConfiguration } from 'vs/platform/files/common/files'; import { ILogService } from 'vs/platform/log/common/log'; -import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, IWorkspacesMainService } from 'vs/platform/workspaces/common/workspaces'; +import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, IWorkspacesMainService, isSingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces'; export class BackupMainService implements IBackupMainService { @@ -149,7 +149,7 @@ export class BackupMainService implements IBackupMainService { } private sanitizeId(workspaceIdentifier: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier): string { - if (typeof workspaceIdentifier === 'string') { + if (isSingleFolderWorkspaceIdentifier(workspaceIdentifier)) { return this.sanitizePath(workspaceIdentifier); } @@ -220,10 +220,26 @@ export class BackupMainService implements IBackupMainService { // Validate Workspace and Folder Backups workspaceAndFolders.forEach(workspaceOrFolder => { const workspaceId = workspaceOrFolder.workspaceIdentifier; - const workspacePath = typeof workspaceId === 'string' ? workspaceId : workspaceId.configPath; - const backupPath = path.join(this.backupHome, typeof workspaceId === 'string' ? this.getFolderHash(workspaceId) : workspaceId.id); + const workspacePath = isSingleFolderWorkspaceIdentifier(workspaceId) ? workspaceId : workspaceId.configPath; + const backupPath = path.join(this.backupHome, isSingleFolderWorkspaceIdentifier(workspaceId) ? this.getFolderHash(workspaceId) : workspaceId.id); const hasBackups = this.hasBackupsSync(backupPath); - const missingWorkspace = hasBackups && (!fs.existsSync(workspacePath) || workspaceId !== this.workspacesService.getWorkspaceId(workspacePath) /* TODO@Ben migration to new workspace id */); + const missingWorkspace = hasBackups && !fs.existsSync(workspacePath); + + // TODO@Ben migration from old workspace ID to new + if (hasBackups && !missingWorkspace && !isSingleFolderWorkspaceIdentifier(workspaceId) && workspaceId.id !== this.workspacesService.getWorkspaceId(workspacePath)) { + staleBackupWorkspaces.push({ workspaceIdentifier: workspaceId, backupPath, target: workspaceOrFolder.target }); + + const identifier = { id: this.workspacesService.getWorkspaceId(workspacePath), configPath: workspacePath } as IWorkspaceIdentifier; + this.pushBackupPathsSync(identifier, this.backups.rootWorkspaces); + const newWorkspaceBackupPath = path.join(this.backupHome, identifier.id); + try { + fs.renameSync(backupPath, newWorkspaceBackupPath); + } catch (ex) { + this.logService.error(`Backup: Could not rename backup folder for legacy workspace: ${ex.toString()}`); + + this.removeBackupPathSync(identifier, this.backups.rootWorkspaces); + } + } // If the workspace/folder has no backups, make sure to delete it // 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 { if (missingWorkspace) { const identifier = this.getRandomEmptyWindowId(); this.pushBackupPathsSync(identifier, this.backups.emptyWorkspaces); - const newEmptyWindowBackupPath = path.join(path.dirname(backupPath), identifier); + const newEmptyWindowBackupPath = path.join(this.backupHome, identifier); try { fs.renameSync(backupPath, newEmptyWindowBackupPath); } catch (ex) { -- GitLab