Skip to content

Commit

Permalink
multi root - migrate hot exit to new workspace id
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Aug 26, 2017
1 parent d3d1029 commit 3d2a2e5
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/vs/platform/backup/electron-main/backupMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 3d2a2e5

Please sign in to comment.