diff --git a/Atom/src/native_handler.mm b/Atom/src/native_handler.mm index e3e8b3fb6..31038e8ee 100644 --- a/Atom/src/native_handler.mm +++ b/Atom/src/native_handler.mm @@ -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]); diff --git a/spec/stdlib/fs-spec.coffee b/spec/stdlib/fs-spec.coffee index 11ef89c83..dd48935c8 100644 --- a/spec/stdlib/fs-spec.coffee +++ b/spec/stdlib/fs-spec.coffee @@ -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", -> diff --git a/src/stdlib/fs.coffee b/src/stdlib/fs.coffee index e7f9e1b8d..9cb912311 100644 --- a/src/stdlib/fs.coffee +++ b/src/stdlib/fs.coffee @@ -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.