diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2019-07-02 15:09:07 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2019-07-02 15:09:07 -0700 |
commit | 7a1a6c8ef26c787e4b6dd1602f3d158b37e81720 (patch) | |
tree | 1e390cd535b38368d091cbb33e5d419408d5ce00 /lib/chef/chef_fs/file_system | |
parent | 77f8739a4741e2370e40ec39345a92a6ea393a1a (diff) | |
download | chef-7a1a6c8ef26c787e4b6dd1602f3d158b37e81720.tar.gz |
fix Layout/EmptyLineAfterGuardClause
i like this one, gives visual priority to returns or raises that are
buried in the middle of things.
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/chef_fs/file_system')
13 files changed, 31 insertions, 0 deletions
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) |