fs.isFile(path) returns false if given path does not exist

This commit is contained in:
Corey Johnson
2012-05-08 10:18:17 -07:00
parent b528196d1b
commit 545671a641
3 changed files with 24 additions and 1 deletions

View File

@@ -127,6 +127,15 @@ bool NativeHandler::Execute(const CefString& name,
return true;
}
else if (name == "isFile") {
NSString *path = stringFromCefV8Value(arguments[0]);
BOOL isDir = false;
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir];
retval = CefV8Value::CreateBool(exists && !isDir);
return true;
}
else if (name == "remove") {
NSString *path = stringFromCefV8Value(arguments[0]);

View File

@@ -1,6 +1,20 @@
fs = require 'fs'
describe "fs", ->
describe ".isFile(path)", ->
fixturesDir = require.resolve('fixtures')
beforeEach ->
it "returns true with a file path", ->
expect(fs.isFile(fs.join(fixturesDir, 'sample.js'))).toBe true
it "returns false with a directory path", ->
expect(fs.isFile(fixturesDir)).toBe false
it "returns false with a non-existent path", ->
expect(fs.isFile(fs.join(fixturesDir, 'non-existent'))).toBe false
expect(fs.isFile(null)).toBe false
describe ".directory(path)", ->
describe "when called with a file path", ->
it "returns the path to the directory", ->

View File

@@ -51,7 +51,7 @@ module.exports =
# Returns true if the file specified by path exists and is a
# regular file.
isFile: (path) ->
not $native.isDirectory path
$native.isFile path
# Returns an array with all the names of files contained
# in the directory path.