Remove native.list

Use native.traverseTree instead from fs.list
and fs.listTree
This commit is contained in:
Kevin Sawicki 2012-10-09 13:10:05 -07:00
parent 7fd06c8e66
commit a1f9e061bc
3 changed files with 14 additions and 37 deletions

View File

@ -13,9 +13,6 @@ var $native = {};
native function absolute(path); native function absolute(path);
$native.absolute = absolute; $native.absolute = absolute;
native function list(path, recursive);
$native.list = list;
native function traverseTree(path, onFile, onDirectory); native function traverseTree(path, onFile, onDirectory);
$native.traverseTree = traverseTree; $native.traverseTree = traverseTree;

View File

@ -137,36 +137,6 @@ bool Native::Execute(const CefString& name,
return true; 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") { else if (name == "isDirectory") {
NSString *path = stringFromCefV8Value(arguments[0]); NSString *path = stringFromCefV8Value(arguments[0]);

View File

@ -60,11 +60,21 @@ module.exports =
# Returns an array with all the names of files contained # Returns an array with all the names of files contained
# in the directory path. # in the directory path.
list: (path) -> list: (rootPath) ->
$native.list(path, false) paths = []
onPath = (path) =>
paths.push(@join(rootPath, path))
false
@traverseTree(rootPath, onPath, onPath)
paths
listTree: (path) -> listTree: (rootPath) ->
$native.list(path, true) paths = []
onPath = (path) =>
paths.push(@join(rootPath, path))
true
@traverseTree(rootPath, onPath, onPath)
paths
move: (source, target) -> move: (source, target) ->
$native.move(source, target) $native.move(source, target)