Class: CommandT::Scanner::FileScanner::WatchmanFileScanner
- Inherits:
-
FindFileScanner
- Object
- CommandT::Scanner
- CommandT::Scanner::FileScanner
- FindFileScanner
- CommandT::Scanner::FileScanner::WatchmanFileScanner
- Defined in:
- lib/command-t/scanner/file_scanner/watchman_file_scanner.rb
Overview
A FileScanner which delegates the heavy lifting to Watchman (github.com/facebook/watchman); useful for very large hierarchies.
Inherits from FindFileScanner so that it can fall back to it in the event that Watchman isn’t available or able to fulfil the request.
Constant Summary collapse
- WatchmanError =
Exception raised when Watchman is unavailable or unable to process the requested path.
Class.new(::RuntimeError)
Constants inherited from CommandT::Scanner::FileScanner
Instance Attribute Summary
Attributes inherited from CommandT::Scanner::FileScanner
Instance Method Summary collapse
Methods inherited from CommandT::Scanner::FileScanner
Methods inherited from CommandT::Scanner
Constructor Details
This class inherits a constructor from CommandT::Scanner::FileScanner
Instance Method Details
#paths! ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/command-t/scanner/file_scanner/watchman_file_scanner.rb', line 20 def paths! sockname = extract_value( Watchman::Utils.load(get_raw_sockname), 'sockname' ) UNIXSocket.open(sockname) do |socket| root = Pathname.new(@path).realpath.to_s roots = Watchman::Utils.query(['watch-list'], socket)['roots'] if !roots.include?(root) # this path isn't being watched yet; try to set up watch result = Watchman::Utils.query(['watch', root], socket) # root_restrict_files setting may prevent Watchman from working # or enforce_root_files/root_files (>= version 3.1) extract_value(result) end query = ['query', root, { 'expression' => ['type', 'f'], 'fields' => ['name'], }] paths = Watchman::Utils.query(query, socket) # could return error if watch is removed extracted = extract_value(paths, 'files') if @wildignore extracted.select { |path| path !~ @wildignore } else extracted end end rescue Errno::ENOENT, WatchmanError # watchman executable not present, or unable to fulfil request super end |