From c642aedda21819c88679f50bf996b9631422de81 Mon Sep 17 00:00:00 2001 From: Ian Plunkett Date: Thu, 19 Jun 2014 15:45:09 -0700 Subject: [PATCH 1/3] Change the behavior of file.recurse so that it will log an error if it processes a broken symlink instead of causing a fatal error. We wrap the call to fs.statSync(filepath).isDirectory() in a try/catch block, then log on the error condition. --- lib/grunt/file.js | 8 +++++++- package.json | 4 ++-- test/fixtures/symlinks/bad-symlink | 1 + test/grunt/file_test.js | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 120000 test/fixtures/symlinks/bad-symlink 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..c325ecc74 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "grunt", "description": "The JavaScript Task Runner", - "version": "0.4.6-0", + "version": "0.4.6-1", "author": "\"Cowboy\" Ben Alman (http://benalman.com/)", "homepage": "http://gruntjs.com/", "repository": { @@ -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'; From 59050ab74be9d1eece523a36169ed02bc344d752 Mon Sep 17 00:00:00 2001 From: Ian Plunkett Date: Fri, 20 Jun 2014 08:56:27 -0700 Subject: [PATCH 2/3] Update package.json Reverting version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c325ecc74..66bcda329 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "grunt", "description": "The JavaScript Task Runner", - "version": "0.4.6-1", + "version": "0.4.6-0", "author": "\"Cowboy\" Ben Alman (http://benalman.com/)", "homepage": "http://gruntjs.com/", "repository": { From 416a57344685974c091babcca62388fd03503fc7 Mon Sep 17 00:00:00 2001 From: Ian Plunkett Date: Fri, 20 Jun 2014 10:37:35 -0700 Subject: [PATCH 3/3] Update package.json Getting rid of this new line. Emacs keeps adding them.