Class: StorageGuardian::Scanner

Inherits:
Object
  • Object
show all
Defined in:
lib/storage_guardian/scanner.rb

Instance Method Summary collapse

Constructor Details

#initialize(root_path) ⇒ Scanner

Returns a new instance of Scanner.



9
10
11
# File 'lib/storage_guardian/scanner.rb', line 9

def initialize(root_path)
  @root = root_path
end

Instance Method Details

#scanObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/storage_guardian/scanner.rb', line 13

def scan
  entries = []
  return entries unless File.directory?(@root)

  Dir.glob(File.join(@root, "**", "*"), File::FNM_DOTMATCH).each do |path|
    next if File.directory?(path)
    next if File.symlink?(path)

    begin
      stat = File.stat(path)
      entries << Entry.new(
        path:   path,
        size:   stat.size,
        mtime:  stat.mtime,
        hash:   nil  # computed lazily by DuplicateDetector
      )
    rescue Errno::ENOENT, Errno::EACCES
      next
    end
  end
  entries
end