mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
29
src/vs/platform/backup/common/backup.ts
Normal file
29
src/vs/platform/backup/common/backup.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
|
||||
|
||||
export interface IBackupWorkspacesFormat {
|
||||
rootWorkspaces: IWorkspaceIdentifier[];
|
||||
folderWorkspaces: string[];
|
||||
emptyWorkspaces: string[];
|
||||
}
|
||||
|
||||
export const IBackupMainService = createDecorator<IBackupMainService>('backupMainService');
|
||||
|
||||
export interface IBackupMainService {
|
||||
_serviceBrand: any;
|
||||
|
||||
isHotExitEnabled(): boolean;
|
||||
|
||||
getWorkspaceBackups(): IWorkspaceIdentifier[];
|
||||
getFolderBackupPaths(): string[];
|
||||
getEmptyWindowBackupPaths(): string[];
|
||||
|
||||
registerWorkspaceBackupSync(workspace: IWorkspaceIdentifier, migrateFrom?: string): string;
|
||||
registerFolderBackupSync(folderPath: string): string;
|
||||
registerEmptyWindowBackupSync(backupFolder?: string): string;
|
||||
}
|
||||
329
src/vs/platform/backup/electron-main/backupMainService.ts
Normal file
329
src/vs/platform/backup/electron-main/backupMainService.ts
Normal file
@@ -0,0 +1,329 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as arrays from 'vs/base/common/arrays';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as crypto from 'crypto';
|
||||
import * as platform from 'vs/base/common/platform';
|
||||
import * as extfs from 'vs/base/node/extfs';
|
||||
import { IBackupWorkspacesFormat, IBackupMainService } 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';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, IWorkspacesMainService, isSingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
|
||||
|
||||
export class BackupMainService implements IBackupMainService {
|
||||
|
||||
public _serviceBrand: any;
|
||||
|
||||
protected backupHome: string;
|
||||
protected workspacesJsonPath: string;
|
||||
|
||||
protected backups: IBackupWorkspacesFormat;
|
||||
|
||||
constructor(
|
||||
@IEnvironmentService environmentService: IEnvironmentService,
|
||||
@IConfigurationService private configurationService: IConfigurationService,
|
||||
@ILogService private logService: ILogService,
|
||||
@IWorkspacesMainService private workspacesService: IWorkspacesMainService
|
||||
) {
|
||||
this.backupHome = environmentService.backupHome;
|
||||
this.workspacesJsonPath = environmentService.backupWorkspacesPath;
|
||||
|
||||
this.loadSync();
|
||||
}
|
||||
|
||||
public getWorkspaceBackups(): IWorkspaceIdentifier[] {
|
||||
if (this.isHotExitOnExitAndWindowClose()) {
|
||||
// Only non-folder windows are restored on main process launch when
|
||||
// hot exit is configured as onExitAndWindowClose.
|
||||
return [];
|
||||
}
|
||||
|
||||
return this.backups.rootWorkspaces.slice(0); // return a copy
|
||||
}
|
||||
|
||||
public getFolderBackupPaths(): string[] {
|
||||
if (this.isHotExitOnExitAndWindowClose()) {
|
||||
// Only non-folder windows are restored on main process launch when
|
||||
// hot exit is configured as onExitAndWindowClose.
|
||||
return [];
|
||||
}
|
||||
|
||||
return this.backups.folderWorkspaces.slice(0); // return a copy
|
||||
}
|
||||
|
||||
public isHotExitEnabled(): boolean {
|
||||
return this.getHotExitConfig() !== HotExitConfiguration.OFF;
|
||||
}
|
||||
|
||||
private isHotExitOnExitAndWindowClose(): boolean {
|
||||
return this.getHotExitConfig() === HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE;
|
||||
}
|
||||
|
||||
private getHotExitConfig(): string {
|
||||
const config = this.configurationService.getConfiguration<IFilesConfiguration>();
|
||||
|
||||
return (config && config.files && config.files.hotExit) || HotExitConfiguration.ON_EXIT;
|
||||
}
|
||||
|
||||
public getEmptyWindowBackupPaths(): string[] {
|
||||
return this.backups.emptyWorkspaces.slice(0); // return a copy
|
||||
}
|
||||
|
||||
public registerWorkspaceBackupSync(workspace: IWorkspaceIdentifier, migrateFrom?: string): string {
|
||||
this.pushBackupPathsSync(workspace, this.backups.rootWorkspaces);
|
||||
|
||||
const backupPath = path.join(this.backupHome, workspace.id);
|
||||
|
||||
if (migrateFrom) {
|
||||
this.moveBackupFolderSync(backupPath, migrateFrom);
|
||||
}
|
||||
|
||||
return backupPath;
|
||||
}
|
||||
|
||||
private moveBackupFolderSync(backupPath: string, moveFromPath: string): void {
|
||||
if (!fs.existsSync(moveFromPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
fs.renameSync(moveFromPath, backupPath);
|
||||
} catch (ex) {
|
||||
this.logService.error(`Backup: Could not move backup folder to new location: ${ex.toString()}`);
|
||||
}
|
||||
}
|
||||
|
||||
public registerFolderBackupSync(folderPath: string): string {
|
||||
this.pushBackupPathsSync(folderPath, this.backups.folderWorkspaces);
|
||||
|
||||
return path.join(this.backupHome, this.getFolderHash(folderPath));
|
||||
}
|
||||
|
||||
public registerEmptyWindowBackupSync(backupFolder?: string): string {
|
||||
|
||||
// Generate a new folder if this is a new empty workspace
|
||||
if (!backupFolder) {
|
||||
backupFolder = this.getRandomEmptyWindowId();
|
||||
}
|
||||
|
||||
this.pushBackupPathsSync(backupFolder, this.backups.emptyWorkspaces);
|
||||
|
||||
return path.join(this.backupHome, backupFolder);
|
||||
}
|
||||
|
||||
private pushBackupPathsSync(workspaceIdentifier: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier, target: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)[]): void {
|
||||
if (this.indexOf(workspaceIdentifier, target) === -1) {
|
||||
target.push(workspaceIdentifier);
|
||||
this.saveSync();
|
||||
}
|
||||
}
|
||||
|
||||
protected removeBackupPathSync(workspaceIdentifier: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier, target: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)[]): void {
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
|
||||
const index = this.indexOf(workspaceIdentifier, target);
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
target.splice(index, 1);
|
||||
this.saveSync();
|
||||
}
|
||||
|
||||
private indexOf(workspaceIdentifier: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier, target: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)[]): number {
|
||||
if (!target) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const sanitizedWorkspaceIdentifier = this.sanitizeId(workspaceIdentifier);
|
||||
|
||||
return arrays.firstIndex(target, id => this.sanitizeId(id) === sanitizedWorkspaceIdentifier);
|
||||
}
|
||||
|
||||
private sanitizeId(workspaceIdentifier: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier): string {
|
||||
if (isSingleFolderWorkspaceIdentifier(workspaceIdentifier)) {
|
||||
return this.sanitizePath(workspaceIdentifier);
|
||||
}
|
||||
|
||||
return workspaceIdentifier.id;
|
||||
}
|
||||
|
||||
protected loadSync(): void {
|
||||
let backups: IBackupWorkspacesFormat;
|
||||
try {
|
||||
backups = JSON.parse(fs.readFileSync(this.workspacesJsonPath, 'utf8').toString()); // invalid JSON or permission issue can happen here
|
||||
} catch (error) {
|
||||
backups = Object.create(null);
|
||||
}
|
||||
|
||||
// Ensure rootWorkspaces is a object[]
|
||||
if (backups.rootWorkspaces) {
|
||||
const rws = backups.rootWorkspaces;
|
||||
if (!Array.isArray(rws) || rws.some(r => typeof r !== 'object')) {
|
||||
backups.rootWorkspaces = [];
|
||||
}
|
||||
} else {
|
||||
backups.rootWorkspaces = [];
|
||||
}
|
||||
|
||||
// Ensure folderWorkspaces is a string[]
|
||||
if (backups.folderWorkspaces) {
|
||||
const fws = backups.folderWorkspaces;
|
||||
if (!Array.isArray(fws) || fws.some(f => typeof f !== 'string')) {
|
||||
backups.folderWorkspaces = [];
|
||||
}
|
||||
} else {
|
||||
backups.folderWorkspaces = [];
|
||||
}
|
||||
|
||||
// Ensure emptyWorkspaces is a string[]
|
||||
if (backups.emptyWorkspaces) {
|
||||
const fws = backups.emptyWorkspaces;
|
||||
if (!Array.isArray(fws) || fws.some(f => typeof f !== 'string')) {
|
||||
backups.emptyWorkspaces = [];
|
||||
}
|
||||
} else {
|
||||
backups.emptyWorkspaces = [];
|
||||
}
|
||||
|
||||
this.backups = this.dedupeBackups(backups);
|
||||
|
||||
// Validate backup workspaces
|
||||
this.validateBackupWorkspaces(backups);
|
||||
}
|
||||
|
||||
protected dedupeBackups(backups: IBackupWorkspacesFormat): IBackupWorkspacesFormat {
|
||||
|
||||
// De-duplicate folder/workspace backups. don't worry about cleaning them up any duplicates as
|
||||
// they will be removed when there are no backups.
|
||||
backups.folderWorkspaces = arrays.distinct(backups.folderWorkspaces, ws => this.sanitizePath(ws));
|
||||
backups.rootWorkspaces = arrays.distinct(backups.rootWorkspaces, ws => this.sanitizePath(ws.id));
|
||||
|
||||
return backups;
|
||||
}
|
||||
|
||||
private validateBackupWorkspaces(backups: IBackupWorkspacesFormat): void {
|
||||
const staleBackupWorkspaces: { workspaceIdentifier: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier; backupPath: string; target: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)[] }[] = [];
|
||||
|
||||
const workspaceAndFolders: { workspaceIdentifier: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier, target: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)[] }[] = [];
|
||||
workspaceAndFolders.push(...backups.rootWorkspaces.map(r => ({ workspaceIdentifier: r, target: backups.rootWorkspaces })));
|
||||
workspaceAndFolders.push(...backups.folderWorkspaces.map(f => ({ workspaceIdentifier: f, target: backups.folderWorkspaces })));
|
||||
|
||||
// Validate Workspace and Folder Backups
|
||||
workspaceAndFolders.forEach(workspaceOrFolder => {
|
||||
const workspaceId = workspaceOrFolder.workspaceIdentifier;
|
||||
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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Validate Empty Windows
|
||||
backups.emptyWorkspaces.forEach(backupFolder => {
|
||||
const backupPath = path.join(this.backupHome, backupFolder);
|
||||
if (!this.hasBackupsSync(backupPath)) {
|
||||
staleBackupWorkspaces.push({ workspaceIdentifier: backupFolder, backupPath, target: backups.emptyWorkspaces });
|
||||
}
|
||||
});
|
||||
|
||||
// Clean up stale backups
|
||||
staleBackupWorkspaces.forEach(staleBackupWorkspace => {
|
||||
const { backupPath, workspaceIdentifier, target } = staleBackupWorkspace;
|
||||
|
||||
try {
|
||||
extfs.delSync(backupPath);
|
||||
} catch (ex) {
|
||||
this.logService.error(`Backup: Could not delete stale backup: ${ex.toString()}`);
|
||||
}
|
||||
|
||||
this.removeBackupPathSync(workspaceIdentifier, target);
|
||||
});
|
||||
}
|
||||
|
||||
private hasBackupsSync(backupPath: string): boolean {
|
||||
try {
|
||||
const backupSchemas = extfs.readdirSync(backupPath);
|
||||
if (backupSchemas.length === 0) {
|
||||
return false; // empty backups
|
||||
}
|
||||
|
||||
return backupSchemas.some(backupSchema => {
|
||||
try {
|
||||
return extfs.readdirSync(path.join(backupPath, backupSchema)).length > 0;
|
||||
} catch (error) {
|
||||
return false; // invalid folder
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
return false; // backup path does not exist
|
||||
}
|
||||
}
|
||||
|
||||
private saveSync(): void {
|
||||
try {
|
||||
// The user data directory must exist so only the Backup directory needs to be checked.
|
||||
if (!fs.existsSync(this.backupHome)) {
|
||||
fs.mkdirSync(this.backupHome);
|
||||
}
|
||||
|
||||
fs.writeFileSync(this.workspacesJsonPath, JSON.stringify(this.backups));
|
||||
} catch (ex) {
|
||||
this.logService.error(`Backup: Could not save workspaces.json: ${ex.toString()}`);
|
||||
}
|
||||
}
|
||||
|
||||
private getRandomEmptyWindowId(): string {
|
||||
return (Date.now() + Math.round(Math.random() * 1000)).toString();
|
||||
}
|
||||
|
||||
private sanitizePath(p: string): string {
|
||||
return platform.isLinux ? p : p.toLowerCase();
|
||||
}
|
||||
|
||||
protected getFolderHash(folderPath: string): string {
|
||||
return crypto.createHash('md5').update(this.sanitizePath(folderPath)).digest('hex');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,595 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as platform from 'vs/base/common/platform';
|
||||
import fs = require('fs');
|
||||
import os = require('os');
|
||||
import path = require('path');
|
||||
import extfs = require('vs/base/node/extfs');
|
||||
import pfs = require('vs/base/node/pfs');
|
||||
import 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 { HotExitConfiguration } from 'vs/platform/files/common/files';
|
||||
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
|
||||
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';
|
||||
|
||||
suite('BackupMainService', () => {
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', 'service');
|
||||
const backupHome = path.join(parentDir, 'Backups');
|
||||
const backupWorkspacesPath = path.join(backupHome, 'workspaces.json');
|
||||
|
||||
const environmentService = new EnvironmentService(parseArgs(process.argv), process.execPath);
|
||||
const logService = new LogMainService(environmentService);
|
||||
|
||||
class TestBackupMainService extends BackupMainService {
|
||||
|
||||
constructor(backupHome: string, backupWorkspacesPath: string, configService: TestConfigurationService) {
|
||||
super(environmentService, configService, new LogMainService(environmentService), new WorkspacesMainService(environmentService, logService));
|
||||
|
||||
this.backupHome = backupHome;
|
||||
this.workspacesJsonPath = backupWorkspacesPath;
|
||||
|
||||
// Force a reload with the new paths
|
||||
this.loadSync();
|
||||
}
|
||||
|
||||
public get backupsData(): IBackupWorkspacesFormat {
|
||||
return this.backups;
|
||||
}
|
||||
|
||||
public removeBackupPathSync(workspaceIdentifier: string | IWorkspaceIdentifier, target: (string | IWorkspaceIdentifier)[]): void {
|
||||
return super.removeBackupPathSync(workspaceIdentifier, target);
|
||||
}
|
||||
|
||||
public loadSync(): void {
|
||||
super.loadSync();
|
||||
}
|
||||
|
||||
public dedupeBackups(backups: IBackupWorkspacesFormat): IBackupWorkspacesFormat {
|
||||
return super.dedupeBackups(backups);
|
||||
}
|
||||
|
||||
public toBackupPath(workspacePath: string): string {
|
||||
return path.join(this.backupHome, super.getFolderHash(workspacePath));
|
||||
}
|
||||
|
||||
public getFolderHash(folderPath: string): string {
|
||||
return super.getFolderHash(folderPath);
|
||||
}
|
||||
}
|
||||
|
||||
function toWorkspace(path: string): IWorkspaceIdentifier {
|
||||
return {
|
||||
id: createHash('md5').update(sanitizePath(path)).digest('hex'),
|
||||
configPath: path
|
||||
};
|
||||
}
|
||||
|
||||
function sanitizePath(p: string): string {
|
||||
return platform.isLinux ? p : p.toLowerCase();
|
||||
}
|
||||
|
||||
const fooFile = Uri.file(platform.isWindows ? 'C:\\foo' : '/foo');
|
||||
const barFile = Uri.file(platform.isWindows ? 'C:\\bar' : '/bar');
|
||||
|
||||
let service: TestBackupMainService;
|
||||
let configService: TestConfigurationService;
|
||||
|
||||
setup(done => {
|
||||
configService = new TestConfigurationService();
|
||||
service = new TestBackupMainService(backupHome, backupWorkspacesPath, configService);
|
||||
|
||||
// Delete any existing backups completely and then re-create it.
|
||||
extfs.del(backupHome, os.tmpdir(), () => {
|
||||
pfs.mkdirp(backupHome).then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
teardown(done => {
|
||||
extfs.del(backupHome, os.tmpdir(), done);
|
||||
});
|
||||
|
||||
test('service validates backup workspaces on startup and cleans up (folder workspaces)', done => {
|
||||
|
||||
// 1) backup workspace path does not exist
|
||||
service.registerFolderBackupSync(fooFile.fsPath);
|
||||
service.registerFolderBackupSync(barFile.fsPath);
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getFolderBackupPaths(), []);
|
||||
|
||||
// 2) backup workspace path exists with empty contents within
|
||||
fs.mkdirSync(service.toBackupPath(fooFile.fsPath));
|
||||
fs.mkdirSync(service.toBackupPath(barFile.fsPath));
|
||||
service.registerFolderBackupSync(fooFile.fsPath);
|
||||
service.registerFolderBackupSync(barFile.fsPath);
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getFolderBackupPaths(), []);
|
||||
assert.ok(!fs.exists(service.toBackupPath(fooFile.fsPath)));
|
||||
assert.ok(!fs.exists(service.toBackupPath(barFile.fsPath)));
|
||||
|
||||
// 3) backup workspace path exists with empty folders within
|
||||
fs.mkdirSync(service.toBackupPath(fooFile.fsPath));
|
||||
fs.mkdirSync(service.toBackupPath(barFile.fsPath));
|
||||
fs.mkdirSync(path.join(service.toBackupPath(fooFile.fsPath), 'file'));
|
||||
fs.mkdirSync(path.join(service.toBackupPath(barFile.fsPath), 'untitled'));
|
||||
service.registerFolderBackupSync(fooFile.fsPath);
|
||||
service.registerFolderBackupSync(barFile.fsPath);
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getFolderBackupPaths(), []);
|
||||
assert.ok(!fs.exists(service.toBackupPath(fooFile.fsPath)));
|
||||
assert.ok(!fs.exists(service.toBackupPath(barFile.fsPath)));
|
||||
|
||||
// 4) backup workspace path points to a workspace that no longer exists
|
||||
// so it should convert the backup worspace to an empty workspace backup
|
||||
const fileBackups = path.join(service.toBackupPath(fooFile.fsPath), 'file');
|
||||
fs.mkdirSync(service.toBackupPath(fooFile.fsPath));
|
||||
fs.mkdirSync(service.toBackupPath(barFile.fsPath));
|
||||
fs.mkdirSync(fileBackups);
|
||||
service.registerFolderBackupSync(fooFile.fsPath);
|
||||
assert.equal(service.getFolderBackupPaths().length, 1);
|
||||
assert.equal(service.getEmptyWindowBackupPaths().length, 0);
|
||||
fs.writeFileSync(path.join(fileBackups, 'backup.txt'), '');
|
||||
service.loadSync();
|
||||
assert.equal(service.getFolderBackupPaths().length, 0);
|
||||
assert.equal(service.getEmptyWindowBackupPaths().length, 1);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
test('service validates backup workspaces on startup and cleans up (root workspaces)', done => {
|
||||
|
||||
// 1) backup workspace path does not exist
|
||||
service.registerWorkspaceBackupSync(toWorkspace(fooFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspace(barFile.fsPath));
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
|
||||
// 2) backup workspace path exists with empty contents within
|
||||
fs.mkdirSync(service.toBackupPath(fooFile.fsPath));
|
||||
fs.mkdirSync(service.toBackupPath(barFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspace(fooFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspace(barFile.fsPath));
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.ok(!fs.exists(service.toBackupPath(fooFile.fsPath)));
|
||||
assert.ok(!fs.exists(service.toBackupPath(barFile.fsPath)));
|
||||
|
||||
// 3) backup workspace path exists with empty folders within
|
||||
fs.mkdirSync(service.toBackupPath(fooFile.fsPath));
|
||||
fs.mkdirSync(service.toBackupPath(barFile.fsPath));
|
||||
fs.mkdirSync(path.join(service.toBackupPath(fooFile.fsPath), 'file'));
|
||||
fs.mkdirSync(path.join(service.toBackupPath(barFile.fsPath), 'untitled'));
|
||||
service.registerWorkspaceBackupSync(toWorkspace(fooFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspace(barFile.fsPath));
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
assert.ok(!fs.exists(service.toBackupPath(fooFile.fsPath)));
|
||||
assert.ok(!fs.exists(service.toBackupPath(barFile.fsPath)));
|
||||
|
||||
// 4) backup workspace path points to a workspace that no longer exists
|
||||
// so it should convert the backup worspace to an empty workspace backup
|
||||
const fileBackups = path.join(service.toBackupPath(fooFile.fsPath), 'file');
|
||||
fs.mkdirSync(service.toBackupPath(fooFile.fsPath));
|
||||
fs.mkdirSync(service.toBackupPath(barFile.fsPath));
|
||||
fs.mkdirSync(fileBackups);
|
||||
service.registerWorkspaceBackupSync(toWorkspace(fooFile.fsPath));
|
||||
assert.equal(service.getWorkspaceBackups().length, 1);
|
||||
assert.equal(service.getEmptyWindowBackupPaths().length, 0);
|
||||
fs.writeFileSync(path.join(fileBackups, 'backup.txt'), '');
|
||||
service.loadSync();
|
||||
assert.equal(service.getWorkspaceBackups().length, 0);
|
||||
assert.equal(service.getEmptyWindowBackupPaths().length, 1);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
test('service supports to migrate backup data from another location', done => {
|
||||
const backupPathToMigrate = service.toBackupPath(fooFile.fsPath);
|
||||
fs.mkdirSync(backupPathToMigrate);
|
||||
fs.writeFileSync(path.join(backupPathToMigrate, 'backup.txt'), 'Some Data');
|
||||
service.registerFolderBackupSync(backupPathToMigrate);
|
||||
|
||||
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));
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
suite('loadSync', () => {
|
||||
test('getFolderBackupPaths() should return [] when workspaces.json doesn\'t exist', () => {
|
||||
assert.deepEqual(service.getFolderBackupPaths(), []);
|
||||
});
|
||||
|
||||
test('getFolderBackupPaths() should return [] when workspaces.json is not properly formed JSON', () => {
|
||||
fs.writeFileSync(backupWorkspacesPath, '');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getFolderBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{]');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getFolderBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, 'foo');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getFolderBackupPaths(), []);
|
||||
});
|
||||
|
||||
test('getFolderBackupPaths() should return [] when folderWorkspaces in workspaces.json is absent', () => {
|
||||
fs.writeFileSync(backupWorkspacesPath, '{}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getFolderBackupPaths(), []);
|
||||
});
|
||||
|
||||
test('getFolderBackupPaths() should return [] when folderWorkspaces in workspaces.json is not a string array', () => {
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"folderWorkspaces":{}}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getFolderBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"folderWorkspaces":{"foo": ["bar"]}}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getFolderBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"folderWorkspaces":{"foo": []}}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getFolderBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"folderWorkspaces":{"foo": "bar"}}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getFolderBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"folderWorkspaces":"foo"}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getFolderBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"folderWorkspaces":1}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getFolderBackupPaths(), []);
|
||||
});
|
||||
|
||||
test('getFolderBackupPaths() should return [] when files.hotExit = "onExitAndWindowClose"', () => {
|
||||
service.registerFolderBackupSync(fooFile.fsPath.toUpperCase());
|
||||
assert.deepEqual(service.getFolderBackupPaths(), [fooFile.fsPath.toUpperCase()]);
|
||||
configService.setUserConfiguration('files.hotExit', HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE);
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getFolderBackupPaths(), []);
|
||||
});
|
||||
|
||||
test('getWorkspaceBackups() should return [] when workspaces.json doesn\'t exist', () => {
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
});
|
||||
|
||||
test('getWorkspaceBackups() should return [] when workspaces.json is not properly formed JSON', () => {
|
||||
fs.writeFileSync(backupWorkspacesPath, '');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{]');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, 'foo');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
});
|
||||
|
||||
test('getWorkspaceBackups() should return [] when folderWorkspaces in workspaces.json is absent', () => {
|
||||
fs.writeFileSync(backupWorkspacesPath, '{}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
});
|
||||
|
||||
test('getWorkspaceBackups() should return [] when rootWorkspaces in workspaces.json is not a object array', () => {
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootWorkspaces":{}}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootWorkspaces":{"foo": ["bar"]}}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootWorkspaces":{"foo": []}}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootWorkspaces":{"foo": "bar"}}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootWorkspaces":"foo"}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"rootWorkspaces":1}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
});
|
||||
|
||||
test('getWorkspaceBackups() should return [] when files.hotExit = "onExitAndWindowClose"', () => {
|
||||
service.registerWorkspaceBackupSync(toWorkspace(fooFile.fsPath.toUpperCase()));
|
||||
assert.equal(service.getWorkspaceBackups().length, 1);
|
||||
assert.deepEqual(service.getWorkspaceBackups().map(r => r.configPath), [fooFile.fsPath.toUpperCase()]);
|
||||
configService.setUserConfiguration('files.hotExit', HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE);
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getWorkspaceBackups(), []);
|
||||
});
|
||||
|
||||
test('getEmptyWorkspaceBackupPaths() should return [] when workspaces.json doesn\'t exist', () => {
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
});
|
||||
|
||||
test('getEmptyWorkspaceBackupPaths() should return [] when workspaces.json is not properly formed JSON', () => {
|
||||
fs.writeFileSync(backupWorkspacesPath, '');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{]');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, 'foo');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
});
|
||||
|
||||
test('getEmptyWorkspaceBackupPaths() should return [] when folderWorkspaces in workspaces.json is absent', () => {
|
||||
fs.writeFileSync(backupWorkspacesPath, '{}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
});
|
||||
|
||||
test('getEmptyWorkspaceBackupPaths() should return [] when folderWorkspaces in workspaces.json is not a string array', () => {
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"emptyWorkspaces":{}}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"emptyWorkspaces":{"foo": ["bar"]}}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"emptyWorkspaces":{"foo": []}}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"emptyWorkspaces":{"foo": "bar"}}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"emptyWorkspaces":"foo"}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
fs.writeFileSync(backupWorkspacesPath, '{"emptyWorkspaces":1}');
|
||||
service.loadSync();
|
||||
assert.deepEqual(service.getEmptyWindowBackupPaths(), []);
|
||||
});
|
||||
});
|
||||
|
||||
suite('dedupeFolderWorkspaces', () => {
|
||||
test('should ignore duplicates on Windows and Mac (folder workspace)', () => {
|
||||
// Skip test on Linux
|
||||
if (platform.isLinux) {
|
||||
return;
|
||||
}
|
||||
|
||||
const backups: IBackupWorkspacesFormat = {
|
||||
rootWorkspaces: [],
|
||||
folderWorkspaces: platform.isWindows ? ['c:\\FOO', 'C:\\FOO', 'c:\\foo'] : ['/FOO', '/foo'],
|
||||
emptyWorkspaces: []
|
||||
};
|
||||
|
||||
service.dedupeBackups(backups);
|
||||
|
||||
assert.equal(backups.folderWorkspaces.length, 1);
|
||||
if (platform.isWindows) {
|
||||
assert.deepEqual(backups.folderWorkspaces, ['c:\\FOO'], 'should return the first duplicated entry');
|
||||
} else {
|
||||
assert.deepEqual(backups.folderWorkspaces, ['/FOO'], 'should return the first duplicated entry');
|
||||
}
|
||||
});
|
||||
|
||||
test('should ignore duplicates on Windows and Mac (root workspace)', () => {
|
||||
// Skip test on Linux
|
||||
if (platform.isLinux) {
|
||||
return;
|
||||
}
|
||||
|
||||
const backups: IBackupWorkspacesFormat = {
|
||||
rootWorkspaces: platform.isWindows ? [toWorkspace('c:\\FOO'), toWorkspace('C:\\FOO'), toWorkspace('c:\\foo')] : [toWorkspace('/FOO'), toWorkspace('/foo')],
|
||||
folderWorkspaces: [],
|
||||
emptyWorkspaces: []
|
||||
};
|
||||
|
||||
service.dedupeBackups(backups);
|
||||
|
||||
assert.equal(backups.rootWorkspaces.length, 1);
|
||||
if (platform.isWindows) {
|
||||
assert.deepEqual(backups.rootWorkspaces.map(r => r.configPath), ['c:\\FOO'], 'should return the first duplicated entry');
|
||||
} else {
|
||||
assert.deepEqual(backups.rootWorkspaces.map(r => r.configPath), ['/FOO'], 'should return the first duplicated entry');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
suite('registerWindowForBackups', () => {
|
||||
test('should persist paths to workspaces.json (folder workspace)', done => {
|
||||
service.registerFolderBackupSync(fooFile.fsPath);
|
||||
service.registerFolderBackupSync(barFile.fsPath);
|
||||
assert.deepEqual(service.getFolderBackupPaths(), [fooFile.fsPath, barFile.fsPath]);
|
||||
pfs.readFile(backupWorkspacesPath, 'utf-8').then(buffer => {
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
|
||||
assert.deepEqual(json.folderWorkspaces, [fooFile.fsPath, barFile.fsPath]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('should persist paths to workspaces.json (root workspace)', done => {
|
||||
const ws1 = toWorkspace(fooFile.fsPath);
|
||||
service.registerWorkspaceBackupSync(ws1);
|
||||
const ws2 = toWorkspace(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);
|
||||
|
||||
pfs.readFile(backupWorkspacesPath, 'utf-8').then(buffer => {
|
||||
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);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('should always store the workspace path in workspaces.json using the case given, regardless of whether the file system is case-sensitive (folder workspace)', done => {
|
||||
service.registerFolderBackupSync(fooFile.fsPath.toUpperCase());
|
||||
assert.deepEqual(service.getFolderBackupPaths(), [fooFile.fsPath.toUpperCase()]);
|
||||
pfs.readFile(backupWorkspacesPath, 'utf-8').then(buffer => {
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
|
||||
assert.deepEqual(json.folderWorkspaces, [fooFile.fsPath.toUpperCase()]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
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)', done => {
|
||||
service.registerWorkspaceBackupSync(toWorkspace(fooFile.fsPath.toUpperCase()));
|
||||
assert.deepEqual(service.getWorkspaceBackups().map(b => b.configPath), [fooFile.fsPath.toUpperCase()]);
|
||||
pfs.readFile(backupWorkspacesPath, 'utf-8').then(buffer => {
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
|
||||
assert.deepEqual(json.rootWorkspaces.map(b => b.configPath), [fooFile.fsPath.toUpperCase()]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('removeBackupPathSync', () => {
|
||||
test('should remove folder workspaces from workspaces.json (folder workspace)', done => {
|
||||
service.registerFolderBackupSync(fooFile.fsPath);
|
||||
service.registerFolderBackupSync(barFile.fsPath);
|
||||
service.removeBackupPathSync(fooFile.fsPath, service.backupsData.folderWorkspaces);
|
||||
pfs.readFile(backupWorkspacesPath, 'utf-8').then(buffer => {
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
|
||||
assert.deepEqual(json.folderWorkspaces, [barFile.fsPath]);
|
||||
service.removeBackupPathSync(barFile.fsPath, service.backupsData.folderWorkspaces);
|
||||
pfs.readFile(backupWorkspacesPath, 'utf-8').then(content => {
|
||||
const json2 = <IBackupWorkspacesFormat>JSON.parse(content);
|
||||
assert.deepEqual(json2.folderWorkspaces, []);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should remove folder workspaces from workspaces.json (root workspace)', done => {
|
||||
const ws1 = toWorkspace(fooFile.fsPath);
|
||||
service.registerWorkspaceBackupSync(ws1);
|
||||
const ws2 = toWorkspace(barFile.fsPath);
|
||||
service.registerWorkspaceBackupSync(ws2);
|
||||
service.removeBackupPathSync(ws1, service.backupsData.rootWorkspaces);
|
||||
pfs.readFile(backupWorkspacesPath, 'utf-8').then(buffer => {
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
|
||||
assert.deepEqual(json.rootWorkspaces.map(r => r.configPath), [barFile.fsPath]);
|
||||
service.removeBackupPathSync(ws2, service.backupsData.rootWorkspaces);
|
||||
pfs.readFile(backupWorkspacesPath, 'utf-8').then(content => {
|
||||
const json2 = <IBackupWorkspacesFormat>JSON.parse(content);
|
||||
assert.deepEqual(json2.rootWorkspaces, []);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should remove empty workspaces from workspaces.json', done => {
|
||||
service.registerEmptyWindowBackupSync('foo');
|
||||
service.registerEmptyWindowBackupSync('bar');
|
||||
service.removeBackupPathSync('foo', service.backupsData.emptyWorkspaces);
|
||||
pfs.readFile(backupWorkspacesPath, 'utf-8').then(buffer => {
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(buffer);
|
||||
assert.deepEqual(json.emptyWorkspaces, ['bar']);
|
||||
service.removeBackupPathSync('bar', service.backupsData.emptyWorkspaces);
|
||||
pfs.readFile(backupWorkspacesPath, 'utf-8').then(content => {
|
||||
const json2 = <IBackupWorkspacesFormat>JSON.parse(content);
|
||||
assert.deepEqual(json2.emptyWorkspaces, []);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should fail gracefully when removing a path that doesn\'t exist', done => {
|
||||
const workspacesJson: IBackupWorkspacesFormat = { rootWorkspaces: [], folderWorkspaces: [fooFile.fsPath], emptyWorkspaces: [] };
|
||||
pfs.writeFile(backupWorkspacesPath, JSON.stringify(workspacesJson)).then(() => {
|
||||
service.removeBackupPathSync(barFile.fsPath, service.backupsData.folderWorkspaces);
|
||||
service.removeBackupPathSync('test', service.backupsData.emptyWorkspaces);
|
||||
pfs.readFile(backupWorkspacesPath, 'utf-8').then(content => {
|
||||
const json = <IBackupWorkspacesFormat>JSON.parse(content);
|
||||
assert.deepEqual(json.folderWorkspaces, [fooFile.fsPath]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('getWorkspaceHash', () => {
|
||||
test('should perform an md5 hash on the path', () => {
|
||||
assert.equal(service.getFolderHash('/foo'), '1effb2475fcfba4f9e8b8a1dbc8f3caf');
|
||||
});
|
||||
|
||||
test('should ignore case on Windows and Mac', () => {
|
||||
// Skip test on Linux
|
||||
if (platform.isLinux) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (platform.isMacintosh) {
|
||||
assert.equal(service.getFolderHash('/foo'), service.getFolderHash('/FOO'));
|
||||
}
|
||||
|
||||
if (platform.isWindows) {
|
||||
assert.equal(service.getFolderHash('c:\\foo'), service.getFolderHash('C:\\FOO'));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
suite('mixed path casing', () => {
|
||||
test('should handle case insensitive paths properly (registerWindowForBackupsSync) (folder workspace)', done => {
|
||||
service.registerFolderBackupSync(fooFile.fsPath);
|
||||
service.registerFolderBackupSync(fooFile.fsPath.toUpperCase());
|
||||
|
||||
if (platform.isLinux) {
|
||||
assert.equal(service.getFolderBackupPaths().length, 2);
|
||||
} else {
|
||||
assert.equal(service.getFolderBackupPaths().length, 1);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
test('should handle case insensitive paths properly (registerWindowForBackupsSync) (root workspace)', done => {
|
||||
service.registerWorkspaceBackupSync(toWorkspace(fooFile.fsPath));
|
||||
service.registerWorkspaceBackupSync(toWorkspace(fooFile.fsPath.toUpperCase()));
|
||||
|
||||
if (platform.isLinux) {
|
||||
assert.equal(service.getWorkspaceBackups().length, 2);
|
||||
} else {
|
||||
assert.equal(service.getWorkspaceBackups().length, 1);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
test('should handle case insensitive paths properly (removeBackupPathSync) (folder workspace)', done => {
|
||||
|
||||
// same case
|
||||
service.registerFolderBackupSync(fooFile.fsPath);
|
||||
service.removeBackupPathSync(fooFile.fsPath, service.backupsData.folderWorkspaces);
|
||||
assert.equal(service.getFolderBackupPaths().length, 0);
|
||||
|
||||
// mixed case
|
||||
service.registerFolderBackupSync(fooFile.fsPath);
|
||||
service.removeBackupPathSync(fooFile.fsPath.toUpperCase(), service.backupsData.folderWorkspaces);
|
||||
|
||||
if (platform.isLinux) {
|
||||
assert.equal(service.getFolderBackupPaths().length, 1);
|
||||
} else {
|
||||
assert.equal(service.getFolderBackupPaths().length, 0);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user