class Anamo::Fstree::Traverser
Attributes
base_path[R]
Public Class Methods
new(base_path = '/', writer = Writer.new, max_depth = 2, exclusions = [])
click to toggle source
# File lib/anamo/fstree/thor.rb, line 57 def initialize base_path = '/', writer = Writer.new, max_depth = 2, exclusions = [] @max_depth = max_depth @base_path = base_path @writer = writer @exclusions = exclusions end
Public Instance Methods
compute()
click to toggle source
# File lib/anamo/fstree/thor.rb, line 64 def compute walk_path @base_path @writer.close end
Private Instance Methods
walk_path(path, parent_data = {})
click to toggle source
# File lib/anamo/fstree/thor.rb, line 71 def walk_path path, parent_data = {}, depth = 0 begin return if @exclusions.include? File.realpath(path) # path is in excluded set rescue return # path does not exist end begin stat = File.stat(path) rescue stat = nil end data = [depth, File.basename(path)] open_as_directory = false if File.symlink? path data << 'sym' elsif File.directory? path open_as_directory = true data << 'd' elsif File.file? path data << 'f' elsif File.socket? path data << 'soc' elsif File.blockdev? path data << 'bd' elsif File.chardev? path data << 'cd' end begin data << stat.uid rescue data << '-' end begin data << stat.gid rescue data << '-' end begin data << stat.mode rescue data << '-' end begin data << stat.mtime rescue data << '-' end begin data << stat.size rescue data << '-' end @writer.add_row data if open_as_directory sub_depth = depth + 1 return if sub_depth > @max_depth Dir["#{path}/*"].each do |sub_path| walk_path sub_path, data, sub_depth end end end