Open jeremymv2 opened 7 years ago
A big 👍 for this as well.
Thanks @jeremymv2 I tend to go with:
directory.children.each do |filename|
file(filename).isFile?
end
@chris-rock would .children
be used for both files
and directories
?
This is awesome. One request is that wildcards be allowed in specifying directory paths. This works in ruby, but seems to not work via the file / directory resources.
For example, this line from the proposal
directory('/private/tmp').files do |d|
should also work like this:
directory('/private/*/important_files').files do |d|
So that Inspec finds all important_files in that are inside a directory in /private
Would also be nice if the file resource allowed wildcards in the path - should I open a separate issue for that?
So far, we can use the find
command:
`command('find . -type f -maxdepth 1').stdout.split("\n").map(&:strip).find_all { |x| !x.empty? }` is returning an array of files
Need it also for Windows. Any plans?
So far, we can use the find command:
`command('find . -type f -maxdepth 1').stdout.split("\n").map(&:strip).find_all(|x| !x.empty?)
Works for me but doesn't fail if the directory to walk doesn't exist or user cannot access it. I put in a second directory test to catch this but would be great if the directory walk enhancement caught the scenario.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.
This really needs a solution of some kind in the core.
Workarounds like the command("find ...")
are not general enough.
It probably needs work in the train library
Refs #709, likely duplicate
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.
Description
As a secops person, I want have an easy to use pattern for enumerating directory children, so that it works as expected both locally and when executing remotely.
From internal conversation: Since InSpec can be executed on a remote target, any
Dir.foreach
will not work as expected, since this reads files from the workstation not from the remote target. Since this is a common issue, we should make it easier to iterate over directories.Proposals:
Also, we could have
directory('/private/tmp').children
to enumerate all files and directories and then use