diff --git a/native/v8_extensions/native.js b/native/v8_extensions/native.js index b2df39ba7..76c4eb523 100644 --- a/native/v8_extensions/native.js +++ b/native/v8_extensions/native.js @@ -16,7 +16,7 @@ var $native = {}; native function list(path, recursive); $native.list = list; - native function traverseTree(path, callback); + native function traverseTree(path, onFile, onDirectory); $native.traverseTree = traverseTree; native function isFile(path); diff --git a/native/v8_extensions/native.mm b/native/v8_extensions/native.mm index b85536578..c2e055b0b 100644 --- a/native/v8_extensions/native.mm +++ b/native/v8_extensions/native.mm @@ -108,22 +108,30 @@ bool Native::Execute(const CefString& name, if (tree == NULL) return true; - CefRefPtr function = arguments[1]; + CefRefPtr onFile = arguments[1]; + CefRefPtr onDirectory = arguments[2]; CefV8ValueList args; FTSENT *entry; while ((entry = fts_read(tree)) != NULL) { if (entry->fts_level == 0) continue; - if ((entry->fts_info & FTS_D) != 0 || (entry->fts_info & FTS_F) != 0) { + if((entry->fts_info & FTS_F) != 0) { int pathLength = entry->fts_pathlen - rootPathLength; char relative[pathLength + 1]; relative[pathLength] = '\0'; strncpy(relative, entry->fts_path + rootPathLength, pathLength); args.clear(); args.push_back(CefV8Value::CreateString(relative)); - args.push_back(CefV8Value::CreateString(entry->fts_name)); - args.push_back(CefV8Value::CreateBool((entry->fts_info & FTS_F) != 0)); - if (!function->ExecuteFunction(function, args)->GetBoolValue()) + onFile->ExecuteFunction(onFile, args); + } + else if ((entry->fts_info & FTS_D) != 0) { + int pathLength = entry->fts_pathlen - rootPathLength; + char relative[pathLength + 1]; + relative[pathLength] = '\0'; + strncpy(relative, entry->fts_path + rootPathLength, pathLength); + args.clear(); + args.push_back(CefV8Value::CreateString(relative)); + if (!onDirectory->ExecuteFunction(onDirectory, args)->GetBoolValue()) fts_set(tree, entry, FTS_SKIP); } } diff --git a/spec/app/project-spec.coffee b/spec/app/project-spec.coffee index bea202ef1..d7f185987 100644 --- a/spec/app/project-spec.coffee +++ b/spec/app/project-spec.coffee @@ -111,7 +111,8 @@ describe "Project", -> describe ".getFilePaths()", -> it "ignores files that return true from atom.ignorePath(path)", -> - spyOn(project, 'ignorePath').andCallFake (path) -> fs.base(path).match /a$/ + spyOn(project, 'ignoreDirectory').andCallFake (path) -> fs.base(path).match /a$/ + spyOn(project, 'ignoreFile').andCallFake (path) -> fs.base(path).match /a$/ project.getFilePaths().done (paths) -> expect(paths).not.toContain('a') diff --git a/src/app/project.coffee b/src/app/project.coffee index 8a8a9f930..323d98f0b 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -55,22 +55,40 @@ class Project filePaths = [] - fs.traverseTree @getPath(), (path, name, isFile) => - return false if @ignorePath(path, name, isFile) - filePaths.push path if isFile - return not isFile + onFile = (path) => + filePaths.push(path) unless @ignoreFile(path) + + onDirectory = (path) => + return not @ignoreDirectory(path) + + fs.traverseTree @getPath(), onFile, onDirectory deferred.resolve filePaths deferred - - ignorePath: (path, name, isFile) -> - if isFile - for ignored in @ignoredFileNames - return true if name is ignored + ignoreDirectory: (path) -> + lastSlash = path.lastIndexOf('/') + if lastSlash isnt -1 + name = path.substring(lastSlash + 1) else - for ignored in @ignoredFolderNames - return true if name is ignored + name = path + for ignored in @ignoredFolderNames + return true if name is ignored + + for regex in @ignoredPathRegexes + return true if path.match(regex) + + return false + + ignoreFile: (path) -> + lastSlash = path.lastIndexOf('/') + if lastSlash isnt -1 + name = path.substring(lastSlash + 1) + else + name = path + + for ignored in @ignoredFileNames + return true if name is ignored for regex in @ignoredPathRegexes return true if path.match(regex) diff --git a/src/stdlib/fs.coffee b/src/stdlib/fs.coffee index 393a1a88c..c130ad13f 100644 --- a/src/stdlib/fs.coffee +++ b/src/stdlib/fs.coffee @@ -102,8 +102,8 @@ module.exports = @makeTree(@directory(path)) @makeDirectory(path) - traverseTree: (rootPath, fn) -> - $native.traverseTree(rootPath, fn) + traverseTree: (rootPath, onFile, onDirectory) -> + $native.traverseTree(rootPath, onFile, onDirectory) lastModified: (path) -> $native.lastModified(path)