implemented mkdir and rmdir

pull/4/head
ioedeveloper 5 years ago
parent df91b9237f
commit 9c830a11e5
  1. 13
      src/app/files/fileManager.js
  2. 34
      src/app/files/fileProvider.js

@ -133,9 +133,9 @@ class FileManager extends Plugin {
* @returns {boolean} true if path is a file.
*/
isFile (path) {
const extension = path.split('/').pop()
const provider = this.fileProviderOf(path)
return extension && extension.indexOf('.') > -1
return provider.isFile(path)
}
/**
@ -218,7 +218,9 @@ class FileManager extends Plugin {
if (this.exists(path)) {
this._handleError({ code: 'EEXIST', message: `Cannot create directory ${path}` })
}
// To implement
const provider = this.fileProviderOf(path)
provider.createDir(path)
}
/**
@ -249,7 +251,10 @@ class FileManager extends Plugin {
rmdir (path) {
this._handleExists(path, `Cannot remove directory ${path}`)
this._handleIsDir(path, `Cannot remove directory ${path}`)
// To implement
const provider = this.fileProviderOf(path)
return provider.remove(path)
}
init () {

@ -79,7 +79,6 @@ class FileProvider {
}
get (path, cb) {
console.log('window.remixFileSystem: ', window.remixFileSystem)
cb = cb || function () {}
path = this.getPathFromUrl(path) || path // ensure we actually use the normalized path from here
var unprefixedpath = this.removePrefix(path)
@ -95,19 +94,8 @@ class FileProvider {
var unprefixedpath = this.removePrefix(path)
var exists = window.remixFileSystem.existsSync(unprefixedpath)
if (exists && window.remixFileSystem.readFileSync(unprefixedpath, 'utf8') === content) return true
if (!exists && unprefixedpath.indexOf('/') !== -1) {
const paths = unprefixedpath.split('/')
paths.pop() // last element should the filename
if (paths.length && paths[0] === '') paths.shift()
let currentCheck = ''
paths.forEach((value) => {
currentCheck = currentCheck + '/' + value
if (!window.remixFileSystem.existsSync(currentCheck)) {
window.remixFileSystem.mkdirSync(currentCheck)
this.event.trigger('folderAdded', [this._normalizePath(currentCheck)])
}
})
this.createDir(path)
}
try {
window.remixFileSystem.writeFileSync(unprefixedpath, content)
@ -124,6 +112,22 @@ class FileProvider {
return true
}
createDir (path, cb) {
var unprefixedpath = this.removePrefix(path)
const paths = unprefixedpath.split('/')
paths.pop() // last element should the filename
if (paths.length && paths[0] === '') paths.shift()
let currentCheck = ''
paths.forEach((value) => {
currentCheck = currentCheck + '/' + value
if (!window.remixFileSystem.existsSync(currentCheck)) {
window.remixFileSystem.mkdirSync(currentCheck)
this.event.trigger('folderAdded', [this._normalizePath(currentCheck)])
}
})
if (cb) cb()
}
// this will not add a folder as readonly but keep the original url to be able to restore it later
addExternal (path, content, url) {
if (url) this.addNormalizedName(path, url)
@ -138,6 +142,10 @@ class FileProvider {
return window.remixFileSystem.statSync(path).isDirectory()
}
isFile (path) {
return window.remixFileSystem.statSync(path).isFile()
}
/**
* Removes the folder recursively
* @param {*} path is the folder to be removed

Loading…
Cancel
Save