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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.DS_Store
.idea/
23 changes: 21 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,25 @@ function toMatcherFunction(ignoreEntry) {
}
}

function _getFileStat(filePath, callback) {
fs.stat(filePath, function (err, stats) {
if (err) {
if (err.code === 'ENOENT') {
fs.lstat(filePath, function (_err, _stats) {
if (_err) {
return callback(_err);
}
return callback(null, _stats);
});
} else {
return callback(err);
}
}

return callback(null, stats);
});
}

function readdir(path, ignores, callback) {
if (typeof ignores == "function") {
callback = ignores;
Expand Down Expand Up @@ -52,7 +71,7 @@ function readdir(path, ignores, callback) {

files.forEach(function(file) {
var filePath = p.join(path, file);
fs.stat(filePath, function(_err, stats) {
_getFileStat(filePath, function(_err, stats) {
if (_err) {
return callback(_err);
}
Expand All @@ -69,7 +88,7 @@ function readdir(path, ignores, callback) {
return null;
}

if (stats.isDirectory()) {
if (stats && stats.isDirectory && stats.isDirectory()) {
readdir(filePath, ignores, function(__err, res) {
if (__err) {
return callback(__err);
Expand Down
16 changes: 16 additions & 0 deletions test/recursive-readdir-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,22 @@ describe("readdir", function() {
});
});

it("does not fail if the symlink is broken and returns the symlink in file list", function(done) {
var expectedFiles = getAbsolutePaths([
"/testsymlinks/testbroken/file.dat.alias"
]);

readdir(p.join(__dirname, "testsymlinks", "testbroken"), function(err, list) {
assert.ifError(err);
assert.deepEqual(
list.sort(),
expectedFiles,
"Failed to find expected files."
);
done();
});
});

if (!global.Promise) {
console.log("Native Promise not supported - skipping tests");
} else {
Expand Down
Binary file added test/testsymlinks/testbroken/file.dat.alias
Binary file not shown.