From 842ac02c9c32e216170ff1c4ab7b02a54cbec374 Mon Sep 17 00:00:00 2001 From: Jevon Wild Date: Wed, 10 Aug 2011 14:06:37 -0700 Subject: [PATCH 1/2] Handling directory read errors gracefully --- lib/plugins/reload.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/plugins/reload.js b/lib/plugins/reload.js index e452c4b..b7962cc 100644 --- a/lib/plugins/reload.js +++ b/lib/plugins/reload.js @@ -89,9 +89,13 @@ exports = module.exports = function(files, options){ if (stat.isDirectory()) { if (~exports.ignoreDirectories.indexOf(basename(file))) return; fs.readdir(file, function(err, files){ - files.map(function(f){ - return file + '/' + f; - }).forEach(traverse); + if (!err) { + files.map(function(f){ + return file + '/' + f; + }).forEach(traverse); + } else { + console.error('Warning: failed reading directory ' + file, err.message); + } }); } else { watch(file); From 155fc2bf4d97fb9b8a5d968e29aacaaccfd7fa72 Mon Sep 17 00:00:00 2001 From: Jevon Wild Date: Fri, 12 Aug 2011 15:12:47 -0700 Subject: [PATCH 2/2] adding symlink-following support for reload --- lib/plugins/reload.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/plugins/reload.js b/lib/plugins/reload.js index b7962cc..d72f53c 100644 --- a/lib/plugins/reload.js +++ b/lib/plugins/reload.js @@ -10,7 +10,8 @@ var fs = require('fs') , basename = require('path').basename - , extname = require('path').extname; + , extname = require('path').extname + , dirname = require('path').dirname; /** * Restart the server the given js `files` have changed. @@ -94,7 +95,25 @@ exports = module.exports = function(files, options){ return file + '/' + f; }).forEach(traverse); } else { - console.error('Warning: failed reading directory ' + file, err.message); + if (err.errno === 2) { + fs.readlink(file, function(err, resolvedLink) { + if (!err) { + fs.readdir(dirname(file) + '/' + resolvedLink, function(err, files){ + if(!err) { + files.map(function(f){ + return file + '/' + f; + }).forEach(traverse); + } else { + console.error('Error reading directory ' + dirname(file) + '/' + resolvedLink, err.message); + } + }); + } else { + console.log('error reading directory ' + file, err.message); + } + }); + } else { + console.log('error reading directory ' + file, err.message); + } } }); } else { @@ -119,7 +138,7 @@ exports = module.exports = function(files, options){ master.on('restarting', function(){ restarting = true; }); - } + }; }; /**