|
|
@ -102,10 +102,14 @@ class FileManager extends Plugin { |
|
|
|
|
|
|
|
|
|
|
|
/** The current opened file */ |
|
|
|
/** The current opened file */ |
|
|
|
file () { |
|
|
|
file () { |
|
|
|
|
|
|
|
try { |
|
|
|
const file = this.currentFile() |
|
|
|
const file = this.currentFile() |
|
|
|
|
|
|
|
|
|
|
|
if (!file) throw createError({ code: 'ENOENT', message: 'No file selected' }) |
|
|
|
if (!file) throw createError({ code: 'ENOENT', message: 'No file selected' }) |
|
|
|
return file |
|
|
|
return file |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
throw new Error(e) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -114,6 +118,7 @@ class FileManager extends Plugin { |
|
|
|
* @returns {boolean} true if the path exists |
|
|
|
* @returns {boolean} true if the path exists |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
exists (path) { |
|
|
|
exists (path) { |
|
|
|
|
|
|
|
try { |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
const provider = this.fileProviderOf(path) |
|
|
|
const provider = this.fileProviderOf(path) |
|
|
|
const result = provider.exists(path, (err, result) => { |
|
|
|
const result = provider.exists(path, (err, result) => { |
|
|
@ -122,6 +127,9 @@ class FileManager extends Plugin { |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
return result |
|
|
|
return result |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
throw new Error(e) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -154,10 +162,14 @@ class FileManager extends Plugin { |
|
|
|
* @returns {void} |
|
|
|
* @returns {void} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async open (path) { |
|
|
|
async open (path) { |
|
|
|
|
|
|
|
try { |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
await this._handleExists(path, `Cannot open file ${path}`) |
|
|
|
await this._handleExists(path, `Cannot open file ${path}`) |
|
|
|
await this._handleIsFile(path, `Cannot open file ${path}`) |
|
|
|
await this._handleIsFile(path, `Cannot open file ${path}`) |
|
|
|
return this.openFile(path) |
|
|
|
return this.openFile(path) |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
throw new Error(e) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -167,6 +179,7 @@ class FileManager extends Plugin { |
|
|
|
* @returns {void} |
|
|
|
* @returns {void} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async writeFile (path, data) { |
|
|
|
async writeFile (path, data) { |
|
|
|
|
|
|
|
try { |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
if (await this.exists(path)) { |
|
|
|
if (await this.exists(path)) { |
|
|
|
await this._handleIsFile(path, `Cannot write file ${path}`) |
|
|
|
await this._handleIsFile(path, `Cannot write file ${path}`) |
|
|
@ -176,6 +189,9 @@ class FileManager extends Plugin { |
|
|
|
this.emit('fileAdded', path) |
|
|
|
this.emit('fileAdded', path) |
|
|
|
return ret |
|
|
|
return ret |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
throw new Error(e) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -184,10 +200,14 @@ class FileManager extends Plugin { |
|
|
|
* @returns {string} content of the file |
|
|
|
* @returns {string} content of the file |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async readFile (path) { |
|
|
|
async readFile (path) { |
|
|
|
|
|
|
|
try { |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
await this._handleExists(path, `Cannot read file ${path}`) |
|
|
|
await this._handleExists(path, `Cannot read file ${path}`) |
|
|
|
await this._handleIsFile(path, `Cannot read file ${path}`) |
|
|
|
await this._handleIsFile(path, `Cannot read file ${path}`) |
|
|
|
return this.getFileContent(path) |
|
|
|
return this.getFileContent(path) |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
throw new Error(e) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -197,6 +217,7 @@ class FileManager extends Plugin { |
|
|
|
* @returns {void} |
|
|
|
* @returns {void} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async copyFile (src, dest) { |
|
|
|
async copyFile (src, dest) { |
|
|
|
|
|
|
|
try { |
|
|
|
src = this.limitPluginScope(src) |
|
|
|
src = this.limitPluginScope(src) |
|
|
|
dest = this.limitPluginScope(dest) |
|
|
|
dest = this.limitPluginScope(dest) |
|
|
|
await this._handleExists(src, `Cannot copy from ${src}`) |
|
|
|
await this._handleExists(src, `Cannot copy from ${src}`) |
|
|
@ -205,6 +226,9 @@ class FileManager extends Plugin { |
|
|
|
const content = await this.readFile(src) |
|
|
|
const content = await this.readFile(src) |
|
|
|
|
|
|
|
|
|
|
|
await this.writeFile(dest, content) |
|
|
|
await this.writeFile(dest, content) |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
throw new Error(e) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -214,6 +238,7 @@ class FileManager extends Plugin { |
|
|
|
* @returns {void} |
|
|
|
* @returns {void} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async rename (oldPath, newPath) { |
|
|
|
async rename (oldPath, newPath) { |
|
|
|
|
|
|
|
try { |
|
|
|
oldPath = this.limitPluginScope(oldPath) |
|
|
|
oldPath = this.limitPluginScope(oldPath) |
|
|
|
newPath = this.limitPluginScope(newPath) |
|
|
|
newPath = this.limitPluginScope(newPath) |
|
|
|
await this._handleExists(oldPath, `Cannot rename ${oldPath}`) |
|
|
|
await this._handleExists(oldPath, `Cannot rename ${oldPath}`) |
|
|
@ -234,6 +259,9 @@ class FileManager extends Plugin { |
|
|
|
} |
|
|
|
} |
|
|
|
return provider.rename(oldPath, newPath, true) |
|
|
|
return provider.rename(oldPath, newPath, true) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
throw new Error(e) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -242,13 +270,17 @@ class FileManager extends Plugin { |
|
|
|
* @returns {void} |
|
|
|
* @returns {void} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async mkdir (path) { |
|
|
|
async mkdir (path) { |
|
|
|
|
|
|
|
try { |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
if (await this.exists(path)) { |
|
|
|
if (await this.exists(path)) { |
|
|
|
throw createError({ code: 'EEXIST', message: `Cannot create directory ${path}` }) |
|
|
|
throw createError({ code: 'EEXIST', message: `Cannot create directory ${path}` }) |
|
|
|
} |
|
|
|
} |
|
|
|
const provider = this.fileProviderOf(path) |
|
|
|
const provider = this.fileProviderOf(path) |
|
|
|
|
|
|
|
|
|
|
|
provider.createDir(path) |
|
|
|
return provider.createDir(path) |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
throw new Error(e) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -257,6 +289,7 @@ class FileManager extends Plugin { |
|
|
|
* @returns {string[]} list of the file/directory name in this directory |
|
|
|
* @returns {string[]} list of the file/directory name in this directory |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async readdir (path) { |
|
|
|
async readdir (path) { |
|
|
|
|
|
|
|
try { |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
await this._handleExists(path) |
|
|
|
await this._handleExists(path) |
|
|
|
await this._handleIsDir(path) |
|
|
|
await this._handleIsDir(path) |
|
|
@ -269,6 +302,9 @@ class FileManager extends Plugin { |
|
|
|
resolve(filesProvider) |
|
|
|
resolve(filesProvider) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
throw new Error(e) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -277,11 +313,15 @@ class FileManager extends Plugin { |
|
|
|
* @returns {void} |
|
|
|
* @returns {void} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async remove (path) { |
|
|
|
async remove (path) { |
|
|
|
|
|
|
|
try { |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
path = this.limitPluginScope(path) |
|
|
|
await this._handleExists(path, `Cannot remove file or directory ${path}`) |
|
|
|
await this._handleExists(path, `Cannot remove file or directory ${path}`) |
|
|
|
const provider = this.fileProviderOf(path) |
|
|
|
const provider = this.fileProviderOf(path) |
|
|
|
|
|
|
|
|
|
|
|
return await provider.remove(path) |
|
|
|
return await provider.remove(path) |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
throw new Error(e) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
init () { |
|
|
|
init () { |
|
|
|