summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb2
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb2
-rw-r--r--lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_artifact_dir.rb2
-rw-r--r--lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb8
-rw-r--r--lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb7
-rw-r--r--lib/chef/chef_fs/file_system/repository/chef_repository_file_system_versioned_cookbook_dir.rb2
-rw-r--r--lib/chef/cookbook/chefignore.rb27
-rw-r--r--lib/chef/cookbook/cookbook_version_loader.rb2
-rw-r--r--lib/chef/cookbook/syntax_check.rb8
-rw-r--r--lib/chef/cookbook_loader.rb6
-rw-r--r--lib/chef/cookbook_uploader.rb2
11 files changed, 41 insertions, 27 deletions
diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb
index 273b45a646..c99c689a71 100644
--- a/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb
@@ -65,7 +65,7 @@ class Chef
file_class.symlink other.file_path, proxy_cookbook_path
# Instantiate a proxy loader using the temporary symlink
- proxy_loader = Chef::Cookbook::CookbookVersionLoader.new(proxy_cookbook_path, other.parent.chefignore)
+ proxy_loader = Chef::Cookbook::CookbookVersionLoader.new(proxy_cookbook_path, other.chefignore)
proxy_loader.load_cookbooks
cookbook_to_upload = proxy_loader.cookbook_version
diff --git a/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb b/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb
index 0fd1e4acdf..739a42b124 100644
--- a/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb
@@ -71,7 +71,7 @@ class Chef
file_class.symlink other.file_path, proxy_cookbook_path
# Instantiate a proxy loader using the temporary symlink
- proxy_loader = Chef::Cookbook::CookbookVersionLoader.new(proxy_cookbook_path, other.parent.chefignore)
+ proxy_loader = Chef::Cookbook::CookbookVersionLoader.new(proxy_cookbook_path, other.chefignore)
proxy_loader.load_cookbooks
cookbook_to_upload = proxy_loader.cookbook_version
diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_artifact_dir.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_artifact_dir.rb
index 8a6e375fde..a15b47ca73 100644
--- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_artifact_dir.rb
+++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_artifact_dir.rb
@@ -25,7 +25,7 @@ class Chef
class ChefRepositoryFileSystemCookbookArtifactDir < ChefRepositoryFileSystemCookbookDir
# Override from parent
def cookbook_version
- loader = Chef::Cookbook::CookbookVersionLoader.new(file_path, parent.chefignore)
+ loader = Chef::Cookbook::CookbookVersionLoader.new(file_path, chefignore)
cookbook_name, _dash, identifier = name.rpartition("-")
# KLUDGE: We shouldn't have to use instance_variable_set
loader.instance_variable_set(:@cookbook_name, cookbook_name)
diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb
index 74170cc7a9..4f8368b025 100644
--- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb
+++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb
@@ -21,6 +21,7 @@ require_relative "../chef_server/cookbook_dir"
require_relative "../chef_server/versioned_cookbook_dir"
require_relative "../exceptions"
require_relative "../../../cookbook/cookbook_version_loader"
+require_relative "../../../cookbook/chefignore"
class Chef
module ChefFS
@@ -31,6 +32,11 @@ class Chef
class ChefRepositoryFileSystemCookbookDir < ChefRepositoryFileSystemCookbookEntry
# API Required by Respository::Directory
+ def chefignore
+ @chefignore ||= Chef::Cookbook::Chefignore.new(file_path)
+ rescue Errno::EISDIR, Errno::EACCES
+ # Work around a bug in Chefignore when chefignore is a directory
+ end
def fs_entry_valid?
return false unless File.directory?(file_path) && name_valid?
@@ -136,7 +142,7 @@ class Chef
end
def cookbook_version
- loader = Chef::Cookbook::CookbookVersionLoader.new(file_path, parent.chefignore)
+ loader = Chef::Cookbook::CookbookVersionLoader.new(file_path, chefignore)
loader.load_cookbooks
loader.cookbook_version
end
diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb
index 1708428372..6ae5045284 100644
--- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb
+++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb
@@ -68,13 +68,14 @@ class Chef
end
# Check chefignore
- ignorer = parent
+ ignorer = self
+
loop do
- if ignorer.is_a?(CookbooksDir)
+ if ignorer.is_a?(ChefRepositoryFileSystemCookbookDir)
# Grab the path from entry to child
path_to_child = name
child = self
- while child.parent != ignorer
+ while child != ignorer
path_to_child = PathUtils.join(child.name, path_to_child)
child = child.parent
end
diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_versioned_cookbook_dir.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_versioned_cookbook_dir.rb
index 442fa879ad..4d76be579a 100644
--- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_versioned_cookbook_dir.rb
+++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_versioned_cookbook_dir.rb
@@ -25,7 +25,7 @@ class Chef
class ChefRepositoryFileSystemVersionedCookbookDir < ChefRepositoryFileSystemCookbookDir
# Override from parent
def cookbook_version
- loader = Chef::Cookbook::CookbookVersionLoader.new(file_path, parent.chefignore)
+ loader = Chef::Cookbook::CookbookVersionLoader.new(file_path, chefignore)
# We need the canonical cookbook name if we are using versioned cookbooks, but we don't
# want to spend a lot of time adding code to the main Chef libraries
canonical_name = canonical_cookbook_name(File.basename(file_path))
diff --git a/lib/chef/cookbook/chefignore.rb b/lib/chef/cookbook/chefignore.rb
index 4fed557000..763f5325cc 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,34 @@ 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?
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
diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb
index 767196ea0e..f9ec765e47 100644
--- a/lib/chef/cookbook/cookbook_version_loader.rb
+++ b/lib/chef/cookbook/cookbook_version_loader.rb
@@ -189,7 +189,7 @@ class Chef
end
def chefignore
- @chefignore ||= Chefignore.new(File.basename(cookbook_path))
+ @chefignore ||= Chefignore.new(cookbook_path)
end
# Enumerate all the files in a cookbook and assign the resulting list to
diff --git a/lib/chef/cookbook/syntax_check.rb b/lib/chef/cookbook/syntax_check.rb
index 6c1f710f6d..073323da05 100644
--- a/lib/chef/cookbook/syntax_check.rb
+++ b/lib/chef/cookbook/syntax_check.rb
@@ -84,11 +84,13 @@ class Chef
# If no +cookbook_path+ is given, +Chef::Config.cookbook_path+ is used.
def self.for_cookbook(cookbook_name, cookbook_path = nil)
cookbook_path ||= Chef::Config.cookbook_path
- unless cookbook_path
- raise ArgumentError, "Cannot find cookbook #{cookbook_name} unless Chef::Config.cookbook_path is set or an explicit cookbook path is given"
+
+ Array(cookbook_path).each do |entry|
+ path = File.expand_path(File.join(entry, cookbook_name.to_s))
+ return new(path) if Dir.exist?(path)
end
- new(File.join(cookbook_path, cookbook_name.to_s))
+ raise ArgumentError, "Cannot find cookbook #{cookbook_name} unless Chef::Config.cookbook_path is set or an explicit cookbook path is given"
end
# Create a new SyntaxCheck object
diff --git a/lib/chef/cookbook_loader.rb b/lib/chef/cookbook_loader.rb
index b27d751d64..2bafed410d 100644
--- a/lib/chef/cookbook_loader.rb
+++ b/lib/chef/cookbook_loader.rb
@@ -49,8 +49,8 @@ class Chef
# @param repo_paths [Array<String>] the array of repo paths containing cookbook dirs
def initialize(*repo_paths)
- @repo_paths = repo_paths.flatten.map { |p| File.expand_path(p) }
- raise ArgumentError, "You must specify at least one cookbook repo path" if repo_paths.empty?
+ @repo_paths = repo_paths.flatten.compact.map { |p| File.expand_path(p) }
+ raise ArgumentError, "You must specify at least one cookbook repo path" if @repo_paths.empty?
end
# The primary function of this class is to build this Mash mapping cookbook names as a string to
@@ -171,7 +171,7 @@ class Chef
begin
mash = Mash.new
all_directories_in_repo_paths.each do |cookbook_path|
- loader = Cookbook::CookbookVersionLoader.new(cookbook_path, chefignore(File.dirname(cookbook_path)))
+ loader = Cookbook::CookbookVersionLoader.new(cookbook_path, chefignore(cookbook_path))
cookbook_name = loader.cookbook_name
if mash.key?(cookbook_name)
raise Chef::Exceptions::CookbookMergingError, "Cookbook merging is no longer supported, the cookbook named #{cookbook_name} can only appear once in the cookbook_path"
diff --git a/lib/chef/cookbook_uploader.rb b/lib/chef/cookbook_uploader.rb
index 31fec8cfd1..ffc4040194 100644
--- a/lib/chef/cookbook_uploader.rb
+++ b/lib/chef/cookbook_uploader.rb
@@ -139,7 +139,7 @@ class Chef
def validate_cookbooks
cookbooks.each do |cb|
- syntax_checker = Chef::Cookbook::SyntaxCheck.for_cookbook(cb.name)
+ syntax_checker = Chef::Cookbook::SyntaxCheck.new(cb.root_dir)
Chef::Log.info("Validating ruby files")
exit(1) unless syntax_checker.validate_ruby_files
Chef::Log.info("Validating templates")