diff --git a/lib/grunt/file.js b/lib/grunt/file.js index c9a7eaeb6..b8c83322c 100644 --- a/lib/grunt/file.js +++ b/lib/grunt/file.js @@ -211,7 +211,13 @@ file.recurse = function recurse(rootdir, callback, subdir) { var abspath = subdir ? path.join(rootdir, subdir) : rootdir; fs.readdirSync(abspath).forEach(function(filename) { var filepath = path.join(abspath, filename); - if (fs.statSync(filepath).isDirectory()) { + var isDirectory = false; + try { + isDirectory = fs.statSync(filepath).isDirectory(); + } catch (e) { + grunt.log.error(e); + } + if (isDirectory) { recurse(rootdir, callback, unixifyPath(path.join(subdir || '', filename || ''))); } else { callback(unixifyPath(filepath), rootdir, subdir, filename); diff --git a/package.json b/package.json index 1a0d6d1c9..66bcda329 100644 --- a/package.json +++ b/package.json @@ -74,4 +74,4 @@ "semver": "2.1.0", "shelljs": "~0.2.5" } -} \ No newline at end of file +} diff --git a/test/fixtures/symlinks/bad-symlink b/test/fixtures/symlinks/bad-symlink new file mode 120000 index 000000000..850f348b9 --- /dev/null +++ b/test/fixtures/symlinks/bad-symlink @@ -0,0 +1 @@ +thing-to-link-to.txt \ No newline at end of file diff --git a/test/grunt/file_test.js b/test/grunt/file_test.js index 613ddc330..69d604fb6 100644 --- a/test/grunt/file_test.js +++ b/test/grunt/file_test.js @@ -723,6 +723,23 @@ exports['file'] = { test.done(); }, + 'recurse bad symlink': function(test) { + var rootdir = 'test/fixtures/symlinks'; + + var expected = {}; + expected[rootdir+'/bad-symlink'] = [rootdir, 'bad-symlink']; + + var actual = {}; + try{ + grunt.file.recurse(rootdir, function(abspath, rootdir, subdir, filename) { + actual[abspath] = [rootdir, filename]; + }); + } catch (e) { + // We log an error if the file doesn't exist, expected behavior + } + test.deepEqual(actual, expected, 'file recurse will process broken symlinks'); + test.done(); + }, 'recurse': function(test) { test.expect(1); var rootdir = 'test/fixtures/expand';