Class: CommandT::Scanner::FileScanner::FindFileScanner

Inherits:
CommandT::Scanner::FileScanner show all
Includes:
PathUtilities
Defined in:
lib/command-t/scanner/file_scanner/find_file_scanner.rb

Overview

A FileScanner which shells out to the ‘find` executable in order to scan.

Direct Known Subclasses

GitFileScanner, WatchmanFileScanner

Constant Summary

Constants inherited from CommandT::Scanner::FileScanner

FileLimitExceeded

Instance Attribute Summary

Attributes inherited from CommandT::Scanner::FileScanner

#path

Instance Method Summary collapse

Methods inherited from CommandT::Scanner::FileScanner

#flush, #initialize, #paths

Methods inherited from CommandT::Scanner

#paths

Constructor Details

This class inherits a constructor from CommandT::Scanner::FileScanner

Instance Method Details

#paths!Object



13
14
15
16
17
18
19
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
# File 'lib/command-t/scanner/file_scanner/find_file_scanner.rb', line 13

def paths!
  # temporarily set field separator to NUL byte; this setting is
  # respected by both `each_line` and `chomp!` below, and makes it easier
  # to parse the output of `find -print0`
  separator = $/
  $/ = "\x00"

  unless @scan_dot_directories
    dot_directory_filter = [
      '-not', '-path', "#{@path}/.*/*",           # top-level dot dir
      '-and', '-not', '-path', "#{@path}/*/.*/*"  # lower-level dot dir
    ]
  end

  paths = []
  Open3.popen3(*([
    'find', '-L',                 # follow symlinks
    @path,                        # anchor search here
    '-maxdepth', @max_depth.to_s, # limit depth of DFS
    '-type', 'f',                 # only show regular files (not dirs etc)
    dot_directory_filter,         # possibly skip out dot directories
    '-print0'                     # NUL-terminate results
  ].flatten.compact)) do |stdin, stdout, stderr|
    counter = 1
    next_progress = progress_reporter.update(counter)
    stdout.each_line do |line|
      next if path_excluded?(line.chomp!)
      paths << line[@prefix_len..-1]
      next_progress = progress_reporter.update(counter) if counter == next_progress
      if (counter += 1) > @max_files
        show_max_files_warning
        break
      end
    end
  end
  paths
ensure
  $/ = separator
end