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.
This commit is contained in:
Kevin Sawicki
2013-03-12 17:49:05 -07:00
parent 8f177c3835
commit c64d07d506

View File

@@ -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.