Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function statList(fsm, list, callback) {

var stats = [];
var total = list.length;
for (var i = 0; i < CONC; ++i) {
for (var i = 0; i < list.length && i < CONC; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd consider a comparison with Math.min() more readable. Fans of premature optimization could save the min() result in a variable. ;-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me as long as its also done at the other places where this construction is used.

Anyhow it will change as the CONC construction is not working properly anyway for synchronous implementations . :-)

Verzonden van mijn HTC

----- Reply message -----
Van: "M.K." [email protected]
Aan: "sstur/nodeftpd" [email protected]
CC: "rianwouters" [email protected], "Author" [email protected]
Onderwerp: [sstur/nodeftpd] Fix 108 (#109)
Datum: vr, jun. 17, 2016 13:08

@@ -16,7 +16,7 @@ function statList(fsm, list, callback) {

var stats = [];
var total = list.length;

  • for (var i = 0; i < CONC; ++i) {
  • for (var i = 0; i < list.length && i < CONC; ++i) {

I'd consider a comparison with Math.min() more readable. Fans of premature optimization could save the min() result in a variable. ;-)


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
https://github.com/sstur/nodeftpd/pull/109/files/f90a4004d3b42385edd37998b8a8f178389914d4#r67494604

handleFile();
}

Expand Down
2 changes: 1 addition & 1 deletion test/lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var common = module.exports = {
});
connection.on('command:pass', function(pass, success, failure) {
if (pass === customOptions.pass) {
success(username);
success(username, customOptions.fs);
} else {
failure();
}
Expand Down
176 changes: 112 additions & 64 deletions test/list.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,134 @@
var common = require('./lib/common');
var fs = require('fs');

describe('LIST command', function() {
'use strict';

var client;
var server;

beforeEach(function(done) {
server = common.server();
client = common.client(done);
});
describe('regular cases', function() {

function unslashRgx(rgx) {
return String(rgx).replace(/^\/|\/$/g, '');
}

it('should return "-" as first character for files', function(done) {
client.list('/', function(error, listing) {
error.should.equal(false);
listing = common.splitResponseLines(listing, / data\d*\.txt$/);
listing.should.have.lengthOf(6);
listing[0].should.startWith('-');
done();
beforeEach(function(done) {
server = common.server();
client = common.client(done);
});
});

it('should return "d" as first character for directories', function(done) {
client.list('/', function(error, listing) {
error.should.equal(false);
listing = common.splitResponseLines(listing, / usr$/);
listing.should.have.lengthOf(1);
listing[0].should.startWith('d');
done();
function unslashRgx(rgx) {
return String(rgx).replace(/^\/|\/$/g, '');
}

it('should return "-" as first character for files', function(done) {
client.list('/', function(error, listing) {
error.should.equal(false);
listing = common.splitResponseLines(listing, / data\d*\.txt$/);
listing.should.have.lengthOf(6);
listing[0].should.startWith('-');
done();
});
});
});

it('should list files similar to ls -l', function(done) {
client.list('/usr', function(error, listing) {
error.should.equal(false);
listing = common.splitResponseLines(listing);
listing.should.have.lengthOf(1);
var lsLongRgx = [
/($# file modes: ___|)[d-]([r-][w-][x-]){3}/,
/($# ?�?�? inodes?: |)\d+/,
/($# owner name: ___|)\S+/,
/($# owner group: __|)\S+/,
/($# size in bytes: |)\d+/,
/($# month: ________|)[A-Z][a-z]{2}/,
/($# day of month: _|)\d{1,2}/,
/($# time or year: _|)([\d ]\d:|19|[2-9]\d)\d{2}/,
/($# file name: ____|)[\S\s]+/,
].map(unslashRgx).join('\\s+');
lsLongRgx = new RegExp(lsLongRgx, '');
var match = (lsLongRgx.exec(listing[0]) || [false]);
match[0].should.equal(listing[0]);
done();
it('should return "d" as first character for directories', function(done) {
client.list('/', function(error, listing) {
error.should.equal(false);
listing = common.splitResponseLines(listing, / usr$/);
listing.should.have.lengthOf(1);
listing[0].should.startWith('d');
done();
});
});
});

it('should list a single file', function(done) {
var filename = 'data.txt';
client.list('/' + filename, function(error, listing) {
error.should.equal(false);
listing = common.splitResponseLines(listing, ' ' + filename);
listing.should.have.lengthOf(1);
listing[0].should.startWith('-');
done();
it('should list files similar to ls -l', function(done) {
client.list('/usr', function(error, listing) {
error.should.equal(false);
listing = common.splitResponseLines(listing);
listing.should.have.lengthOf(1);
var lsLongRgx = [
/($# file modes: ___|)[d-]([r-][w-][x-]){3}/,
/($# ?�?�? inodes?: |)\d+/,
/($# owner name: ___|)\S+/,
/($# owner group: __|)\S+/,
/($# size in bytes: |)\d+/,
/($# month: ________|)[A-Z][a-z]{2}/,
/($# day of month: _|)\d{1,2}/,
/($# time or year: _|)([\d ]\d:|19|[2-9]\d)\d{2}/,
/($# file name: ____|)[\S\s]+/,
].map(unslashRgx).join('\\s+');
lsLongRgx = new RegExp(lsLongRgx, '');
var match = (lsLongRgx.exec(listing[0]) || [false]);
match[0].should.equal(listing[0]);
done();
});
});
});

it('should list a subdirectory', function(done) {
client.list('/usr', function(error, listing) {
error.should.equal(false);
listing = common.splitResponseLines(listing);
listing.should.have.lengthOf(1);
listing[0].should.startWith('d');
listing[0].should.endWith(' local');
done();
it('should list a single file', function(done) {
var filename = 'data.txt';
client.list('/' + filename, function(error, listing) {
error.should.equal(false);
listing = common.splitResponseLines(listing, ' ' + filename);
listing.should.have.lengthOf(1);
listing[0].should.startWith('-');
done();
});
});

it('should list a subdirectory', function(done) {
client.list('/usr', function(error, listing) {
error.should.equal(false);
listing = common.splitResponseLines(listing);
listing.should.have.lengthOf(1);
listing[0].should.startWith('d');
listing[0].should.endWith(' local');
done();
});
});

afterEach(function() {
server.close();
});
});

afterEach(function() {
server.close();
describe('corner cases', function() {
'use strict';

var files;

beforeEach(function(done) {
server = common.server({
fs: {
stat: function(path, callback) {
console.log('STAT', path);
callback(
undefined /* err */,
new fs.Stats(0,32768 /* file mode */,0,0,0,0,0,0,0,43 /* size */,0,0,0,0)
);
},
readdir: function(path, callback) {
console.log('READDIR', path);
callback(undefined, files);
},
},
});
client = common.client(done);
});


it.only('supports directories with only a few files', function(done) {
files = ['a'];
client.list('/', function(error, listing) {
error.should.equal(false);
console.log(listing);
listing = common.splitResponseLines(listing);
listing.should.have.lengthOf(1);
done();
});
});

afterEach(function() {
server.close();
});
});


});