This commit is contained in:
Sandeep Somavarapu
2016-10-11 18:23:04 +02:00
parent 34d582ebb1
commit 4ef0081b7f
3 changed files with 102 additions and 53 deletions

View File

@@ -5,9 +5,6 @@
'use strict';
import * as fs from 'fs';
import * as crypto from 'crypto';
import nls = require('vs/nls');
import pfs = require('vs/base/node/pfs');
import { TPromise } from 'vs/base/common/winjs.base';
@@ -38,6 +35,7 @@ export interface IInitData {
options: any;
};
extensions: IExtensionDescription[];
workspaceStoragePath: string;
}
const nativeExit = process.exit.bind(process);
@@ -68,7 +66,8 @@ export class ExtensionHostMain {
this._extensions = initData.extensions;
this._contextService = new WorkspaceContextService(initData.contextService.workspace);
const workspaceStoragePath = this._getOrCreateWorkspaceStoragePath();
const workspaceStoragePath = initData.workspaceStoragePath;
console.log(workspaceStoragePath);
const threadService = new ExtHostThreadService(remoteCom);
@@ -80,53 +79,6 @@ export class ExtensionHostMain {
defineAPI(new ExtHostAPIImplementation(threadService, this._extensionService, this._contextService, telemetryService));
}
private _getOrCreateWorkspaceStoragePath(): string {
let workspaceStoragePath: string;
const workspace = this._contextService.getWorkspace();
function rmkDir(directory: string): boolean {
try {
fs.mkdirSync(directory);
return true;
} catch (err) {
if (err.code === 'ENOENT') {
if (rmkDir(paths.dirname(directory))) {
fs.mkdirSync(directory);
return true;
}
} else {
return fs.statSync(directory).isDirectory();
}
}
}
if (workspace) {
const hash = crypto.createHash('md5');
hash.update(workspace.resource.fsPath);
if (workspace.uid) {
hash.update(workspace.uid.toString());
}
workspaceStoragePath = paths.join(this._environment.appSettingsHome, 'workspaceStorage', hash.digest('hex'));
if (!fs.existsSync(workspaceStoragePath)) {
try {
if (rmkDir(workspaceStoragePath)) {
fs.writeFileSync(paths.join(workspaceStoragePath, 'meta.json'), JSON.stringify({
workspacePath: workspace.resource.fsPath,
uid: workspace.uid ? workspace.uid : null
}, null, 4));
} else {
workspaceStoragePath = undefined;
}
} catch (err) {
workspaceStoragePath = undefined;
}
}
}
return workspaceStoragePath;
}
public start(): TPromise<void> {
return this.registerExtensions();
}