Refresh master with initial release/0.24 snapshot (#332)

* Initial port of release/0.24 source code

* Fix additional headers

* Fix a typo in launch.json
This commit is contained in:
Karl Burtram
2017-12-15 15:38:57 -08:00
committed by GitHub
parent 271b3a0b82
commit 6ad0df0e3e
7118 changed files with 107999 additions and 56466 deletions

View File

@@ -88,14 +88,19 @@ export class BackupMainService implements IBackupMainService {
}
private moveBackupFolderSync(backupPath: string, moveFromPath: string): void {
if (!fs.existsSync(moveFromPath)) {
return;
// Target exists: make sure to convert existing backups to empty window backups
if (fs.existsSync(backupPath)) {
this.convertToEmptyWindowBackup(backupPath);
}
try {
fs.renameSync(moveFromPath, backupPath);
} catch (ex) {
this.logService.error(`Backup: Could not move backup folder to new location: ${ex.toString()}`);
// When we have data to migrate from, move it over to the target location
if (fs.existsSync(moveFromPath)) {
try {
fs.renameSync(moveFromPath, backupPath);
} catch (ex) {
this.logService.error(`Backup: Could not move backup folder to new location: ${ex.toString()}`);
}
}
}
@@ -225,38 +230,13 @@ export class BackupMainService implements IBackupMainService {
const hasBackups = this.hasBackupsSync(backupPath);
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
if (!hasBackups || missingWorkspace) {
staleBackupWorkspaces.push({ workspaceIdentifier: workspaceId, backupPath, target: workspaceOrFolder.target });
if (missingWorkspace) {
const identifier = this.getRandomEmptyWindowId();
this.pushBackupPathsSync(identifier, this.backups.emptyWorkspaces);
const newEmptyWindowBackupPath = path.join(this.backupHome, identifier);
try {
fs.renameSync(backupPath, newEmptyWindowBackupPath);
} catch (ex) {
this.logService.error(`Backup: Could not rename backup folder for missing workspace: ${ex.toString()}`);
this.removeBackupPathSync(identifier, this.backups.emptyWorkspaces);
}
this.convertToEmptyWindowBackup(backupPath);
}
}
});
@@ -283,6 +263,27 @@ export class BackupMainService implements IBackupMainService {
});
}
private convertToEmptyWindowBackup(backupPath: string): boolean {
// New empty window backup
const identifier = this.getRandomEmptyWindowId();
this.pushBackupPathsSync(identifier, this.backups.emptyWorkspaces);
// Rename backupPath to new empty window backup path
const newEmptyWindowBackupPath = path.join(this.backupHome, identifier);
try {
fs.renameSync(backupPath, newEmptyWindowBackupPath);
} catch (ex) {
this.logService.error(`Backup: Could not rename backup folder: ${ex.toString()}`);
this.removeBackupPathSync(identifier, this.backups.emptyWorkspaces);
return false;
}
return true;
}
private hasBackupsSync(backupPath: string): boolean {
try {
const backupSchemas = extfs.readdirSync(backupPath);