Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a907294b6 |
@@ -7,7 +7,7 @@ module.exports = {
|
||||
if (!this.fs) return this.reply(550, 'File system not instantiated');
|
||||
if (!this.fs.chdir) return this.reply(402, 'Not supported by file system');
|
||||
|
||||
return Promise.resolve(this.fs.chdir(command.arg))
|
||||
return Promise.try(() => this.fs.chdir(command.arg))
|
||||
.then(cwd => {
|
||||
const path = cwd ? `"${escapePath(cwd)}"` : undefined;
|
||||
return this.reply(250, path);
|
||||
|
||||
@@ -6,7 +6,7 @@ module.exports = {
|
||||
if (!this.fs) return this.reply(550, 'File system not instantiated');
|
||||
if (!this.fs.delete) return this.reply(402, 'Not supported by file system');
|
||||
|
||||
return Promise.resolve(this.fs.delete(command.arg))
|
||||
return Promise.try(() => this.fs.delete(command.arg))
|
||||
.then(() => {
|
||||
return this.reply(250);
|
||||
})
|
||||
|
||||
@@ -16,8 +16,8 @@ module.exports = {
|
||||
const path = command.arg || '.';
|
||||
return this.connector.waitForConnection()
|
||||
.tap(() => this.commandSocket.pause())
|
||||
.then(() => Promise.resolve(this.fs.get(path)))
|
||||
.then(stat => stat.isDirectory() ? Promise.resolve(this.fs.list(path)) : [stat])
|
||||
.then(() => Promise.try(() => this.fs.get(path)))
|
||||
.then(stat => stat.isDirectory() ? Promise.try(() => this.fs.list(path)) : [stat])
|
||||
.then(files => {
|
||||
const getFileMessage = file => {
|
||||
if (simple) return file.name;
|
||||
|
||||
@@ -7,7 +7,7 @@ module.exports = {
|
||||
if (!this.fs) return this.reply(550, 'File system not instantiated');
|
||||
if (!this.fs.get) return this.reply(402, 'Not supported by file system');
|
||||
|
||||
return Promise.resolve(this.fs.get(command.arg))
|
||||
return Promise.try(() => this.fs.get(command.arg))
|
||||
.then(fileStat => {
|
||||
const modificationTime = moment.utc(fileStat.mtime).format('YYYYMMDDHHmmss.SSS');
|
||||
return this.reply(213, modificationTime);
|
||||
|
||||
@@ -7,7 +7,7 @@ module.exports = {
|
||||
if (!this.fs) return this.reply(550, 'File system not instantiated');
|
||||
if (!this.fs.mkdir) return this.reply(402, 'Not supported by file system');
|
||||
|
||||
return Promise.resolve(this.fs.mkdir(command.arg))
|
||||
return Promise.try(() => this.fs.mkdir(command.arg))
|
||||
.then(dir => {
|
||||
const path = dir ? `"${escapePath(dir)}"` : undefined;
|
||||
return this.reply(257, path);
|
||||
|
||||
@@ -7,7 +7,7 @@ module.exports = {
|
||||
if (!this.fs) return this.reply(550, 'File system not instantiated');
|
||||
if (!this.fs.currentDirectory) return this.reply(402, 'Not supported by file system');
|
||||
|
||||
return Promise.resolve(this.fs.currentDirectory())
|
||||
return Promise.try(() => this.fs.currentDirectory())
|
||||
.then(cwd => {
|
||||
const path = cwd ? `"${escapePath(cwd)}"` : undefined;
|
||||
return this.reply(257, path);
|
||||
|
||||
@@ -10,7 +10,7 @@ module.exports = {
|
||||
|
||||
return this.connector.waitForConnection()
|
||||
.tap(() => this.commandSocket.pause())
|
||||
.then(() => Promise.resolve(this.fs.read(filePath, {start: this.restByteCount})))
|
||||
.then(() => Promise.try(() => this.fs.read(filePath, {start: this.restByteCount})))
|
||||
.then(stream => {
|
||||
const destroyConnection = (connection, reject) => err => {
|
||||
if (connection) connection.destroy(err);
|
||||
|
||||
@@ -7,7 +7,7 @@ module.exports = {
|
||||
if (!this.fs.get) return this.reply(402, 'Not supported by file system');
|
||||
|
||||
const fileName = command.arg;
|
||||
return Promise.resolve(this.fs.get(fileName))
|
||||
return Promise.try(() => this.fs.get(fileName))
|
||||
.then(() => {
|
||||
this.renameFrom = fileName;
|
||||
return this.reply(350);
|
||||
|
||||
@@ -11,7 +11,7 @@ module.exports = {
|
||||
const from = this.renameFrom;
|
||||
const to = command.arg;
|
||||
|
||||
return Promise.resolve(this.fs.rename(from, to))
|
||||
return Promise.try(() => this.fs.rename(from, to))
|
||||
.then(() => {
|
||||
return this.reply(250);
|
||||
})
|
||||
|
||||
@@ -6,7 +6,7 @@ module.exports = function ({log, command} = {}) {
|
||||
|
||||
const [mode, ...fileNameParts] = command.arg.split(' ');
|
||||
const fileName = fileNameParts.join(' ');
|
||||
return Promise.resolve(this.fs.chmod(fileName, parseInt(mode, 8)))
|
||||
return Promise.try(() => this.fs.chmod(fileName, parseInt(mode, 8)))
|
||||
.then(() => {
|
||||
return this.reply(200);
|
||||
})
|
||||
|
||||
@@ -6,7 +6,7 @@ module.exports = {
|
||||
if (!this.fs) return this.reply(550, 'File system not instantiated');
|
||||
if (!this.fs.get) return this.reply(402, 'Not supported by file system');
|
||||
|
||||
return Promise.resolve(this.fs.get(command.arg))
|
||||
return Promise.try(() => this.fs.get(command.arg))
|
||||
.then(fileStat => {
|
||||
return this.reply(213, {message: fileStat.size});
|
||||
})
|
||||
|
||||
@@ -11,12 +11,12 @@ module.exports = {
|
||||
if (!this.fs) return this.reply(550, 'File system not instantiated');
|
||||
if (!this.fs.get) return this.reply(402, 'Not supported by file system');
|
||||
|
||||
return Promise.resolve(this.fs.get(path))
|
||||
return Promise.try(() => this.fs.get(path))
|
||||
.then(stat => {
|
||||
if (stat.isDirectory()) {
|
||||
if (!this.fs.list) return this.reply(402, 'Not supported by file system');
|
||||
|
||||
return Promise.resolve(this.fs.list(path))
|
||||
return Promise.try(() => this.fs.list(path))
|
||||
.then(stats => [213, stats]);
|
||||
}
|
||||
return [212, [stat]];
|
||||
|
||||
@@ -11,7 +11,7 @@ module.exports = {
|
||||
|
||||
return this.connector.waitForConnection()
|
||||
.tap(() => this.commandSocket.pause())
|
||||
.then(() => Promise.resolve(this.fs.write(fileName, {append, start: this.restByteCount})))
|
||||
.then(() => Promise.try(() => this.fs.write(fileName, {append, start: this.restByteCount})))
|
||||
.then(stream => {
|
||||
const destroyConnection = (connection, reject) => err => {
|
||||
if (connection) connection.destroy(err);
|
||||
|
||||
@@ -8,11 +8,9 @@ module.exports = {
|
||||
if (!this.fs.get || !this.fs.getUniqueName) return this.reply(402, 'Not supported by file system');
|
||||
|
||||
const fileName = args.command.arg;
|
||||
return Promise.try(() => {
|
||||
return Promise.resolve(this.fs.get(fileName))
|
||||
.then(() => Promise.resolve(this.fs.getUniqueName()))
|
||||
.catch(() => Promise.resolve(fileName));
|
||||
})
|
||||
return Promise.try(() => this.fs.get(fileName))
|
||||
.then(() => Promise.try(() => this.fs.getUniqueName()))
|
||||
.catch(() => fileName)
|
||||
.then(name => {
|
||||
args.command.arg = name;
|
||||
return stor.call(this, args);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
const {expect} = require('chai');
|
||||
const nodePath = require('path');
|
||||
const Promise = require('bluebird');
|
||||
|
||||
const FileSystem = require('../src/fs');
|
||||
const errors = require('../src/errors');
|
||||
|
||||
describe('FileSystem', function () {
|
||||
let fs;
|
||||
@@ -13,6 +15,25 @@ describe('FileSystem', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('extend', function () {
|
||||
class FileSystemOV extends FileSystem {
|
||||
chdir() {
|
||||
throw new errors.FileSystemError('Not a valid directory');
|
||||
}
|
||||
}
|
||||
let ovFs;
|
||||
before(function () {
|
||||
ovFs = new FileSystemOV({});
|
||||
});
|
||||
|
||||
it('handles error', function () {
|
||||
return Promise.try(() => ovFs.chdir())
|
||||
.catch(err => {
|
||||
expect(err).to.be.instanceof(errors.FileSystemError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#_resolvePath', function () {
|
||||
it('gets correct relative path', function () {
|
||||
const result = fs._resolvePath();
|
||||
|
||||
@@ -385,7 +385,7 @@ describe('Integration', function () {
|
||||
runFileSystemTests('binary');
|
||||
});
|
||||
|
||||
describe.skip('#EXPLICIT', function () {
|
||||
describe('#EXPLICIT', function () {
|
||||
before(() => {
|
||||
return server.close()
|
||||
.then(() => startServer('ftp://127.0.0.1:8880', {
|
||||
|
||||
Reference in New Issue
Block a user