mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Don't use a web worker for loading all paths
Instead use fs.realpath() and fs.stat() to walk the project tree asynchronously.
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
fs = require 'fs-utils'
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
loadPaths: (rootPath, ignoredNames, excludeGitIgnoredPaths) ->
|
||||
if excludeGitIgnoredPaths
|
||||
Git = require 'git'
|
||||
repo = Git.open(rootPath, refreshOnWindowFocus: false)
|
||||
|
||||
paths = []
|
||||
isIgnored = (path) ->
|
||||
for segment in path.split('/')
|
||||
return true if _.contains(ignoredNames, segment)
|
||||
repo?.isPathIgnored(fs.join(rootPath, path))
|
||||
onFile = (path) ->
|
||||
paths.push(path) unless isIgnored(path)
|
||||
onDirectory = (path) ->
|
||||
not isIgnored(path)
|
||||
fs.traverseTree(rootPath, onFile, onDirectory)
|
||||
|
||||
repo?.destroy()
|
||||
|
||||
callTaskMethod('pathsLoaded', paths)
|
||||
@@ -1,17 +1,33 @@
|
||||
Task = require 'task'
|
||||
_ = require 'underscore'
|
||||
fs = require 'fs-utils'
|
||||
|
||||
module.exports =
|
||||
class LoadPathsTask extends Task
|
||||
constructor: (@callback) ->
|
||||
super('fuzzy-finder/lib/load-paths-handler')
|
||||
class LoadPathsTask
|
||||
aborted: false
|
||||
|
||||
started: ->
|
||||
constructor: (@callback) ->
|
||||
|
||||
start: ->
|
||||
rootPath = project.getPath()
|
||||
ignoredNames = config.get('fuzzyFinder.ignoredNames') ? []
|
||||
ignoredNames = ignoredNames.concat(config.get('core.ignoredNames') ? [])
|
||||
excludeGitIgnoredPaths = config.get('core.hideGitIgnoredFiles')
|
||||
rootPath = project.getPath()
|
||||
@callWorkerMethod('loadPaths', rootPath, ignoredNames, excludeGitIgnoredPaths)
|
||||
ignoreGitIgnoredFiles = config.get('core.hideGitIgnoredFiles')
|
||||
|
||||
pathsLoaded: (paths) ->
|
||||
@done()
|
||||
@callback(paths)
|
||||
paths = []
|
||||
isIgnored = (path) ->
|
||||
for segment in path.split('/')
|
||||
return true if _.contains(ignoredNames, segment)
|
||||
ignoreGitIgnoredFiles and git?.isPathIgnored(fs.join(rootPath, path))
|
||||
onFile = (path) ->
|
||||
return if @aborted
|
||||
path = path.substring(rootPath.length + 1)
|
||||
paths.push(path) unless isIgnored(path)
|
||||
onDirectory = (path) =>
|
||||
not @aborted and not isIgnored(path.substring(rootPath.length + 1))
|
||||
onDone = =>
|
||||
@callback(paths) unless @aborted
|
||||
|
||||
fs.traverseTreeAsync(rootPath, onFile, onDirectory, onDone)
|
||||
|
||||
abort: ->
|
||||
@aborted = true
|
||||
|
||||
@@ -168,6 +168,33 @@ module.exports =
|
||||
|
||||
traverse(rootPath, '', onFile, onDirectory)
|
||||
|
||||
traverseTreeAsync: (rootPath, onFile, onDirectory, onDone) ->
|
||||
pathCounter = 0
|
||||
startPath = -> pathCounter++
|
||||
endPath = -> onDone() if --pathCounter is 0
|
||||
|
||||
traverse = (rootPath, onFile, onDirectory) =>
|
||||
startPath()
|
||||
fs.readdir rootPath, (error, files) =>
|
||||
if error or files.length is 0
|
||||
endPath()
|
||||
return
|
||||
|
||||
for file in files
|
||||
path = @join(rootPath, file)
|
||||
do (path) =>
|
||||
startPath()
|
||||
fs.stat path, (error, stats) =>
|
||||
unless error
|
||||
if stats.isFile()
|
||||
onFile(path)
|
||||
else if stats.isDirectory()
|
||||
traverse(path, onFile, onDirectory) if onDirectory(path)
|
||||
endPath()
|
||||
endPath()
|
||||
|
||||
traverse(rootPath, onFile, onDirectory)
|
||||
|
||||
md5ForPath: (path) ->
|
||||
contents = fs.readFileSync(path)
|
||||
require('crypto').createHash('md5').update(contents).digest('hex')
|
||||
|
||||
Reference in New Issue
Block a user