make sure "remove" return a promise

pull/262/head
yann300 4 years ago
parent 33622dde00
commit 7230f0b822
  1. 52
      src/app/files/fileProvider.js
  2. 5
      src/app/files/remixDProvider.js

@ -157,35 +157,37 @@ class FileProvider {
* @param {*} path is the folder to be removed * @param {*} path is the folder to be removed
*/ */
remove (path) { remove (path) {
path = this.removePrefix(path) return new Promise((resolve, reject) => {
if (window.remixFileSystem.existsSync(path)) { path = this.removePrefix(path)
const stat = window.remixFileSystem.statSync(path) if (window.remixFileSystem.existsSync(path)) {
try { const stat = window.remixFileSystem.statSync(path)
if (!stat.isDirectory()) { try {
return this.removeFile(path) if (!stat.isDirectory()) {
} else { resolve(this.removeFile(path))
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 { } else {
// folder is empty const items = window.remixFileSystem.readdirSync(path)
window.remixFileSystem.rmdirSync(path, console.log) 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 resolve(true)
return true })
} }
removeFile (path) { removeFile (path) {

@ -130,19 +130,22 @@ module.exports = class RemixDProvider {
} }
remove (path) { remove (path) {
return new Promise((resolve, reject) => {
const unprefixedpath = this.removePrefix(path) const unprefixedpath = this.removePrefix(path)
this._appManager.call('remixd', 'remove', { path: unprefixedpath }) this._appManager.call('remixd', 'remove', { path: unprefixedpath })
.then(result => { .then(result => {
console.log('result: ', result) console.log('result: ', result)
const path = this.type + '/' + unprefixedpath const path = this.type + '/' + unprefixedpath
delete this.filesContent[path] delete this.filesContent[path]
resolve(true)
this.init(() => { this.init(() => {
this.event.trigger('fileRemoved', [path]) this.event.trigger('fileRemoved', [path])
}) })
}).catch(error => { }).catch(error => {
if (error) console.log(error) if (error) console.log(error)
resolve(false)
})
}) })
} }

Loading…
Cancel
Save