diff options
author | Vivek Singh <vivek.singh@msystechnologies.com> | 2019-09-25 14:34:00 +0530 |
---|---|---|
committer | Vivek Singh <vivek.singh@msystechnologies.com> | 2019-10-28 14:06:22 +0530 |
commit | 752e5f869506866a503fe8c8a789c4c94205e6c4 (patch) | |
tree | d01e0ed3838c9c9072a01cf6cdc7ec8665f2f677 /lib | |
parent | f62d1fc80eb857ffabdbb5cabe166bbdbe840561 (diff) | |
download | chef-752e5f869506866a503fe8c8a789c4c94205e6c4.tar.gz |
Update the #find_ignore_file to ignore file till root dir
- Minor update in #readable_file_or_symlink? method to use arg path params instead of instance var.
- Change log level trace to debug for missing lookup path.
Signed-off-by: Vivek Singh <vivek.singh@msystechnologies.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/cookbook/chefignore.rb | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/lib/chef/cookbook/chefignore.rb b/lib/chef/cookbook/chefignore.rb index 4fed557000..53f62818ab 100644 --- a/lib/chef/cookbook/chefignore.rb +++ b/lib/chef/cookbook/chefignore.rb @@ -24,11 +24,9 @@ class Chef attr_reader :ignores def initialize(ignore_file_or_repo) - # Check the 'ignore_file_or_repo' path first and then look in the parent directory + # Check the 'ignore_file_or_repo' path first and then look in the parent directories till root # to handle both the chef repo cookbook layout and a standalone cookbook @ignore_file = find_ignore_file(ignore_file_or_repo) - @ignore_file = find_ignore_file(File.dirname(ignore_file_or_repo)) unless readable_file_or_symlink?(@ignore_file) - @ignores = parse_ignore_file end @@ -50,27 +48,36 @@ class Chef def parse_ignore_file ignore_globs = [] - if readable_file_or_symlink?(@ignore_file) + if @ignore_file && readable_file_or_symlink?(@ignore_file) File.foreach(@ignore_file) do |line| ignore_globs << line.strip unless line =~ COMMENTS_AND_WHITESPACE end else - Chef::Log.trace("No chefignore file found at #{@ignore_file} no files will be ignored") + Chef::Log.debug("No chefignore file found. No files will be ignored!") end ignore_globs end + # Lookup of chefignore file till the root dir of the provided path. + # If file refer then lookup the parent dir till the root. + # eg. path: /var/.chef/cookbook_name + # Lookup at '/var/.chef/cookbook_name/chefignore', '/var/.chef/chefignore' '/var/chefignore' and '/chefignore' until exist def find_ignore_file(path) - if File.basename(path) =~ /chefignore/ - path - else - File.join(path, "chefignore") + Pathname.new(path).ascend do |dir| + next unless dir.directory? + + file = dir.join("chefignore") + return file.expand_path.to_s if file.exist? + + Chef::Log.debug("No chefignore file found at #{file}") end + + nil end def readable_file_or_symlink?(path) - File.exist?(@ignore_file) && File.readable?(@ignore_file) && - (File.file?(@ignore_file) || File.symlink?(@ignore_file)) + File.exist?(path) && File.readable?(path) && + (File.file?(path) || File.symlink?(path)) end end end |