Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing issue with broken symlinks #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ function readdir(path, ignores, callback) {
var filePath = p.join(path, file)
fs.stat(filePath, function(_err, stats) {
if (_err) {
if (_err.code == 'ENOENT') {
fs.lstat(filePath, function(_lserr, stats) {
if (_lserr) {
return callback(_lserr)
}

if (ignores.some(function(matcher) { return matcher(filePath, stats) })) {
pending -= 1
if (!pending) {
return callback(null, list)
}
return null
}
return callback(_err)
})
return null
}
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 @@ -240,6 +240,22 @@ describe('readdir', function() {
done()
})
})

it('does not fail on broken symlink if it is ignored', function(done) {
var expectedFiles = getAbsolutePaths([
'/testbrokensymlink/foo.bar'
])
function ignoreFunction(path, stats) {
return stats.isSymbolicLink();
}

readdir(p.join(__dirname, 'testbrokensymlink'), [ignoreFunction], function(err, list) {
assert.ifError(err)
assert.deepEqual(list.sort(), expectedFiles,
'Failed to find expected files.')
done()
})
})
})

it('works when there are no files to report except ignored files', function(done) {
Expand Down
1 change: 1 addition & 0 deletions test/testbrokensymlink/brokenlink
Empty file added test/testbrokensymlink/foo.bar
Empty file.