提交 60e70cbf 编写于 作者: S Sandeep Somavarapu

ExtensionHost: get storage path from storage service

上级 d85ee136
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
'use strict'; 'use strict';
import * as fs from 'fs'; import * as fs from 'fs';
import * as crypto from 'crypto';
import * as nls from 'vs/nls'; import * as nls from 'vs/nls';
import * as json from 'vs/base/common/json'; import * as json from 'vs/base/common/json';
import pkg from 'vs/platform/package'; import pkg from 'vs/platform/package';
...@@ -32,6 +31,7 @@ import { IExtensionsStorageData, ExtensionsStorageFile } from 'vs/platform/exten ...@@ -32,6 +31,7 @@ import { IExtensionsStorageData, ExtensionsStorageFile } from 'vs/platform/exten
import { ExtensionScanner, MessagesCollector } from 'vs/workbench/node/extensionPoints'; import { ExtensionScanner, MessagesCollector } from 'vs/workbench/node/extensionPoints';
import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc'; import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc';
import Event, { Emitter } from 'vs/base/common/event'; 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_LOG_BROADCAST_CHANNEL = 'vscode:extensionLog';
export const EXTENSION_ATTACH_BROADCAST_CHANNEL = 'vscode:extensionAttach'; export const EXTENSION_ATTACH_BROADCAST_CHANNEL = 'vscode:extensionAttach';
...@@ -61,8 +61,6 @@ export class ExtensionHostProcessWorker { ...@@ -61,8 +61,6 @@ export class ExtensionHostProcessWorker {
private isExtensionDevelopmentTestFromCli: boolean; private isExtensionDevelopmentTestFromCli: boolean;
private isExtensionDevelopmentDebugging: boolean; private isExtensionDevelopmentDebugging: boolean;
private workspaceStoragePath: string;
private _onMessage = new Emitter<any>(); private _onMessage = new Emitter<any>();
public get onMessage(): Event<any> { public get onMessage(): Event<any> {
return this._onMessage.event; return this._onMessage.event;
...@@ -74,7 +72,8 @@ export class ExtensionHostProcessWorker { ...@@ -74,7 +72,8 @@ export class ExtensionHostProcessWorker {
@IWindowService private windowService: IWindowService, @IWindowService private windowService: IWindowService,
@ILifecycleService lifecycleService: ILifecycleService, @ILifecycleService lifecycleService: ILifecycleService,
@IInstantiationService private instantiationService: IInstantiationService, @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 // handle extension host lifecycle a bit special when we know we are developing an extension that runs inside
this.isExtensionDevelopmentHost = !!environmentService.extensionDevelopmentPath; this.isExtensionDevelopmentHost = !!environmentService.extensionDevelopmentPath;
...@@ -221,7 +220,7 @@ export class ExtensionHostProcessWorker { ...@@ -221,7 +220,7 @@ export class ExtensionHostProcessWorker {
contextService: { contextService: {
workspace: this.contextService.getWorkspace() workspace: this.contextService.getWorkspace()
}, },
workspaceStoragePath: this.getOrCreateWorkspaceStoragePath(), workspaceStoragePath: this.storageService.getWorkspaceStoragePath(),
extensions: extensionDescriptors extensions: extensionDescriptors
}); });
this.extensionHostProcessHandle.send(initPayload); this.extensionHostProcessHandle.send(initPayload);
...@@ -280,7 +279,7 @@ export class ExtensionHostProcessWorker { ...@@ -280,7 +279,7 @@ export class ExtensionHostProcessWorker {
} }
private getWorkspaceDisabledExtensions(): TPromise<string[]> { private getWorkspaceDisabledExtensions(): TPromise<string[]> {
const workspaceStoragePath = this.getOrCreateWorkspaceStoragePath(); const workspaceStoragePath = this.storageService.getWorkspaceStoragePath();
if (!workspaceStoragePath) { if (!workspaceStoragePath) {
return TPromise.wrap([]); return TPromise.wrap([]);
} }
...@@ -432,57 +431,4 @@ export class ExtensionHostProcessWorker { ...@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册