diff --git a/apps/remix-ide/src/app/files/fileManager.js b/apps/remix-ide/src/app/files/fileManager.js index 2b5c7dbd04..d1838738e2 100644 --- a/apps/remix-ide/src/app/files/fileManager.js +++ b/apps/remix-ide/src/app/files/fileManager.js @@ -600,20 +600,6 @@ class FileManager extends Plugin { if (callback) callback(error) }) } - - async createWorkspace (name) { - const workspaceProvider = this._deps.filesProviders.workspace - const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name - const workspaceRootPath = 'browser/' + workspaceProvider.workspacesPath - if (!this.exists(workspaceRootPath)) await this.mkdir(workspaceRootPath) - if (!this.exists(workspacePath)) await this.mkdir(workspacePath) - } - - async workspaceExists (name) { - const workspaceProvider = this._deps.filesProviders.workspace - const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name - return this.exists(workspacePath) - } } module.exports = FileManager diff --git a/apps/remix-ide/src/app/files/fileProvider.js b/apps/remix-ide/src/app/files/fileProvider.js index 75e471ee83..adc5840dfd 100644 --- a/apps/remix-ide/src/app/files/fileProvider.js +++ b/apps/remix-ide/src/app/files/fileProvider.js @@ -66,7 +66,9 @@ class FileProvider { exists (path, cb) { // todo check the type (directory/file) as well #2386 // currently it is not possible to have a file and folder with same path - return cb(null, this._exists(path)) + const ret = this._exists(path) + if (cb) cb(null, ret) + return ret } _exists (path) { diff --git a/apps/remix-ide/src/app/panels/file-panel.js b/apps/remix-ide/src/app/panels/file-panel.js index 8bf74a6756..03a7283dd3 100644 --- a/apps/remix-ide/src/app/panels/file-panel.js +++ b/apps/remix-ide/src/app/panels/file-panel.js @@ -170,13 +170,30 @@ module.exports = class Filepanel extends ViewPlugin { return await this.request.uploadFile() } + async processCreateWorkspace (name) { + const workspaceProvider = this._deps.fileProviders.workspace + const browserProvider = this._deps.fileProviders.browser + const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name + const workspaceRootPath = 'browser/' + workspaceProvider.workspacesPath + if (!browserProvider.exists(workspaceRootPath)) browserProvider.createDir(workspaceRootPath) + if (!browserProvider.exists(workspacePath)) browserProvider.createDir(workspacePath) + } + + async workspaceExists (name) { + const workspaceProvider = this._deps.fileProviders.workspace + const browserProvider = this._deps.fileProviders.browser + const workspacePath = 'browser/' + workspaceProvider.workspacesPath + '/' + name + return browserProvider.exists(workspacePath) + } + async createWorkspace (workspaceName) { - if (await this._deps.fileManager.workspaceExists(workspaceName)) throw new Error('workspace already exists') + if (await this.workspaceExists(workspaceName)) throw new Error('workspace already exists') + const browserProvider = this._deps.fileProviders.browser const workspacesPath = this._deps.fileProviders.workspace.workspacesPath - await this._deps.fileManager.createWorkspace(workspaceName) + await this.processCreateWorkspace(workspaceName) for (const file in examples) { try { - await this._deps.fileManager.writeFile('browser/' + workspacesPath + '/' + workspaceName + '/' + examples[file].name, examples[file].content) + await browserProvider.set('browser/' + workspacesPath + '/' + workspaceName + '/' + examples[file].name, examples[file].content) } catch (error) { console.error(error) }