From fbcd8e43a083f80cd27c0e0e0fcbfb5a7570f510 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 26 Apr 2012 16:26:49 -0700 Subject: [PATCH] Add fs.makeDirectory --- Atom/src/native_handler.mm | 14 +++++++++++++- src/stdlib/fs.coffee | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Atom/src/native_handler.mm b/Atom/src/native_handler.mm index 7f5a8562a..92b75940a 100644 --- a/Atom/src/native_handler.mm +++ b/Atom/src/native_handler.mm @@ -13,7 +13,7 @@ NSString *stringFromCefV8Value(const CefRefPtr& value) { NativeHandler::NativeHandler() : CefV8Handler() { m_object = CefV8Value::CreateObject(NULL); - const char *functionNames[] = {"exists", "read", "write", "absolute", "list", "isFile", "isDirectory", "remove", "asyncList", "open", "openDialog", "quit", "writeToPasteboard", "readFromPasteboard", "showDevTools", "newWindow", "saveDialog", "exit", "watchPath", "unwatchPath"}; + const char *functionNames[] = {"exists", "read", "write", "absolute", "list", "isFile", "isDirectory", "remove", "asyncList", "open", "openDialog", "quit", "writeToPasteboard", "readFromPasteboard", "showDevTools", "newWindow", "saveDialog", "exit", "watchPath", "unwatchPath", "makeDirectory"}; NSUInteger arrayLength = sizeof(functionNames) / sizeof(const char *); for (NSUInteger i = 0; i < arrayLength; i++) { const char *functionName = functionNames[i]; @@ -308,6 +308,18 @@ bool NativeHandler::Execute(const CefString& name, return true; } + else if (name == "makeDirectory") { + NSString *path = stringFromCefV8Value(arguments[0]); + NSFileManager *fm = [NSFileManager defaultManager]; + NSError *error = nil; + [fm createDirectoryAtPath:path withIntermediateDirectories:NO attributes:nil error:&error]; + + if (error) { + exception = [[error localizedDescription] UTF8String]; + } + + return true; + } return false; }; \ No newline at end of file diff --git a/src/stdlib/fs.coffee b/src/stdlib/fs.coffee index b72b774f9..fff77aec1 100644 --- a/src/stdlib/fs.coffee +++ b/src/stdlib/fs.coffee @@ -66,6 +66,9 @@ module.exports = write: (path, content) -> $native.write(path, content) + makeDirectory: (path) -> + $native.makeDirectory(path) + async: list: (path) -> deferred = $.Deferred()