Module: FindFiles
- Included in:
- Inspec::Resources::ApacheConf, Inspec::Resources::MysqlConf, Inspec::Resources::PostgresConf
- Defined in:
- lib/utils/find_files.rb
Overview
copyright: 2015, Vulcano Security GmbH license: All rights reserved author: Dominik Richter author: Christoph Hartmann
Constant Summary collapse
- TYPES =
{ block: 'b', character: 'c', directory: 'd', pipe: 'p', file: 'f', link: 'l', socket: 's', door: 'D', }.freeze
Instance Method Summary collapse
-
#find_files(path, opts = {}) ⇒ Object
ignores errors.
- #find_files_or_error(path, opts = {}) ⇒ Object
Instance Method Details
#find_files(path, opts = {}) ⇒ Object
ignores errors
20 21 22 |
# File 'lib/utils/find_files.rb', line 20 def find_files(path, opts = {}) find_files_or_error(path, opts) || [] end |
#find_files_or_error(path, opts = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/utils/find_files.rb', line 24 def find_files_or_error(path, opts = {}) depth = opts[:depth] type = TYPES[opts[:type].to_sym] if opts[:type] cmd = "find #{path}" cmd += " -maxdepth #{depth.to_i}" if depth.to_i > 0 cmd += " -type #{type}" unless type.nil? result = inspec.command(cmd) exit_status = result.exit_status unless exit_status == 0 warn "find_files(): exit #{exit_status} from `#{cmd}`" return nil end result.stdout.split("\n") .map(&:strip) .find_all { |x| !x.empty? } end |