mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
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:
@@ -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);
|
||||
|
||||
@@ -23,9 +23,10 @@ import { LogMainService } from 'vs/platform/log/common/log';
|
||||
import { IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { createHash } from 'crypto';
|
||||
import { WorkspacesMainService } from 'vs/platform/workspaces/electron-main/workspacesMainService';
|
||||
import { getRandomTestPath } from 'vs/workbench/test/workbenchTestServices';
|
||||
|
||||
suite('BackupMainService', () => {
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', 'service');
|
||||
const parentDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'backupservice');
|
||||
const backupHome = path.join(parentDir, 'Backups');
|
||||
const backupWorkspacesPath = path.join(backupHome, 'workspaces.json');
|
||||
|
||||
@@ -208,6 +209,33 @@ suite('BackupMainService', () => {
|
||||
assert.ok(fs.existsSync(path.join(workspaceBackupPath, 'backup.txt')));
|
||||
assert.ok(!fs.existsSync(backupPathToMigrate));
|
||||
|
||||
const emptyBackups = service.getEmptyWindowBackupPaths();
|
||||
assert.equal(0, emptyBackups.length);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
test('service backup migration makes sure to preserve existing backups', done => {
|
||||
const backupPathToMigrate = service.toBackupPath(fooFile.fsPath);
|
||||
fs.mkdirSync(backupPathToMigrate);
|
||||
fs.writeFileSync(path.join(backupPathToMigrate, 'backup.txt'), 'Some Data');
|
||||
service.registerFolderBackupSync(backupPathToMigrate);
|
||||
|
||||
const backupPathToPreserve = service.toBackupPath(barFile.fsPath);
|
||||
fs.mkdirSync(backupPathToPreserve);
|
||||
fs.writeFileSync(path.join(backupPathToPreserve, 'backup.txt'), 'Some Data');
|
||||
service.registerFolderBackupSync(backupPathToPreserve);
|
||||
|
||||
const workspaceBackupPath = service.registerWorkspaceBackupSync(toWorkspace(barFile.fsPath), backupPathToMigrate);
|
||||
|
||||
assert.ok(fs.existsSync(workspaceBackupPath));
|
||||
assert.ok(fs.existsSync(path.join(workspaceBackupPath, 'backup.txt')));
|
||||
assert.ok(!fs.existsSync(backupPathToMigrate));
|
||||
|
||||
const emptyBackups = service.getEmptyWindowBackupPaths();
|
||||
assert.equal(1, emptyBackups.length);
|
||||
assert.equal(1, fs.readdirSync(path.join(backupHome, emptyBackups[0])).length);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -337,7 +365,8 @@ suite('BackupMainService', () => {
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
});
|
||||
|
||||
test('getEmptyWorkspaceBackupPaths() should return [] when folderWorkspaces in workspaces.json is not a string array', () => {
|
||||
test('getEmptyWorkspaceBackupPaths() should return [] when folderWorkspaces in workspaces.json is not a string array', function () {
|
||||
this.timeout(5000);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"emptyWorkspaces":{}}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
|
||||
Reference in New Issue
Block a user