diff --git a/src/vs/workbench/electron-browser/extensionHost.ts b/src/vs/workbench/electron-browser/extensionHost.ts index ee47acfcec0d1223cab1cb4c524e2b693b3237e1..b377b393427e37a539837d399360e5d2930d45c8 100644 --- a/src/vs/workbench/electron-browser/extensionHost.ts +++ b/src/vs/workbench/electron-browser/extensionHost.ts @@ -6,7 +6,6 @@ 'use strict'; import * as fs from 'fs'; -import * as crypto from 'crypto'; import * as nls from 'vs/nls'; import * as json from 'vs/base/common/json'; import pkg from 'vs/platform/package'; @@ -32,6 +31,7 @@ import { IExtensionsStorageData, ExtensionsStorageFile } from 'vs/platform/exten import { ExtensionScanner, MessagesCollector } from 'vs/workbench/node/extensionPoints'; import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc'; import Event, { Emitter } from 'vs/base/common/event'; +import { IStorageService } from 'vs/platform/storage/common/storage'; export const EXTENSION_LOG_BROADCAST_CHANNEL = 'vscode:extensionLog'; export const EXTENSION_ATTACH_BROADCAST_CHANNEL = 'vscode:extensionAttach'; @@ -61,8 +61,6 @@ export class ExtensionHostProcessWorker { private isExtensionDevelopmentTestFromCli: boolean; private isExtensionDevelopmentDebugging: boolean; - private workspaceStoragePath: string; - private _onMessage = new Emitter(); public get onMessage(): Event { return this._onMessage.event; @@ -74,7 +72,8 @@ export class ExtensionHostProcessWorker { @IWindowService private windowService: IWindowService, @ILifecycleService lifecycleService: ILifecycleService, @IInstantiationService private instantiationService: IInstantiationService, - @IEnvironmentService private environmentService: IEnvironmentService + @IEnvironmentService private environmentService: IEnvironmentService, + @IStorageService private storageService: IStorageService ) { // handle extension host lifecycle a bit special when we know we are developing an extension that runs inside this.isExtensionDevelopmentHost = !!environmentService.extensionDevelopmentPath; @@ -221,7 +220,7 @@ export class ExtensionHostProcessWorker { contextService: { workspace: this.contextService.getWorkspace() }, - workspaceStoragePath: this.getOrCreateWorkspaceStoragePath(), + workspaceStoragePath: this.storageService.getWorkspaceStoragePath(), extensions: extensionDescriptors }); this.extensionHostProcessHandle.send(initPayload); @@ -280,7 +279,7 @@ export class ExtensionHostProcessWorker { } private getWorkspaceDisabledExtensions(): TPromise { - const workspaceStoragePath = this.getOrCreateWorkspaceStoragePath(); + const workspaceStoragePath = this.storageService.getWorkspaceStoragePath(); if (!workspaceStoragePath) { return TPromise.wrap([]); } @@ -432,57 +431,4 @@ export class ExtensionHostProcessWorker { } } } - - private getOrCreateWorkspaceStoragePath(): string { - const workspace = this.contextService.getWorkspace(); - - if (!workspace) { - return void 0; - } - - if (this.workspaceStoragePath) { - return this.workspaceStoragePath; - } - - 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()); - } - this.workspaceStoragePath = paths.join(this.environmentService.appSettingsHome, 'workspaceStorage', hash.digest('hex')); - if (!fs.existsSync(this.workspaceStoragePath)) { - try { - if (rmkDir(this.workspaceStoragePath)) { - fs.writeFileSync(paths.join(this.workspaceStoragePath, 'meta.json'), JSON.stringify({ - workspacePath: workspace.resource.fsPath, - uid: workspace.uid ? workspace.uid : null - }, null, 4)); - } else { - this.workspaceStoragePath = void 0; - } - } catch (err) { - this.workspaceStoragePath = void 0; - } - } - } - - return this.workspaceStoragePath; - } } \ No newline at end of file