From e6dd87840e042e874d6d4697a4e41e4f71f35f56 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 16 Jun 2020 12:58:23 +0200 Subject: [PATCH] make sure "remove" return a promise --- apps/remix-ide/src/app/files/fileProvider.js | 52 ++++++++++--------- .../remix-ide/src/app/files/remixDProvider.js | 5 +- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/apps/remix-ide/src/app/files/fileProvider.js b/apps/remix-ide/src/app/files/fileProvider.js index 1fa54ab11c..ac4dcda389 100644 --- a/apps/remix-ide/src/app/files/fileProvider.js +++ b/apps/remix-ide/src/app/files/fileProvider.js @@ -157,35 +157,37 @@ class FileProvider { * @param {*} path is the folder to be removed */ remove (path) { - path = this.removePrefix(path) - if (window.remixFileSystem.existsSync(path)) { - const stat = window.remixFileSystem.statSync(path) - try { - if (!stat.isDirectory()) { - return this.removeFile(path) - } else { - const items = window.remixFileSystem.readdirSync(path) - if (items.length !== 0) { - items.forEach((item, index) => { - const curPath = `${path}/${item}` - if (window.remixFileSystem.statSync(curPath).isDirectory()) { // delete folder - this.remove(curPath) - } else { // delete file - this.removeFile(curPath) - } - }) - if (window.remixFileSystem.readdirSync(path).length === 0) window.remixFileSystem.rmdirSync(path, console.log) + return new Promise((resolve, reject) => { + path = this.removePrefix(path) + if (window.remixFileSystem.existsSync(path)) { + const stat = window.remixFileSystem.statSync(path) + try { + if (!stat.isDirectory()) { + resolve(this.removeFile(path)) } else { - // folder is empty - window.remixFileSystem.rmdirSync(path, console.log) + const items = window.remixFileSystem.readdirSync(path) + if (items.length !== 0) { + items.forEach((item, index) => { + const curPath = `${path}/${item}` + if (window.remixFileSystem.statSync(curPath).isDirectory()) { // delete folder + this.remove(curPath) + } else { // delete file + this.removeFile(curPath) + } + }) + if (window.remixFileSystem.readdirSync(path).length === 0) window.remixFileSystem.rmdirSync(path, console.log) + } else { + // folder is empty + window.remixFileSystem.rmdirSync(path, console.log) + } } + } catch (e) { + console.log(e) + return resolve(false) } - } catch (e) { - console.log(e) - return false } - } - return true + return resolve(true) + }) } removeFile (path) { diff --git a/apps/remix-ide/src/app/files/remixDProvider.js b/apps/remix-ide/src/app/files/remixDProvider.js index 2e1f2574f3..7ec256a397 100644 --- a/apps/remix-ide/src/app/files/remixDProvider.js +++ b/apps/remix-ide/src/app/files/remixDProvider.js @@ -130,19 +130,22 @@ module.exports = class RemixDProvider { } remove (path) { + return new Promise((resolve, reject) => { const unprefixedpath = this.removePrefix(path) - this._appManager.call('remixd', 'remove', { path: unprefixedpath }) .then(result => { console.log('result: ', result) const path = this.type + '/' + unprefixedpath delete this.filesContent[path] + resolve(true) this.init(() => { this.event.trigger('fileRemoved', [path]) }) }).catch(error => { if (error) console.log(error) + resolve(false) + }) }) }