Changed the way we init default locations.

For the `data` and `downloads`.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2019-05-08 12:32:19 +02:00 committed by Christian Weichel
parent bfb0edf50c
commit d346b81331
3 changed files with 4 additions and 41 deletions

View File

@ -1,5 +1,4 @@
import { inject, injectable } from 'inversify';
import URI from '@theia/core/lib/common/uri';
import { FileSystem } from '@theia/filesystem/lib/common';
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
import { WorkspaceServiceExt } from './workspace-service-ext';
@ -21,27 +20,4 @@ export class WorkspaceServiceExtImpl implements WorkspaceServiceExt {
return stats.map(stat => stat.uri);
}
async defaultWorkspaceUri(): Promise<string> {
const home = await this.fileSystem.getCurrentUserHome();
if (home) {
return new URI(home.uri).resolve('Arduino-PoC').resolve('workspace').toString();
}
throw new Error(`Could not locate current user's home folder.`);
}
async defaultDownloadsDirUri(): Promise<string> {
const home = await this.fileSystem.getCurrentUserHome();
if (home) {
return new URI(home.uri).resolve('Arduino-PoC').resolve('downloads').toString();
}
throw new Error(`Could not locate current user's home folder.`);
}
async defaultDataDirUri(): Promise<string> {
const home = await this.fileSystem.getCurrentUserHome();
if (home) {
return new URI(home.uri).resolve('Arduino-PoC').resolve('data').toString();
}
throw new Error(`Could not locate current user's home folder.`);
}
}

View File

@ -2,11 +2,4 @@ export const WorkspaceServiceExtPath = '/services/workspace-service-ext';
export const WorkspaceServiceExt = Symbol('WorkspaceServiceExt');
export interface WorkspaceServiceExt {
roots(): Promise<string[]>;
/**
* By default it is under `~/Arduino-PoC/workspace`.
* It might not exist yet.
*/
defaultWorkspaceUri(): Promise<string>;
defaultDownloadsDirUri(): Promise<string>;
defaultDataDirUri(): Promise<string>;
}

View File

@ -10,6 +10,8 @@ import * as PQueue from 'p-queue';
import { ToolOutputServiceServer } from '../common/protocol/tool-output-service';
import { Instance } from './cli-protocol/common_pb';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as os from 'os';
@injectable()
export class CoreClientProviderImpl implements CoreClientProvider {
@ -66,20 +68,12 @@ export class CoreClientProviderImpl implements CoreClientProvider {
throw new Error(`Could not resolve filesystem path of URI: ${rootUri}.`);
}
const defaultDownloadsDirUri = await this.workspaceServiceExt.defaultDownloadsDirUri();
const defaultDownloadsDirPath = await this.fileSystem.getFsPath(defaultDownloadsDirUri);
if (!defaultDownloadsDirPath) {
throw new Error(`Could not resolve filesystem path of URI: ${defaultDownloadsDirUri}.`);
}
const defaultDownloadsDirPath = path.resolve(os.homedir(), 'Arduino-PoC', 'downloads');
if (!fs.existsSync(defaultDownloadsDirPath)) {
fs.mkdirpSync(defaultDownloadsDirPath);
}
const defaultDataDirUri = await this.workspaceServiceExt.defaultDataDirUri();
const defaultDataDirPath = await this.fileSystem.getFsPath(defaultDataDirUri);
if (!defaultDataDirPath) {
throw new Error(`Could not resolve filesystem path of URI: ${defaultDataDirUri}.`);
}
const defaultDataDirPath = path.resolve(os.homedir(), 'Arduino-PoC', 'data')
if (!fs.existsSync(defaultDataDirPath)) {
fs.mkdirpSync(defaultDataDirPath);
}