提交 575a367a 编写于 作者: B Benjamin Pasero

storage - move meta data into storage service too

上级 523fc339
......@@ -15,7 +15,7 @@ import { IWindowService } from 'vs/platform/windows/common/windows';
import { localize } from 'vs/nls';
import { mark, getDuration } from 'vs/base/common/performance';
import { join } from 'path';
import { copy, exists, mkdirp, readdir } from 'vs/base/node/pfs';
import { copy, exists, mkdirp, readdir, writeFile } from 'vs/base/node/pfs';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IWorkspaceInitializationPayload, isWorkspaceIdentifier, isSingleFolderWorkspaceInitializationPayload } from 'vs/platform/workspaces/common/workspaces';
......@@ -31,6 +31,7 @@ export class StorageService extends Disposable implements IStorageService {
_serviceBrand: any;
private static WORKSPACE_STORAGE_NAME = 'storage.db';
private static WORKSPACE_META_NAME = 'workspace.json';
private _onDidChangeStorage: Emitter<IWorkspaceStorageChangeEvent> = this._register(new Emitter<IWorkspaceStorageChangeEvent>());
get onDidChangeStorage(): Event<IWorkspaceStorageChangeEvent> { return this._onDidChangeStorage.event; }
......@@ -300,10 +301,36 @@ export class StorageService extends Disposable implements IStorageService {
return { path: workspaceStorageFolderPath, wasCreated: false };
}
return mkdirp(workspaceStorageFolderPath).then(() => ({ path: workspaceStorageFolderPath, wasCreated: true }));
return mkdirp(workspaceStorageFolderPath).then(() => {
// Write metadata into folder
this.ensureWorkspaceStorageFolderMeta(payload);
return { path: workspaceStorageFolderPath, wasCreated: true };
});
});
}
private ensureWorkspaceStorageFolderMeta(payload: IWorkspaceInitializationPayload): void {
let meta: object;
if (isSingleFolderWorkspaceInitializationPayload(payload)) {
meta = { folder: payload.folder.toString() };
} else if (isWorkspaceIdentifier(payload)) {
meta = { configuration: payload.configPath };
}
if (meta) {
const workspaceStorageMetaPath = join(this.getWorkspaceStorageFolderPath(payload), StorageService.WORKSPACE_META_NAME);
exists(workspaceStorageMetaPath).then(exists => {
if (exists) {
return void 0; // already existing
}
return writeFile(workspaceStorageMetaPath, JSON.stringify(meta, void 0, 2));
}).then(null, error => onUnexpectedError(error));
}
}
get(key: string, scope: StorageScope, fallbackValue: string): string;
get(key: string, scope: StorageScope): string | undefined;
get(key: string, scope: StorageScope, fallbackValue?: string): string | undefined {
......
......@@ -132,6 +132,7 @@ export function toWorkspaceIdentifier(workspace: IWorkspace): IWorkspaceIdentifi
export type IMultiFolderWorkspaceInitializationPayload = IWorkspaceIdentifier;
export interface ISingleFolderWorkspaceInitializationPayload { id: string; folder: ISingleFolderWorkspaceIdentifier; }
export interface IEmptyWorkspaceInitializationPayload { id: string; }
export type IWorkspaceInitializationPayload = IMultiFolderWorkspaceInitializationPayload | ISingleFolderWorkspaceInitializationPayload | IEmptyWorkspaceInitializationPayload;
export function isSingleFolderWorkspaceInitializationPayload(obj: any): obj is ISingleFolderWorkspaceInitializationPayload {
......
......@@ -16,7 +16,7 @@ import { IWorkspaceContextService, Workspace, WorkbenchState } from 'vs/platform
import { WorkspaceService } from 'vs/workbench/services/configuration/node/configurationService';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { stat, exists, writeFile } from 'vs/base/node/pfs';
import { stat } from 'vs/base/node/pfs';
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
import * as gracefulFs from 'graceful-fs';
import { KeyboardMapperFactory } from 'vs/workbench/services/keybinding/electron-browser/keybindingService';
......@@ -44,7 +44,7 @@ import { MenubarChannelClient } from 'vs/platform/menubar/node/menubarIpc';
import { IMenubarService } from 'vs/platform/menubar/common/menubar';
import { Schemas } from 'vs/base/common/network';
import { sanitizeFilePath } from 'vs/base/node/extfs';
import { basename, join } from 'path';
import { basename } from 'path';
import { createHash } from 'crypto';
import { IdleValue } from 'vs/base/common/async';
import { setGlobalLeakWarningThreshold } from 'vs/base/common/event';
......@@ -136,11 +136,6 @@ function openWorkbench(configuration: IWindowConfiguration): Promise<void> {
storageService
}, mainServices, mainProcessClient, configuration);
// Store meta file in workspace storage after workbench is running
shell.onRunning(() => {
ensureWorkspaceStorageFolderMeta(payload, workspaceService, environmentService);
});
// Gracefully Shutdown Storage
shell.onShutdown(event => {
event.join(storageService.close());
......@@ -255,32 +250,6 @@ function createStorageService(payload: IWorkspaceInitializationPayload, environm
});
}
function getWorkspaceStoragePath(payload: IWorkspaceInitializationPayload, environmentService: IEnvironmentService): string {
return join(environmentService.workspaceStorageHome, payload.id); // workspace home + workspace id;
}
function ensureWorkspaceStorageFolderMeta(payload: IWorkspaceInitializationPayload, workspaceService: IWorkspaceContextService, environmentService: IEnvironmentService): void {
const state = workspaceService.getWorkbenchState();
if (state === WorkbenchState.EMPTY) {
return; // no storage meta for empty workspaces
}
const workspaceStorageMetaPath = join(getWorkspaceStoragePath(payload, environmentService), 'workspace.json');
exists(workspaceStorageMetaPath).then(exists => {
if (exists) {
return void 0; // already existing
}
const workspace = workspaceService.getWorkspace();
return writeFile(workspaceStorageMetaPath, JSON.stringify({
configuration: workspace.configuration ? uri.revive(workspace.configuration).toString() : void 0,
folder: state === WorkbenchState.FOLDER ? uri.revive(workspace.folders[0].uri).toString() : void 0
}, undefined, 2));
}).then(null, error => onUnexpectedError(error));
}
function createStorageLegacyService(workspaceService: IWorkspaceContextService, environmentService: IEnvironmentService): IStorageLegacyService {
let workspaceId: string;
......
......@@ -126,9 +126,6 @@ export class WorkbenchShell extends Disposable {
private readonly _onShutdown = this._register(new Emitter<ShutdownEvent>());
get onShutdown(): Event<ShutdownEvent> { return this._onShutdown.event; }
private readonly _onRunning = this._register(new Emitter<void>());
get onRunning(): Event<void> { return this._onRunning.event; }
private storageService: DelegatingStorageService;
private environmentService: IEnvironmentService;
private logService: ILogService;
......@@ -217,10 +214,8 @@ export class WorkbenchShell extends Disposable {
// Startup Workbench
workbench.startup().then(startupInfos => {
// Set lifecycle phase to `Runnning` so that other contributions can
// now do something we also emit this as event to interested parties outside
// Set lifecycle phase to `Runnning`
this.lifecycleService.phase = LifecyclePhase.Running;
this._onRunning.fire();
// Startup Telemetry
this.logStartupTelemetry(startupInfos);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册