Migrate fs.traverseTree to use Node's fs

This commit is contained in:
Kevin Sawicki
2013-03-05 14:28:53 -08:00
committed by Kevin Sawicki & Nathan Sobo
parent fe7f43155a
commit 07a8a35e48

View File

@@ -121,7 +121,20 @@ module.exports =
$native.getAllFilePathsAsync(rootPath, callback)
traverseTree: (rootPath, onFile, onDirectory) ->
$native.traverseTree(rootPath, onFile, onDirectory)
return unless nodeFs.existsSync(rootPath) and nodeFs.statSync(rootPath).isDirectory()
traverse = (rootPath, prefix, onFile, onDirectory) =>
prefix = "#{prefix}/" if prefix
for file in nodeFs.readdirSync(rootPath)
relativePath = "#{prefix}#{file}"
absolutePath = @join(rootPath, file)
stats = nodeFs.statSync(absolutePath)
if stats.isDirectory()
traverse(absolutePath, relativePath, onFile, onDirectory) if onDirectory(relativePath)
else if stats.isFile()
onFile(relativePath)
traverse(rootPath, '', onFile, onDirectory)
lastModified: (path) ->
$native.lastModified(path)