From a1f9e061bca327efeb4c11bc4d0fa1103ad1114a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 9 Oct 2012 13:10:05 -0700 Subject: [PATCH] Remove native.list Use native.traverseTree instead from fs.list and fs.listTree --- native/v8_extensions/native.js | 3 --- native/v8_extensions/native.mm | 30 ------------------------------ src/stdlib/fs.coffee | 18 ++++++++++++++---- 3 files changed, 14 insertions(+), 37 deletions(-) diff --git a/native/v8_extensions/native.js b/native/v8_extensions/native.js index 76c4eb523..3f087c5ee 100644 --- a/native/v8_extensions/native.js +++ b/native/v8_extensions/native.js @@ -13,9 +13,6 @@ var $native = {}; native function absolute(path); $native.absolute = absolute; - native function list(path, recursive); - $native.list = list; - native function traverseTree(path, onFile, onDirectory); $native.traverseTree = traverseTree; diff --git a/native/v8_extensions/native.mm b/native/v8_extensions/native.mm index aca4e49cf..2adabef0d 100644 --- a/native/v8_extensions/native.mm +++ b/native/v8_extensions/native.mm @@ -137,36 +137,6 @@ bool Native::Execute(const CefString& name, return true; } - else if (name == "list") { - NSString *path = stringFromCefV8Value(arguments[0]); - bool recursive = arguments[1]->GetBoolValue(); - - if (!path or [path length] == 0) { - exception = "$native.list requires a path argument"; - return true; - } - - std::string argument = arguments[0]->GetStringValue().ToString(); - char rootPath[argument.size() + 1]; - strcpy(rootPath, argument.c_str()); - char * const paths[] = {rootPath, NULL}; - FTS *tree = fts_open(paths, FTS_PHYSICAL | FTS_NOCHDIR | FTS_NOSTAT, NULL); - retval = CefV8Value::CreateArray(0); - int index = 0; - if (tree != NULL) { - FTSENT *entry; - while ((entry = fts_read(tree)) != NULL) { - if (entry->fts_level == 0) - continue; - if (!recursive) - fts_set(tree, entry, FTS_SKIP); - if (entry->fts_info == FTS_D || entry->fts_info == FTS_NSOK) - retval->SetValue(index++, CefV8Value::CreateString(entry->fts_path)); - } - } - - return true; - } else if (name == "isDirectory") { NSString *path = stringFromCefV8Value(arguments[0]); diff --git a/src/stdlib/fs.coffee b/src/stdlib/fs.coffee index c130ad13f..93146d5ec 100644 --- a/src/stdlib/fs.coffee +++ b/src/stdlib/fs.coffee @@ -60,11 +60,21 @@ module.exports = # Returns an array with all the names of files contained # in the directory path. - list: (path) -> - $native.list(path, false) + list: (rootPath) -> + paths = [] + onPath = (path) => + paths.push(@join(rootPath, path)) + false + @traverseTree(rootPath, onPath, onPath) + paths - listTree: (path) -> - $native.list(path, true) + listTree: (rootPath) -> + paths = [] + onPath = (path) => + paths.push(@join(rootPath, path)) + true + @traverseTree(rootPath, onPath, onPath) + paths move: (source, target) -> $native.move(source, target)