mirror of
https://github.com/inspec/inspec
synced 2024-11-30 08:30:39 +00:00
a6582bea9b
* Remove any "All Rights Reserved" references InSpec is licensed and released under the Apache 2.0 license. This change removes all reference to legacy code files that still had any Copyright or License lines referring to "All Rights Reserved". Signed-off-by: Adam Leff <adam@leff.co> * fix functional tests Signed-off-by: Christoph Hartmann <chris@lollyrock.com>
43 lines
927 B
Ruby
43 lines
927 B
Ruby
# encoding: utf-8
|
|
# copyright: 2015, Vulcano Security GmbH
|
|
# author: Dominik Richter
|
|
# author: Christoph Hartmann
|
|
|
|
module FindFiles
|
|
TYPES = {
|
|
block: 'b',
|
|
character: 'c',
|
|
directory: 'd',
|
|
pipe: 'p',
|
|
file: 'f',
|
|
link: 'l',
|
|
socket: 's',
|
|
door: 'D',
|
|
}.freeze
|
|
|
|
# ignores errors
|
|
def find_files(path, opts = {})
|
|
find_files_or_error(path, opts) || []
|
|
end
|
|
|
|
def find_files_or_error(path, opts = {})
|
|
depth = opts[:depth]
|
|
type = TYPES[opts[:type].to_sym] if opts[:type]
|
|
|
|
cmd = "find #{path}"
|
|
cmd += " -type #{type}" unless type.nil?
|
|
cmd += " -maxdepth #{depth.to_i}" if depth.to_i > 0
|
|
|
|
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
|
|
end
|