mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Vscode merge (#4582)
* Merge from vscode 37cb23d3dd4f9433d56d4ba5ea3203580719a0bd * fix issues with merges * bump node version in azpipe * replace license headers * remove duplicate launch task * fix build errors * fix build errors * fix tslint issues * working through package and linux build issues * more work * wip * fix packaged builds * working through linux build errors * wip * wip * wip * fix mac and linux file limits * iterate linux pipeline * disable editor typing * revert series to parallel * remove optimize vscode from linux * fix linting issues * revert testing change * add work round for new node * readd packaging for extensions * fix issue with angular not resolving decorator dependencies
This commit is contained in:
@@ -7,14 +7,17 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
|
||||
import { IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
||||
export interface ISerializedWorkspace { id: string; configURIPath: string; remoteAuthority?: string; }
|
||||
|
||||
export interface IBackupWorkspacesFormat {
|
||||
rootWorkspaces: IWorkspaceIdentifier[];
|
||||
rootURIWorkspaces: ISerializedWorkspace[];
|
||||
folderURIWorkspaces: string[];
|
||||
emptyWorkspaceInfos: IEmptyWindowBackupInfo[];
|
||||
|
||||
// deprecated
|
||||
folderWorkspaces?: string[]; // use folderURIWorkspaces instead
|
||||
emptyWorkspaces?: string[];
|
||||
rootWorkspaces?: { id: string, configPath: string }[]; // use rootURIWorkspaces instead
|
||||
}
|
||||
|
||||
export const IBackupMainService = createDecorator<IBackupMainService>('backupMainService');
|
||||
@@ -24,18 +27,23 @@ export interface IEmptyWindowBackupInfo {
|
||||
remoteAuthority?: string;
|
||||
}
|
||||
|
||||
export interface IWorkspaceBackupInfo {
|
||||
workspace: IWorkspaceIdentifier;
|
||||
remoteAuthority?: string;
|
||||
}
|
||||
|
||||
export interface IBackupMainService {
|
||||
_serviceBrand: any;
|
||||
|
||||
isHotExitEnabled(): boolean;
|
||||
|
||||
getWorkspaceBackups(): IWorkspaceIdentifier[];
|
||||
getWorkspaceBackups(): IWorkspaceBackupInfo[];
|
||||
getFolderBackupPaths(): URI[];
|
||||
getEmptyWindowBackupPaths(): IEmptyWindowBackupInfo[];
|
||||
|
||||
registerWorkspaceBackupSync(workspace: IWorkspaceIdentifier, migrateFrom?: string): string;
|
||||
registerWorkspaceBackupSync(workspace: IWorkspaceBackupInfo, migrateFrom?: string): string;
|
||||
registerFolderBackupSync(folderUri: URI): string;
|
||||
registerEmptyWindowBackupSync(backupInfo: IEmptyWindowBackupInfo): string;
|
||||
registerEmptyWindowBackupSync(backupFolder?: string, remoteAuthority?: string): string;
|
||||
|
||||
unregisterWorkspaceBackupSync(workspace: IWorkspaceIdentifier): void;
|
||||
unregisterFolderBackupSync(folderUri: URI): void;
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as crypto from 'crypto';
|
||||
import * as path from 'vs/base/common/path';
|
||||
import * as platform from 'vs/base/common/platform';
|
||||
import { writeFileAndFlushSync } from 'vs/base/node/extfs';
|
||||
import * as arrays from 'vs/base/common/arrays';
|
||||
import { IBackupMainService, IBackupWorkspacesFormat, IEmptyWindowBackupInfo } from 'vs/platform/backup/common/backup';
|
||||
import { IBackupMainService, IBackupWorkspacesFormat, IEmptyWindowBackupInfo, IWorkspaceBackupInfo } from 'vs/platform/backup/common/backup';
|
||||
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';
|
||||
@@ -17,7 +17,7 @@ import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { IWorkspaceIdentifier, isWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { isEqual as areResourcesEquals, getComparisonKey, hasToIgnoreCase } from 'vs/base/common/resources';
|
||||
import { isEqual } from 'vs/base/common/paths';
|
||||
import { isEqual } from 'vs/base/common/extpath';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { writeFile, readFile, readdir, exists, del, rename } from 'vs/base/node/pfs';
|
||||
|
||||
@@ -28,7 +28,7 @@ export class BackupMainService implements IBackupMainService {
|
||||
protected backupHome: string;
|
||||
protected workspacesJsonPath: string;
|
||||
|
||||
private rootWorkspaces: IWorkspaceIdentifier[];
|
||||
private rootWorkspaces: IWorkspaceBackupInfo[];
|
||||
private folderWorkspaces: URI[];
|
||||
private emptyWorkspaces: IEmptyWindowBackupInfo[];
|
||||
|
||||
@@ -60,7 +60,17 @@ export class BackupMainService implements IBackupMainService {
|
||||
}
|
||||
|
||||
// read workspace backups
|
||||
this.rootWorkspaces = await this.validateWorkspaces(backups.rootWorkspaces);
|
||||
let rootWorkspaces: IWorkspaceBackupInfo[] = [];
|
||||
try {
|
||||
if (Array.isArray(backups.rootURIWorkspaces)) {
|
||||
rootWorkspaces = backups.rootURIWorkspaces.map(f => ({ workspace: { id: f.id, configPath: URI.parse(f.configURIPath) }, remoteAuthority: f.remoteAuthority }));
|
||||
} else if (Array.isArray(backups.rootWorkspaces)) {
|
||||
rootWorkspaces = backups.rootWorkspaces.map(f => ({ workspace: { id: f.id, configPath: URI.file(f.configPath) } }));
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore URI parsing exceptions
|
||||
}
|
||||
this.rootWorkspaces = await this.validateWorkspaces(rootWorkspaces);
|
||||
|
||||
// read folder backups
|
||||
let workspaceFolders: URI[] = [];
|
||||
@@ -90,7 +100,7 @@ export class BackupMainService implements IBackupMainService {
|
||||
await this.save();
|
||||
}
|
||||
|
||||
getWorkspaceBackups(): IWorkspaceIdentifier[] {
|
||||
getWorkspaceBackups(): IWorkspaceBackupInfo[] {
|
||||
if (this.isHotExitOnExitAndWindowClose()) {
|
||||
// Only non-folder windows are restored on main process launch when
|
||||
// hot exit is configured as onExitAndWindowClose.
|
||||
@@ -128,13 +138,13 @@ export class BackupMainService implements IBackupMainService {
|
||||
return this.emptyWorkspaces.slice(0); // return a copy
|
||||
}
|
||||
|
||||
registerWorkspaceBackupSync(workspace: IWorkspaceIdentifier, migrateFrom?: string): string {
|
||||
if (!this.rootWorkspaces.some(w => w.id === workspace.id)) {
|
||||
this.rootWorkspaces.push(workspace);
|
||||
registerWorkspaceBackupSync(workspaceInfo: IWorkspaceBackupInfo, migrateFrom?: string): string {
|
||||
if (!this.rootWorkspaces.some(w => workspaceInfo.workspace.id === w.workspace.id)) {
|
||||
this.rootWorkspaces.push(workspaceInfo);
|
||||
this.saveSync();
|
||||
}
|
||||
|
||||
const backupPath = this.getBackupPath(workspace.id);
|
||||
const backupPath = this.getBackupPath(workspaceInfo.workspace.id);
|
||||
|
||||
if (migrateFrom) {
|
||||
this.moveBackupFolderSync(backupPath, migrateFrom);
|
||||
@@ -178,7 +188,8 @@ export class BackupMainService implements IBackupMainService {
|
||||
}
|
||||
|
||||
unregisterWorkspaceBackupSync(workspace: IWorkspaceIdentifier): void {
|
||||
let index = arrays.firstIndex(this.rootWorkspaces, w => w.id === workspace.id);
|
||||
const id = workspace.id;
|
||||
let index = arrays.firstIndex(this.rootWorkspaces, w => w.workspace.id === id);
|
||||
if (index !== -1) {
|
||||
this.rootWorkspaces.splice(index, 1);
|
||||
this.saveSync();
|
||||
@@ -202,16 +213,14 @@ export class BackupMainService implements IBackupMainService {
|
||||
}
|
||||
}
|
||||
|
||||
registerEmptyWindowBackupSync(backupInfo: IEmptyWindowBackupInfo): string {
|
||||
let backupFolder = backupInfo.backupFolder;
|
||||
let remoteAuthority = backupInfo.remoteAuthority;
|
||||
registerEmptyWindowBackupSync(backupFolder?: string, remoteAuthority?: string): string {
|
||||
|
||||
// Generate a new folder if this is a new empty workspace
|
||||
if (!backupFolder) {
|
||||
backupFolder = this.getRandomEmptyWindowId();
|
||||
}
|
||||
|
||||
if (!this.emptyWorkspaces.some(w => isEqual(w.backupFolder, backupFolder, !platform.isLinux))) {
|
||||
if (!this.emptyWorkspaces.some(w => !!w.backupFolder && isEqual(w.backupFolder, backupFolder!, !platform.isLinux))) {
|
||||
this.emptyWorkspaces.push({ backupFolder, remoteAuthority });
|
||||
this.saveSync();
|
||||
}
|
||||
@@ -220,7 +229,7 @@ export class BackupMainService implements IBackupMainService {
|
||||
}
|
||||
|
||||
unregisterEmptyWindowBackupSync(backupFolder: string): void {
|
||||
let index = arrays.firstIndex(this.emptyWorkspaces, w => isEqual(w.backupFolder, backupFolder, !platform.isLinux));
|
||||
let index = arrays.firstIndex(this.emptyWorkspaces, w => !!w.backupFolder && isEqual(w.backupFolder, backupFolder, !platform.isLinux));
|
||||
if (index !== -1) {
|
||||
this.emptyWorkspaces.splice(index, 1);
|
||||
this.saveSync();
|
||||
@@ -231,16 +240,17 @@ export class BackupMainService implements IBackupMainService {
|
||||
return path.join(this.backupHome, oldFolderHash);
|
||||
}
|
||||
|
||||
private async validateWorkspaces(rootWorkspaces: IWorkspaceIdentifier[]): Promise<IWorkspaceIdentifier[]> {
|
||||
private async validateWorkspaces(rootWorkspaces: IWorkspaceBackupInfo[]): Promise<IWorkspaceBackupInfo[]> {
|
||||
if (!Array.isArray(rootWorkspaces)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const seenIds: { [id: string]: boolean } = Object.create(null);
|
||||
const result: IWorkspaceIdentifier[] = [];
|
||||
const result: IWorkspaceBackupInfo[] = [];
|
||||
|
||||
// Validate Workspaces
|
||||
for (let workspace of rootWorkspaces) {
|
||||
for (let workspaceInfo of rootWorkspaces) {
|
||||
const workspace = workspaceInfo.workspace;
|
||||
if (!isWorkspaceIdentifier(workspace)) {
|
||||
return []; // wrong format, skip all entries
|
||||
}
|
||||
@@ -253,8 +263,8 @@ export class BackupMainService implements IBackupMainService {
|
||||
|
||||
// If the workspace has no backups, ignore it
|
||||
if (hasBackups) {
|
||||
if (await exists(workspace.configPath)) {
|
||||
result.push(workspace);
|
||||
if (workspace.configPath.scheme !== Schemas.file || await exists(workspace.configPath.fsPath)) {
|
||||
result.push(workspaceInfo);
|
||||
} else {
|
||||
// If the workspace has backups, but the target workspace is missing, convert backups to empty ones
|
||||
await this.convertToEmptyWindowBackup(backupPath);
|
||||
@@ -344,7 +354,7 @@ export class BackupMainService implements IBackupMainService {
|
||||
|
||||
// New empty window backup
|
||||
let newBackupFolder = this.getRandomEmptyWindowId();
|
||||
while (this.emptyWorkspaces.some(w => isEqual(w.backupFolder, newBackupFolder, platform.isLinux))) {
|
||||
while (this.emptyWorkspaces.some(w => !!w.backupFolder && isEqual(w.backupFolder, newBackupFolder, platform.isLinux))) {
|
||||
newBackupFolder = this.getRandomEmptyWindowId();
|
||||
}
|
||||
|
||||
@@ -365,7 +375,7 @@ export class BackupMainService implements IBackupMainService {
|
||||
|
||||
// New empty window backup
|
||||
let newBackupFolder = this.getRandomEmptyWindowId();
|
||||
while (this.emptyWorkspaces.some(w => isEqual(w.backupFolder, newBackupFolder, platform.isLinux))) {
|
||||
while (this.emptyWorkspaces.some(w => !!w.backupFolder && isEqual(w.backupFolder, newBackupFolder, platform.isLinux))) {
|
||||
newBackupFolder = this.getRandomEmptyWindowId();
|
||||
}
|
||||
|
||||
@@ -421,7 +431,7 @@ export class BackupMainService implements IBackupMainService {
|
||||
|
||||
private serializeBackups(): IBackupWorkspacesFormat {
|
||||
return {
|
||||
rootWorkspaces: this.rootWorkspaces,
|
||||
rootURIWorkspaces: this.rootWorkspaces.map(f => ({ id: f.workspace.id, configURIPath: f.workspace.configPath.toString(), remoteAuthority: f.remoteAuthority })),
|
||||
folderURIWorkspaces: this.folderWorkspaces.map(f => f.toString()),
|
||||
emptyWorkspaceInfos: this.emptyWorkspaces,
|
||||
emptyWorkspaces: this.emptyWorkspaces.map(info => info.backupFolder)
|
||||
|
||||
@@ -7,19 +7,19 @@ import * as assert from 'assert';
|
||||
import * as platform from 'vs/base/common/platform';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as path from 'vs/base/common/path';
|
||||
import * as pfs from 'vs/base/node/pfs';
|
||||
import { URI as Uri } from 'vs/base/common/uri';
|
||||
import { URI as Uri, URI } from 'vs/base/common/uri';
|
||||
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
|
||||
import { parseArgs } from 'vs/platform/environment/node/argv';
|
||||
import { BackupMainService } from 'vs/platform/backup/electron-main/backupMainService';
|
||||
import { IBackupWorkspacesFormat } from 'vs/platform/backup/common/backup';
|
||||
import { IBackupWorkspacesFormat, ISerializedWorkspace, IWorkspaceBackupInfo } from 'vs/platform/backup/common/backup';
|
||||
import { HotExitConfiguration } from 'vs/platform/files/common/files';
|
||||
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
|
||||
import { ConsoleLogMainService } from 'vs/platform/log/common/log';
|
||||
import { IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { createHash } from 'crypto';
|
||||
import { getRandomTestPath } from 'vs/workbench/test/workbenchTestServices';
|
||||
import { getRandomTestPath } from 'vs/base/test/node/testUtils';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
|
||||
suite('BackupMainService', () => {
|
||||
@@ -60,7 +60,24 @@ suite('BackupMainService', () => {
|
||||
function toWorkspace(path: string): IWorkspaceIdentifier {
|
||||
return {
|
||||
id: createHash('md5').update(sanitizePath(path)).digest('hex'),
|
||||
configPath: path
|
||||
configPath: URI.file(path)
|
||||
};
|
||||
}
|
||||
|
||||
function toWorkspaceBackupInfo(path: string, remoteAuthority?: string): IWorkspaceBackupInfo {
|
||||
return {
|
||||
workspace: {
|
||||
id: createHash('md5').update(sanitizePath(path)).digest('hex'),
|
||||
configPath: URI.file(path)
|
||||
},
|
||||
remoteAuthority
|
||||
};
|
||||
}
|
||||
|
||||
function toSerializedWorkspace(ws: IWorkspaceIdentifier): ISerializedWorkspace {
|
||||
return {
|
||||
id: ws.id,
|
||||
configURIPath: ws.configPath.toString()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -73,8 +90,8 @@ suite('BackupMainService', () => {
|
||||
}
|
||||
|
||||
async function ensureWorkspaceExists(workspace: IWorkspaceIdentifier): Promise<IWorkspaceIdentifier> {
|
||||
if (!fs.existsSync(workspace.configPath)) {
|
||||
await pfs.writeFile(workspace.configPath, 'Hello');
|
||||
if (!fs.existsSync(workspace.configPath.fsPath)) {
|
||||
await pfs.writeFile(workspace.configPath.fsPath, 'Hello');
|
||||
}
|
||||
const backupFolder = service.toBackupPath(workspace.id);
|
||||
await createBackupFolder(backupFolder);
|
||||
@@ -168,16 +185,16 @@ suite('BackupMainService', () => {
|
||||
this.timeout(1000 * 10); // increase timeout for this test
|
||||
|
||||
// 1) backup workspace path does not exist
|
||||
service.registerWorkspaceBackupSync(toWorkspace(fooFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspace(barFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(fooFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(barFile.fsPath));
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
|
||||
// 2) backup workspace path exists with empty contents within
|
||||
fs.mkdirSync(service.toBackupPath(fooFile));
|
||||
fs.mkdirSync(service.toBackupPath(barFile));
|
||||
service.registerWorkspaceBackupSync(toWorkspace(fooFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspace(barFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(fooFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(barFile.fsPath));
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.ok(!fs.existsSync(service.toBackupPath(fooFile)));
|
||||
@@ -188,8 +205,8 @@ suite('BackupMainService', () => {
|
||||
fs.mkdirSync(service.toBackupPath(barFile));
|
||||
fs.mkdirSync(path.join(service.toBackupPath(fooFile), Schemas.file));
|
||||
fs.mkdirSync(path.join(service.toBackupPath(barFile), Schemas.untitled));
|
||||
service.registerWorkspaceBackupSync(toWorkspace(fooFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspace(barFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(fooFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(barFile.fsPath));
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.ok(!fs.existsSync(service.toBackupPath(fooFile)));
|
||||
@@ -201,7 +218,7 @@ suite('BackupMainService', () => {
|
||||
fs.mkdirSync(service.toBackupPath(fooFile));
|
||||
fs.mkdirSync(service.toBackupPath(barFile));
|
||||
fs.mkdirSync(fileBackups);
|
||||
service.registerWorkspaceBackupSync(toWorkspace(fooFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(fooFile.fsPath));
|
||||
assert.equal(service.getWorkspaceBackups().length, 1);
|
||||
assert.equal(service.getEmptyWindowBackupPaths().length, 0);
|
||||
fs.writeFileSync(path.join(fileBackups, 'backup.txt'), '');
|
||||
@@ -216,7 +233,7 @@ suite('BackupMainService', () => {
|
||||
fs.writeFileSync(path.join(backupPathToMigrate, 'backup.txt'), 'Some Data');
|
||||
service.registerFolderBackupSync(Uri.file(backupPathToMigrate));
|
||||
|
||||
const workspaceBackupPath = service.registerWorkspaceBackupSync(toWorkspace(barFile.fsPath), backupPathToMigrate);
|
||||
const workspaceBackupPath = service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(barFile.fsPath), backupPathToMigrate);
|
||||
|
||||
assert.ok(fs.existsSync(workspaceBackupPath));
|
||||
assert.ok(fs.existsSync(path.join(workspaceBackupPath, 'backup.txt')));
|
||||
@@ -237,7 +254,7 @@ suite('BackupMainService', () => {
|
||||
fs.writeFileSync(path.join(backupPathToPreserve, 'backup.txt'), 'Some Data');
|
||||
service.registerFolderBackupSync(Uri.file(backupPathToPreserve));
|
||||
|
||||
const workspaceBackupPath = service.registerWorkspaceBackupSync(toWorkspace(barFile.fsPath), backupPathToMigrate);
|
||||
const workspaceBackupPath = service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(barFile.fsPath), backupPathToMigrate);
|
||||
|
||||
assert.ok(fs.existsSync(workspaceBackupPath));
|
||||
assert.ok(fs.existsSync(path.join(workspaceBackupPath, 'backup.txt')));
|
||||
@@ -245,18 +262,14 @@ suite('BackupMainService', () => {
|
||||
|
||||
const emptyBackups = service.getEmptyWindowBackupPaths();
|
||||
assert.equal(1, emptyBackups.length);
|
||||
assert.equal(1, fs.readdirSync(path.join(backupHome, emptyBackups[0].backupFolder)).length);
|
||||
assert.equal(1, fs.readdirSync(path.join(backupHome, emptyBackups[0].backupFolder!)).length);
|
||||
});
|
||||
|
||||
suite('migrate folderPath to folderURI', () => {
|
||||
suite('migrate path to URI', () => {
|
||||
|
||||
test('migration makes sure to preserve existing backups', async () => {
|
||||
if (platform.isLinux) {
|
||||
return; // TODO:Martin #54483 fix tests
|
||||
}
|
||||
|
||||
let path1 = path.join(parentDir, 'folder1').toLowerCase();
|
||||
let path2 = path.join(parentDir, 'folder2').toUpperCase();
|
||||
test('migration folder path to URI makes sure to preserve existing backups', async () => {
|
||||
let path1 = path.join(parentDir, 'folder1');
|
||||
let path2 = path.join(parentDir, 'FOLDER2');
|
||||
let uri1 = Uri.file(path1);
|
||||
let uri2 = Uri.file(path2);
|
||||
|
||||
@@ -290,8 +303,30 @@ suite('BackupMainService', () => {
|
||||
const newBackupFolder2 = service.toBackupPath(uri2);
|
||||
assert.ok(fs.existsSync(path.join(newBackupFolder2, Schemas.file, 'unsaved2.txt')));
|
||||
});
|
||||
|
||||
test('migrate storage file', async () => {
|
||||
let folderPath = path.join(parentDir, 'f1');
|
||||
ensureFolderExists(URI.file(folderPath));
|
||||
const backupFolderPath = service.toLegacyBackupPath(folderPath);
|
||||
await createBackupFolder(backupFolderPath);
|
||||
|
||||
let workspacePath = path.join(parentDir, 'f2.code-workspace');
|
||||
const workspace = toWorkspace(workspacePath);
|
||||
await ensureWorkspaceExists(workspace);
|
||||
|
||||
const workspacesJson = { rootWorkspaces: [{ id: workspace.id, configPath: workspacePath }], folderWorkspaces: [folderPath], emptyWorkspaces: [] };
|
||||
await pfs.writeFile(backupWorkspacesPath, JSON.stringify(workspacesJson));
|
||||
await service.initialize();
|
||||
const content = await pfs.readFile(backupWorkspacesPath, 'utf-8');
|
||||
const json = (<IBackupWorkspacesFormat>JSON.parse(content));
|
||||
assert.deepEqual(json.folderURIWorkspaces, [URI.file(folderPath).toString()]);
|
||||
assert.deepEqual(json.rootURIWorkspaces, [{ id: workspace.id, configURIPath: URI.file(workspacePath).toString() }]);
|
||||
|
||||
assertEqualUris(service.getWorkspaceBackups().map(w => w.workspace.configPath), [workspace.configPath]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
suite('loadSync', () => {
|
||||
test('getFolderBackupPaths() should return [] when workspaces.json doesn\'t exist', () => {
|
||||
assertEqualUris(service.getFolderBackupPaths(), []);
|
||||
@@ -387,10 +422,32 @@ suite('BackupMainService', () => {
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
});
|
||||
|
||||
test('getWorkspaceBackups() should return [] when rootURIWorkspaces in workspaces.json is not a object array', async () => {
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootURIWorkspaces":{}}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootURIWorkspaces":{"foo": ["bar"]}}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootURIWorkspaces":{"foo": []}}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootURIWorkspaces":{"foo": "bar"}}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootURIWorkspaces":"foo"}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootURIWorkspaces":1}');
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
});
|
||||
|
||||
test('getWorkspaceBackups() should return [] when files.hotExit = "onExitAndWindowClose"', async () => {
|
||||
service.registerWorkspaceBackupSync(toWorkspace(fooFile.fsPath.toUpperCase()));
|
||||
const upperFooPath = fooFile.fsPath.toUpperCase();
|
||||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(upperFooPath));
|
||||
assert.equal(service.getWorkspaceBackups().length, 1);
|
||||
assert.deepEqual(service.getWorkspaceBackups().map(r => r.configPath), [fooFile.fsPath.toUpperCase()]);
|
||||
assertEqualUris(service.getWorkspaceBackups().map(r => r.workspace.configPath), [URI.file(upperFooPath)]);
|
||||
configService.setUserConfiguration('files.hotExit', HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE);
|
||||
await service.initialize();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
@@ -447,7 +504,7 @@ suite('BackupMainService', () => {
|
||||
await ensureFolderExists(existingTestFolder1);
|
||||
|
||||
const workspacesJson: IBackupWorkspacesFormat = {
|
||||
rootWorkspaces: [],
|
||||
rootURIWorkspaces: [],
|
||||
folderURIWorkspaces: [existingTestFolder1.toString(), existingTestFolder1.toString()],
|
||||
emptyWorkspaceInfos: []
|
||||
};
|
||||
@@ -464,7 +521,7 @@ suite('BackupMainService', () => {
|
||||
await ensureFolderExists(existingTestFolder1);
|
||||
|
||||
const workspacesJson: IBackupWorkspacesFormat = {
|
||||
rootWorkspaces: [],
|
||||
rootURIWorkspaces: [],
|
||||
folderURIWorkspaces: [existingTestFolder1.toString(), existingTestFolder1.toString().toLowerCase()],
|
||||
emptyWorkspaceInfos: []
|
||||
};
|
||||
@@ -476,18 +533,17 @@ suite('BackupMainService', () => {
|
||||
});
|
||||
|
||||
test('should ignore duplicates on Windows and Mac (root workspace)', async () => {
|
||||
if (platform.isLinux) {
|
||||
return; // TODO:Martin #54483 fix tests
|
||||
}
|
||||
|
||||
const workspacePath = path.join(parentDir, 'Foo.code-workspace');
|
||||
const workspacePath1 = path.join(parentDir, 'FOO.code-workspace');
|
||||
const workspacePath2 = path.join(parentDir, 'foo.code-workspace');
|
||||
|
||||
const workspace1 = await ensureWorkspaceExists(toWorkspace(workspacePath));
|
||||
const workspace2 = await ensureWorkspaceExists(toWorkspace(workspacePath.toUpperCase()));
|
||||
const workspace3 = await ensureWorkspaceExists(toWorkspace(workspacePath.toLowerCase()));
|
||||
const workspace2 = await ensureWorkspaceExists(toWorkspace(workspacePath1));
|
||||
const workspace3 = await ensureWorkspaceExists(toWorkspace(workspacePath2));
|
||||
|
||||
const workspacesJson: IBackupWorkspacesFormat = {
|
||||
rootWorkspaces: [workspace1, workspace2, workspace3],
|
||||
rootURIWorkspaces: [workspace1, workspace2, workspace3].map(toSerializedWorkspace),
|
||||
folderURIWorkspaces: [],
|
||||
emptyWorkspaceInfos: []
|
||||
};
|
||||
@@ -496,11 +552,11 @@ suite('BackupMainService', () => {
|
||||
|
||||
const buffer = await pfs.readFile(backupWorkspacesPath, 'utf-8');
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
|
||||
assert.equal(json.rootWorkspaces.length, platform.isLinux ? 3 : 1);
|
||||
assert.equal(json.rootURIWorkspaces.length, platform.isLinux ? 3 : 1);
|
||||
if (platform.isLinux) {
|
||||
assert.deepEqual(json.rootWorkspaces.map(r => r.configPath), [workspacePath, workspacePath.toUpperCase(), workspacePath.toLowerCase()]);
|
||||
assert.deepEqual(json.rootURIWorkspaces.map(r => r.configURIPath), [URI.file(workspacePath).toString(), URI.file(workspacePath1).toString(), URI.file(workspacePath2).toString()]);
|
||||
} else {
|
||||
assert.deepEqual(json.rootWorkspaces.map(r => r.configPath), [workspacePath], 'should return the first duplicated entry');
|
||||
assert.deepEqual(json.rootURIWorkspaces.map(r => r.configURIPath), [URI.file(workspacePath).toString()], 'should return the first duplicated entry');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -516,21 +572,21 @@ suite('BackupMainService', () => {
|
||||
});
|
||||
|
||||
test('should persist paths to workspaces.json (root workspace)', async () => {
|
||||
const ws1 = toWorkspace(fooFile.fsPath);
|
||||
const ws1 = toWorkspaceBackupInfo(fooFile.fsPath);
|
||||
service.registerWorkspaceBackupSync(ws1);
|
||||
const ws2 = toWorkspace(barFile.fsPath);
|
||||
const ws2 = toWorkspaceBackupInfo(barFile.fsPath);
|
||||
service.registerWorkspaceBackupSync(ws2);
|
||||
|
||||
assert.deepEqual(service.getWorkspaceBackups().map(b => b.configPath), [fooFile.fsPath, barFile.fsPath]);
|
||||
assert.equal(ws1.id, service.getWorkspaceBackups()[0].id);
|
||||
assert.equal(ws2.id, service.getWorkspaceBackups()[1].id);
|
||||
assertEqualUris(service.getWorkspaceBackups().map(b => b.workspace.configPath), [fooFile, barFile]);
|
||||
assert.equal(ws1.workspace.id, service.getWorkspaceBackups()[0].workspace.id);
|
||||
assert.equal(ws2.workspace.id, service.getWorkspaceBackups()[1].workspace.id);
|
||||
|
||||
const buffer = await pfs.readFile(backupWorkspacesPath, 'utf-8');
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
|
||||
|
||||
assert.deepEqual(json.rootWorkspaces.map(b => b.configPath), [fooFile.fsPath, barFile.fsPath]);
|
||||
assert.equal(ws1.id, json.rootWorkspaces[0].id);
|
||||
assert.equal(ws2.id, json.rootWorkspaces[1].id);
|
||||
assert.deepEqual(json.rootURIWorkspaces.map(b => b.configURIPath), [fooFile.toString(), barFile.toString()]);
|
||||
assert.equal(ws1.workspace.id, json.rootURIWorkspaces[0].id);
|
||||
assert.equal(ws2.workspace.id, json.rootURIWorkspaces[1].id);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -544,11 +600,12 @@ suite('BackupMainService', () => {
|
||||
});
|
||||
|
||||
test('should always store the workspace path in workspaces.json using the case given, regardless of whether the file system is case-sensitive (root workspace)', () => {
|
||||
service.registerWorkspaceBackupSync(toWorkspace(fooFile.fsPath.toUpperCase()));
|
||||
assert.deepEqual(service.getWorkspaceBackups().map(b => b.configPath), [fooFile.fsPath.toUpperCase()]);
|
||||
const upperFooPath = fooFile.fsPath.toUpperCase();
|
||||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(upperFooPath));
|
||||
assertEqualUris(service.getWorkspaceBackups().map(b => b.workspace.configPath), [URI.file(upperFooPath)]);
|
||||
return pfs.readFile(backupWorkspacesPath, 'utf-8').then(buffer => {
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
|
||||
assert.deepEqual(json.rootWorkspaces.map(b => b.configPath), [fooFile.fsPath.toUpperCase()]);
|
||||
assert.deepEqual(json.rootURIWorkspaces.map(b => b.configURIPath), [URI.file(upperFooPath).toString()]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -569,25 +626,25 @@ suite('BackupMainService', () => {
|
||||
});
|
||||
|
||||
test('should remove folder workspaces from workspaces.json (root workspace)', () => {
|
||||
const ws1 = toWorkspace(fooFile.fsPath);
|
||||
const ws1 = toWorkspaceBackupInfo(fooFile.fsPath);
|
||||
service.registerWorkspaceBackupSync(ws1);
|
||||
const ws2 = toWorkspace(barFile.fsPath);
|
||||
const ws2 = toWorkspaceBackupInfo(barFile.fsPath);
|
||||
service.registerWorkspaceBackupSync(ws2);
|
||||
service.unregisterWorkspaceBackupSync(ws1);
|
||||
service.unregisterWorkspaceBackupSync(ws1.workspace);
|
||||
return pfs.readFile(backupWorkspacesPath, 'utf-8').then(buffer => {
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
|
||||
assert.deepEqual(json.rootWorkspaces.map(r => r.configPath), [barFile.fsPath]);
|
||||
service.unregisterWorkspaceBackupSync(ws2);
|
||||
assert.deepEqual(json.rootURIWorkspaces.map(r => r.configURIPath), [barFile.toString()]);
|
||||
service.unregisterWorkspaceBackupSync(ws2.workspace);
|
||||
return pfs.readFile(backupWorkspacesPath, 'utf-8').then(content => {
|
||||
const json2 = <IBackupWorkspacesFormat>JSON.parse(content);
|
||||
assert.deepEqual(json2.rootWorkspaces, []);
|
||||
assert.deepEqual(json2.rootURIWorkspaces, []);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should remove empty workspaces from workspaces.json', () => {
|
||||
service.registerEmptyWindowBackupSync({ backupFolder: 'foo' });
|
||||
service.registerEmptyWindowBackupSync({ backupFolder: 'bar' });
|
||||
service.registerEmptyWindowBackupSync('foo');
|
||||
service.registerEmptyWindowBackupSync('bar');
|
||||
service.unregisterEmptyWindowBackupSync('foo');
|
||||
return pfs.readFile(backupWorkspacesPath, 'utf-8').then(buffer => {
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
|
||||
@@ -604,7 +661,7 @@ suite('BackupMainService', () => {
|
||||
|
||||
await ensureFolderExists(existingTestFolder1); // make sure backup folder exists, so the folder is not removed on loadSync
|
||||
|
||||
const workspacesJson: IBackupWorkspacesFormat = { rootWorkspaces: [], folderURIWorkspaces: [existingTestFolder1.toString()], emptyWorkspaceInfos: [] };
|
||||
const workspacesJson: IBackupWorkspacesFormat = { rootURIWorkspaces: [], folderURIWorkspaces: [existingTestFolder1.toString()], emptyWorkspaceInfos: [] };
|
||||
await pfs.writeFile(backupWorkspacesPath, JSON.stringify(workspacesJson));
|
||||
await service.initialize();
|
||||
service.unregisterFolderBackupSync(barFile);
|
||||
@@ -646,8 +703,8 @@ suite('BackupMainService', () => {
|
||||
});
|
||||
|
||||
test('should handle case insensitive paths properly (registerWindowForBackupsSync) (root workspace)', () => {
|
||||
service.registerWorkspaceBackupSync(toWorkspace(fooFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspace(fooFile.fsPath.toUpperCase()));
|
||||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(fooFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspaceBackupInfo(fooFile.fsPath.toUpperCase()));
|
||||
|
||||
if (platform.isLinux) {
|
||||
assert.equal(service.getWorkspaceBackups().length, 2);
|
||||
|
||||
Reference in New Issue
Block a user