summaryrefslogtreecommitdiff
path: root/lib/chef/chef_fs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/chef_fs')
-rw-r--r--lib/chef/chef_fs/chef_fs_data_store.rb8
-rw-r--r--lib/chef/chef_fs/command_line.rb5
-rw-r--r--lib/chef/chef_fs/config.rb1
-rw-r--r--lib/chef/chef_fs/file_pattern.rb6
-rw-r--r--lib/chef/chef_fs/file_system.rb1
-rw-r--r--lib/chef/chef_fs/file_system/base_fs_object.rb7
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb3
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb1
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/environments_dir.rb2
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/policies_dir.rb1
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb1
-rw-r--r--lib/chef/chef_fs/file_system/repository/base_file.rb1
-rw-r--r--lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb4
-rw-r--r--lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb2
-rw-r--r--lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb2
-rw-r--r--lib/chef/chef_fs/file_system/repository/chef_repository_file_system_versioned_cookbook_dir.rb1
-rw-r--r--lib/chef/chef_fs/file_system/repository/directory.rb4
-rw-r--r--lib/chef/chef_fs/file_system/repository/file_system_entry.rb2
-rw-r--r--lib/chef/chef_fs/file_system_cache.rb1
-rw-r--r--lib/chef/chef_fs/parallelizer/parallel_enumerable.rb1
-rw-r--r--lib/chef/chef_fs/path_utils.rb3
21 files changed, 57 insertions, 0 deletions
diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb
index 50badef794..6b0cb4630a 100644
--- a/lib/chef/chef_fs/chef_fs_data_store.rb
+++ b/lib/chef/chef_fs/chef_fs_data_store.rb
@@ -279,6 +279,7 @@ class Chef
if !policy_group["policies"] || !policy_group["policies"][path[3]]
raise ChefZero::DataStore::DataNotFoundError.new(path, entry)
end
+
# The policy group looks like:
# {
# "policies": {
@@ -401,6 +402,7 @@ class Chef
unless group["policies"] && group["policies"].key?(path[3])
raise ChefZero::DataStore::DataNotFoundError.new(path)
end
+
group["policies"].delete(path[3])
group
end
@@ -413,6 +415,7 @@ class Chef
if result.size == members.size
raise ChefZero::DataStore::DataNotFoundError.new(path)
end
+
result
end
@@ -424,6 +427,7 @@ class Chef
if result.size == invitations.size
raise ChefZero::DataStore::DataNotFoundError.new(path)
end
+
result
end
@@ -457,6 +461,7 @@ class Chef
policies.children.each do |policy|
# We want to delete just the ones that == POLICY
next unless policy.name.rpartition("-")[0] == path[1]
+
policy.delete(false)
FileSystemCache.instance.delete!(policy.file_path)
found_policy = true
@@ -502,6 +507,7 @@ class Chef
revisions << revision if name == path[1]
end
raise ChefZero::DataStore::DataNotFoundError.new(path) if revisions.empty?
+
revisions
end
@@ -544,6 +550,7 @@ class Chef
if result.empty?
raise ChefZero::DataStore::DataNotFoundError.new(path)
end
+
result
else
# list /cookbooks/name = <single version>
@@ -846,6 +853,7 @@ class Chef
def ensure_dir(entry)
return entry if entry.exists?
+
parent = entry.parent
if parent
ensure_dir(parent)
diff --git a/lib/chef/chef_fs/command_line.rb b/lib/chef/chef_fs/command_line.rb
index 56c0c574e8..217fb208d3 100644
--- a/lib/chef/chef_fs/command_line.rb
+++ b/lib/chef/chef_fs/command_line.rb
@@ -44,6 +44,7 @@ class Chef
when :directory_to_file
next if diff_filter && diff_filter !~ /T/
+
if output_mode == :name_only
yield "#{new_path}\n"
elsif output_mode == :name_status
@@ -54,6 +55,7 @@ class Chef
when :file_to_directory
next if diff_filter && diff_filter !~ /T/
+
if output_mode == :name_only
yield "#{new_path}\n"
elsif output_mode == :name_status
@@ -71,6 +73,7 @@ class Chef
new_path += File.extname(old_path)
end
next if diff_filter && diff_filter !~ /D/
+
if output_mode == :name_only
yield "#{new_path}\n"
elsif output_mode == :name_status
@@ -86,6 +89,7 @@ class Chef
when :added
next if diff_filter && diff_filter !~ /A/
+
if output_mode == :name_only
yield "#{new_path}\n"
elsif output_mode == :name_status
@@ -101,6 +105,7 @@ class Chef
when :modified
next if diff_filter && diff_filter !~ /M/
+
if output_mode == :name_only
yield "#{new_path}\n"
elsif output_mode == :name_status
diff --git a/lib/chef/chef_fs/config.rb b/lib/chef/chef_fs/config.rb
index c6f6878c00..7940dbf1fe 100644
--- a/lib/chef/chef_fs/config.rb
+++ b/lib/chef/chef_fs/config.rb
@@ -272,6 +272,7 @@ class Chef
# cookbooks -> cookbook_path
singular_name = INFLECTIONS[object_name]
raise "Unknown object name #{object_name}" unless singular_name
+
variable_name = "#{singular_name}_path"
paths = Array(@chef_config[variable_name]).flatten
result[object_name] = paths.map { |path| File.expand_path(path) }
diff --git a/lib/chef/chef_fs/file_pattern.rb b/lib/chef/chef_fs/file_pattern.rb
index 88604e2b8f..5e3e276541 100644
--- a/lib/chef/chef_fs/file_pattern.rb
+++ b/lib/chef/chef_fs/file_pattern.rb
@@ -74,6 +74,7 @@ class Chef
argument_is_absolute = Chef::ChefFS::PathUtils.is_absolute?(path)
return false if is_absolute != argument_is_absolute
+
path = path[1, path.length - 1] if argument_is_absolute
path_parts = Chef::ChefFS::PathUtils.split(path)
@@ -81,6 +82,7 @@ class Chef
return false if regexp_parts.length <= path_parts.length && !has_double_star
# If the path doesn't match up to this point, children won't match either.
return false if path_parts.zip(regexp_parts).any? { |part, regexp| !regexp.nil? && !regexp.match(part) }
+
# Otherwise, it's possible we could match: the path matches to this point, and the pattern is longer than the path.
# TODO There is one edge case where the double star comes after some characters like abc**def--we could check whether the next
# bit of path starts with abc in that case.
@@ -114,6 +116,7 @@ class Chef
path = path[1, path.length - 1] if Chef::ChefFS::PathUtils.is_absolute?(path)
dirs_in_path = Chef::ChefFS::PathUtils.split(path).length
return nil if exact_parts.length <= dirs_in_path
+
exact_parts[dirs_in_path]
end
@@ -124,6 +127,7 @@ class Chef
# abc/x\\yz.exact_path == 'abc/xyz'
def exact_path
return nil if has_double_star || exact_parts.any? { |part| part.nil? }
+
result = Chef::ChefFS::PathUtils.join(*exact_parts)
is_absolute ? Chef::ChefFS::PathUtils.join("", result) : result
end
@@ -151,6 +155,7 @@ class Chef
def match?(path)
argument_is_absolute = Chef::ChefFS::PathUtils.is_absolute?(path)
return false if is_absolute != argument_is_absolute
+
path = path[1, path.length - 1] if argument_is_absolute
!!regexp.match(path)
end
@@ -213,6 +218,7 @@ class Chef
if has_double_star_prev
raise ArgumentError, ".. overlapping a ** is unsupported"
end
+
full_regexp_parts.pop
normalized_parts.pop
if !@has_double_star
diff --git a/lib/chef/chef_fs/file_system.rb b/lib/chef/chef_fs/file_system.rb
index ff85a4a1b1..dbf0704c9e 100644
--- a/lib/chef/chef_fs/file_system.rb
+++ b/lib/chef/chef_fs/file_system.rb
@@ -94,6 +94,7 @@ class Chef
def self.resolve_path(entry, path)
return entry if path.length == 0
return resolve_path(entry.root, path) if path[0, 1] == "/" && entry.root != entry
+
if path[0, 1] == "/"
path = path[1, path.length - 1]
end
diff --git a/lib/chef/chef_fs/file_system/base_fs_object.rb b/lib/chef/chef_fs/file_system/base_fs_object.rb
index f7516232ac..e319232b0e 100644
--- a/lib/chef/chef_fs/file_system/base_fs_object.rb
+++ b/lib/chef/chef_fs/file_system/base_fs_object.rb
@@ -32,6 +32,7 @@ class Chef
if name != ""
raise ArgumentError, "Name of root object must be empty string: was '#{name}' instead"
end
+
@path = "/"
end
end
@@ -108,12 +109,14 @@ class Chef
# Override children to report your *actual* list of children as an array.
def children
raise NotFoundError.new(self) if !exists?
+
[]
end
# Expand this entry into a chef object (Chef::Role, ::Node, etc.)
def chef_object
raise NotFoundError.new(self) if !exists?
+
nil
end
@@ -125,6 +128,7 @@ class Chef
# file_contents. This is used for knife upload /cookbooks/cookbookname.
def create_child(name, file_contents)
raise NotFoundError.new(self) if !exists?
+
raise OperationNotAllowedError.new(:create_child, self)
end
@@ -132,6 +136,7 @@ class Chef
# directory unless recurse is true.
def delete(recurse)
raise NotFoundError.new(self) if !exists?
+
raise OperationNotAllowedError.new(:delete, self)
end
@@ -167,12 +172,14 @@ class Chef
# Read the contents of this file entry.
def read
raise NotFoundError.new(self) if !exists?
+
raise OperationNotAllowedError.new(:read, self)
end
# Write the contents of this file entry.
def write(file_contents)
raise NotFoundError.new(self) if !exists?
+
raise OperationNotAllowedError.new(:write, self)
end
diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb
index b8e1b7b43c..336f3592d5 100644
--- a/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb
@@ -69,6 +69,7 @@ class Chef
def can_have_child?(name, is_dir)
return name != "root_files" if is_dir
+
true
end
@@ -117,6 +118,7 @@ class Chef
end
else
raise NotFoundError.new(self) if !exists?
+
raise MustDeleteRecursivelyError.new(self, "#{path_for_printing} must be deleted recursively")
end
end
@@ -134,6 +136,7 @@ class Chef
if !other.dir?
return [ !exists?, nil, nil ]
end
+
are_same = true
Chef::ChefFS::CommandLine.diff_entries(self, other, nil, :name_only).each do |type, old_entry, new_entry|
if [ :directory_to_file, :file_to_directory, :deleted, :added, :modified ].include?(type)
diff --git a/lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb b/lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb
index fb8a537596..317fbb91cc 100644
--- a/lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb
@@ -50,6 +50,7 @@ class Chef
def delete(recurse)
if !recurse
raise NotFoundError.new(self) if !exists?
+
raise MustDeleteRecursivelyError.new(self, "#{path_for_printing} must be deleted recursively")
end
begin
diff --git a/lib/chef/chef_fs/file_system/chef_server/environments_dir.rb b/lib/chef/chef_fs/file_system/chef_server/environments_dir.rb
index 09ab30c799..f213430d14 100644
--- a/lib/chef/chef_fs/file_system/chef_server/environments_dir.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/environments_dir.rb
@@ -41,11 +41,13 @@ class Chef
def delete(recurse)
raise NotFoundError.new(self) if !exists?
+
raise DefaultEnvironmentCannotBeModifiedError.new(:delete, self)
end
def write(file_contents)
raise NotFoundError.new(self) if !exists?
+
raise DefaultEnvironmentCannotBeModifiedError.new(:write, self)
end
end
diff --git a/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb b/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb
index d0674075c6..073bea7a95 100644
--- a/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb
@@ -95,6 +95,7 @@ class Chef
if e.response.code == "404"
raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
end
+
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:children, self, e, "HTTP error retrieving children: #{e}")
end
# Anything else is unexpected (OperationFailedError)
diff --git a/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb b/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb
index 7c5e01bf7e..d2c5bdc9b7 100644
--- a/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb
@@ -94,6 +94,7 @@ class Chef
if e.response.code == "404"
raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
end
+
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:children, self, e, "HTTP error retrieving children: #{e}")
end
else
diff --git a/lib/chef/chef_fs/file_system/repository/base_file.rb b/lib/chef/chef_fs/file_system/repository/base_file.rb
index ade5fc2039..b36a1ae214 100644
--- a/lib/chef/chef_fs/file_system/repository/base_file.rb
+++ b/lib/chef/chef_fs/file_system/repository/base_file.rb
@@ -132,6 +132,7 @@ class Chef
if is_ruby_file?
raise Chef::ChefFS::FileSystem::RubyFileError.new(:write, self)
end
+
if content && write_pretty_json && is_json_file?
content = minimize(content, self)
end
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 5098d55727..2d8699621b 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
@@ -34,6 +34,7 @@ class Chef
def fs_entry_valid?
return false unless File.directory?(file_path) && name_valid?
+
if can_upload?
true
else
@@ -54,6 +55,7 @@ class Chef
if exists?
raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, self)
end
+
begin
Dir.mkdir(file_path)
rescue Errno::EEXIST
@@ -103,6 +105,7 @@ class Chef
elsif name == Chef::Cookbook::CookbookVersionLoader::UPLOADED_COOKBOOK_VERSION_FILE
return false
end
+
super(name, is_dir)
end
@@ -110,6 +113,7 @@ class Chef
def self.canonical_cookbook_name(entry_name)
name_match = Chef::ChefFS::FileSystem::ChefServer::VersionedCookbookDir::VALID_VERSIONED_COOKBOOK_NAME.match(entry_name)
return nil if name_match.nil?
+
name_match[1]
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 a6cae64c6d..7a0dc80f79 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
@@ -101,6 +101,7 @@ class Chef
if child.exists?
raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, child)
end
+
if file_contents
child.write(file_contents)
else
@@ -124,6 +125,7 @@ class Chef
if !recurse
raise MustDeleteRecursivelyError.new(self, $!)
end
+
FileUtils.rm_r(file_path)
else
File.delete(file_path)
diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb
index 30ccf8c736..6b5da9421c 100644
--- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb
+++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb
@@ -180,6 +180,7 @@ class Chef
def make_child_entry(name)
if CHILDREN.include?(name)
return nil if !root_dir
+
return root_dir.child(name)
end
@@ -187,6 +188,7 @@ class Chef
if paths.size == 0
return NonexistentFSObject.new(name, self)
end
+
case name
when "acls"
dirs = paths.map { |path| AclsDir.new(name, self, path) }
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 4fb214cff8..442fa879ad 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
@@ -30,6 +30,7 @@ class Chef
# want to spend a lot of time adding code to the main Chef libraries
canonical_name = canonical_cookbook_name(File.basename(file_path))
raise "When versioned_cookbooks mode is on, cookbook #{file_path} must match format <cookbook_name>-x.y.z" unless canonical_name
+
# KLUDGE: We shouldn't have to use instance_variable_set
loader.instance_variable_set(:@cookbook_name, canonical_name)
loader.load_cookbooks
diff --git a/lib/chef/chef_fs/file_system/repository/directory.rb b/lib/chef/chef_fs/file_system/repository/directory.rb
index f428e939d3..1275cb4621 100644
--- a/lib/chef/chef_fs/file_system/repository/directory.rb
+++ b/lib/chef/chef_fs/file_system/repository/directory.rb
@@ -71,6 +71,7 @@ class Chef
def children
return FileSystemCache.instance.children(file_path) if FileSystemCache.instance.exist?(file_path)
+
children = dir_ls.sort
.map { |child_name| make_child_entry(child_name) }
.select { |new_child| new_child.fs_entry_valid? && can_have_child?(new_child.name, new_child.dir?) }
@@ -84,6 +85,7 @@ class Chef
if child.exists?
raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, child)
end
+
FileSystemCache.instance.delete!(child.file_path)
if file_contents
child.write(file_contents)
@@ -122,6 +124,7 @@ class Chef
if exists?
raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, self)
end
+
begin
FileSystemCache.instance.delete!(file_path)
Dir.mkdir(file_path)
@@ -139,6 +142,7 @@ class Chef
if !recurse
raise MustDeleteRecursivelyError.new(self, $!)
end
+
FileUtils.rm_r(file_path)
FileSystemCache.instance.delete!(file_path)
else
diff --git a/lib/chef/chef_fs/file_system/repository/file_system_entry.rb b/lib/chef/chef_fs/file_system/repository/file_system_entry.rb
index 33b4de8014..ed6a3d598c 100644
--- a/lib/chef/chef_fs/file_system/repository/file_system_entry.rb
+++ b/lib/chef/chef_fs/file_system/repository/file_system_entry.rb
@@ -92,6 +92,7 @@ class Chef
if child.exists?
raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, child)
end
+
if file_contents
child.write(file_contents)
else
@@ -111,6 +112,7 @@ class Chef
if !recurse
raise MustDeleteRecursivelyError.new(self, $!)
end
+
FileUtils.rm_r(file_path)
else
File.delete(file_path)
diff --git a/lib/chef/chef_fs/file_system_cache.rb b/lib/chef/chef_fs/file_system_cache.rb
index e36dbbce7c..0024a49098 100644
--- a/lib/chef/chef_fs/file_system_cache.rb
+++ b/lib/chef/chef_fs/file_system_cache.rb
@@ -73,6 +73,7 @@ class Chef
def _get_parent(path)
parts = ChefFS::PathUtils.split(path)
return nil if parts.nil? || parts.length < 2
+
ChefFS::PathUtils.join(*parts[0..-2])
end
end
diff --git a/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb b/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb
index 2291220ef8..143b38aef8 100644
--- a/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb
+++ b/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb
@@ -147,6 +147,7 @@ class Chef
if @each_running
raise "each() called on parallel enumerable twice simultaneously! Bad mojo"
end
+
@each_running = true
begin
# Grab all the inputs, yielding any responses during enumeration
diff --git a/lib/chef/chef_fs/path_utils.rb b/lib/chef/chef_fs/path_utils.rb
index fe6428a5b1..c490f50c17 100644
--- a/lib/chef/chef_fs/path_utils.rb
+++ b/lib/chef/chef_fs/path_utils.rb
@@ -42,6 +42,7 @@ class Chef
def self.join(*parts)
return "" if parts.length == 0
+
# Determine if it started with a slash
absolute = parts[0].length == 0 || parts[0].length > 0 && parts[0] =~ /^#{regexp_path_separator}/
# Remove leading and trailing slashes from each part so that the join will work (and the slash at the end will go away)
@@ -87,6 +88,7 @@ class Chef
# This can occur if a path such as "C:" is given. Ruby gives the parent as "C:."
# for reasons only it knows.
raise ArgumentError "Invalid path segment #{path}" if parent_path.length > path.length
+
begin
path = File.realpath(path)
break
@@ -113,6 +115,7 @@ class Chef
def self.descendant_path(path, ancestor)
candidate_fragment = path[0, ancestor.length]
return nil unless PathUtils.os_path_eq?(candidate_fragment, ancestor)
+
if ancestor.length == path.length
""
elsif path[ancestor.length, 1] =~ /#{PathUtils.regexp_path_separator}/