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
7 changes: 4 additions & 3 deletions lib/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ exports.walk = function (start, callback) {
if (stat.isDirectory()) {

fs.readdir(start, function (err, files) {
if(!files) return callback(new Error("path: " + start + " is not accessible."));
var coll = files.reduce(function (acc, i) {
var abspath = path.join(start, i);

Expand Down Expand Up @@ -184,12 +185,12 @@ exports.path = {};
exports.path.abspath = function (to) {
var from;
switch (to.charAt(0)) {
case "~": from = process.env.HOME; to = to.substr(1); break
case path.sep: from = ""; break
case "~": from = process.env.HOME; to = to.substr(1); break;
case path.sep: from = ""; break;
default : from = process.cwd(); break
}
return path.join(from, to);
}
};

exports.path.relativePath = function (base, compare) {
base = base.split(path.sep);
Expand Down
10 changes: 10 additions & 0 deletions tests/file_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,13 @@ describe("file.path#relativePath", function () {
done();
});
});

describe("should handle directory with no access permission", function(){
it('should write error when no permission', function(done){
file.walk('test_resource/nopermdir', function (err) {
assert.notEqual(err, null);
assert.equal(err.message, 'path: test_resource/nopermdir is not accessible.');
done();
});
});
});