From c64d07d506e98d31921572263ca8c021b652aea2 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 12 Mar 2013 17:49:05 -0700 Subject: [PATCH] Return false if stat exception is thrown Calling exists() and then statSync() ends up stat'ing the file twice so removing the exists() check saves a stat call. --- src/stdlib/fs-utils.coffee | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/stdlib/fs-utils.coffee b/src/stdlib/fs-utils.coffee index 10661b2b1..1b3d8a46f 100644 --- a/src/stdlib/fs-utils.coffee +++ b/src/stdlib/fs-utils.coffee @@ -51,12 +51,20 @@ module.exports = # Returns true if the file specified by path exists and is a # directory. isDirectory: (path) -> - @exists(path) and fs.statSync(path).isDirectory() + return false unless path?.length > 0 + try + fs.statSync(path).isDirectory() + catch e + false # Returns true if the file specified by path exists and is a # regular file. isFile: (path) -> - @exists(path) and fs.statSync(path).isFile() + return false unless path?.length > 0 + try + path? and fs.statSync(path).isFile() + catch e + false # Returns an array with all the names of files contained # in the directory path.