Project.getFilePaths does not traverse into ignored directories

This commit is contained in:
Corey Johnson & Nathan Sobo 2012-05-08 17:59:38 -07:00
parent 289193787e
commit 4665321b37
2 changed files with 26 additions and 3 deletions

View File

@ -71,3 +71,12 @@ describe "Project", ->
project.setPath(null)
expect(project.getPath()?).toBeFalsy()
expect(project.getRootDirectory()?).toBeFalsy()
describe ".getFilePaths()", ->
it "ignores files that return true from atom.ignorePath(path)", ->
spyOn(project, 'ignorePath').andCallFake (path) -> fs.base(path).match /a$/
project.getFilePaths().done (paths) ->
expect(paths).not.toContain('a')
expect(paths).toContain('b')

View File

@ -1,6 +1,8 @@
fs = require 'fs'
Buffer = require 'buffer'
_ = require 'underscore'
$ = require 'jquery'
Buffer = require 'buffer'
EventEmitter = require 'event-emitter'
Directory = require 'directory'
@ -31,8 +33,20 @@ class Project
@rootDirectory
getFilePaths: ->
fs.async.listTree(@getPath()).pipe (paths) =>
@relativize(path) for path in paths when fs.isFile(path)
deferred = $.Deferred()
filePaths = []
fs.traverseTree @getPath(), (path, prune) =>
if @ignorePath(path)
prune()
else if fs.isFile(path)
filePaths.push @relativize(path)
deferred.resolve filePaths
deferred
ignorePath: (path) ->
fs.base(path).match(/\.DS_Store/) or path.match(/(^|\/)\.git(\/|$)/)
open: (filePath) ->
if filePath?