mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user