summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@chef.io>2016-02-05 13:21:23 -0800
committerdanielsdeleo <dan@chef.io>2016-02-16 15:26:43 -0800
commitac3eee3026be917e5ac095a4ac7a3c6673d24aa0 (patch)
tree26f4819a94ecd414dbfbca2e34f65e625795d502
parenta73e4b50789a50bd7e8b29d5470e05640a1fc551 (diff)
downloadchef-ac3eee3026be917e5ac095a4ac7a3c6673d24aa0.tar.gz
Remove unused code from level 2 inlined
-rw-r--r--lib/chef/chef_fs/file_system/repository/chef_repository_file_system_data_bags_dir.rb144
1 files changed, 97 insertions, 47 deletions
diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_data_bags_dir.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_data_bags_dir.rb
index 80828c936c..a6883892ac 100644
--- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_data_bags_dir.rb
+++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_data_bags_dir.rb
@@ -51,10 +51,15 @@ class Chef
## end
# inlined initialize
- def initialize(name, parent, file_path = nil)
+ #
+ # original method signature: def initialize(name, parent, file_path = nil)
+ #
+ # the only caller of this should never give a nil path
+ def initialize(name, parent, file_path)
super(name, parent)
- @file_path = file_path || "#{parent.file_path}/#{name}"
- @data_handler = Chef::ChefFS::DataHandler::DataBagItemDataHandler.new
+ @file_path = file_path # || "#{parent.file_path}/#{name}"
+ # Seems like this has to be important, but where is it used?
+ #@data_handler = Chef::ChefFS::DataHandler::DataBagItemDataHandler.new
end
@@ -86,18 +91,20 @@ class Chef
## end
# Inlined version of the above
- def data_handler
- @data_handler
- end
+ # Seems like this has to be important, but where is it used?
+ ##def data_handler
+ ## @data_handler
+ ##end
- def chef_object
- begin
- return data_handler.chef_object(Chef::JSONCompat.parse(read))
- rescue
- Chef::Log.error("Could not read #{path_for_printing} into a Chef object: #{$!}")
- end
- nil
- end
+ # Inherited from ChefRepositoryFileSystemEntry, but apparently unused
+ ## def chef_object
+ ## begin
+ ## return data_handler.chef_object(Chef::JSONCompat.parse(read))
+ ## rescue
+ ## Chef::Log.error("Could not read #{path_for_printing} into a Chef object: #{$!}")
+ ## end
+ ## nil
+ ## end
# Overridden by subclass
## def can_have_child?(name, is_dir)
@@ -149,59 +156,102 @@ class Chef
end
end
+ # Inherited from FileSystemEntry but has extra cases we cannot hit all the cases
+ ## def create_child(child_name, file_contents=nil)
+ ## child = make_child_entry(child_name)
+ ## if child.exists?
+ ## raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, child)
+ ## end
+ ## if file_contents
+ ## child.write(file_contents)
+ ## else
+ ## begin
+ ## Dir.mkdir(child.file_path)
+ ## rescue Errno::EEXIST
+ ## raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, child)
+ ## end
+ ## end
+ ## child
+ ## end
+
+ # Inherited from FileSystemEntry, modified to remove code we can't hit
def create_child(child_name, file_contents=nil)
child = make_child_entry(child_name)
if child.exists?
raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, child)
end
- if file_contents
- child.write(file_contents)
- else
- begin
- Dir.mkdir(child.file_path)
- rescue Errno::EEXIST
- raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, child)
- end
+ begin
+ Dir.mkdir(child.file_path)
+ rescue Errno::EEXIST
+ raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, child)
end
child
end
- def dir?
- File.directory?(file_path)
- end
+ # Inherited from FileSystemEntry but this is a data bag dir, it should always be a dir
+ ## def dir?
+ ## File.directory?(file_path)
+ ## end
+ # Inherited from FileSystemEntry but with other stuff inlined we don't need it any more
+ ## def dir?
+ ## true
+ ## end
+
+ # Inherited from FileSystemEntry but it seems we cannot hit all of these cases
+ ## def delete(recurse)
+ ## begin
+ ## if dir?
+ ## if !recurse
+ ## raise MustDeleteRecursivelyError.new(self, $!)
+ ## end
+ ## FileUtils.rm_r(file_path)
+ ## else
+ ## File.delete(file_path)
+ ## end
+ ## rescue Errno::ENOENT
+ ## raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
+ ## end
+ ## end
+
+ # Inherited from FileSystemEntry but it seems we cannot hit all of these cases
def delete(recurse)
- begin
- if dir?
- if !recurse
- raise MustDeleteRecursivelyError.new(self, $!)
- end
- FileUtils.rm_r(file_path)
- else
- File.delete(file_path)
+ if exists?
+ if !recurse
+ raise MustDeleteRecursivelyError.new(self, $!)
end
- rescue Errno::ENOENT
+ FileUtils.rm_r(file_path)
+ else
raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
end
end
+
+ # Inherited from FileSystemEntry but it seems we cannot hit all of these cases
+ ## def exists?
+ ## File.exists?(file_path) && (parent.nil? || parent.can_have_child?(name, dir?))
+ ## end
+
+ # Inherited from FileSystemEntry but there are extra cases we don't seem to hit
def exists?
- File.exists?(file_path) && (parent.nil? || parent.can_have_child?(name, dir?))
+ File.exists?(file_path) # && (parent.nil? || parent.can_have_child?(name, dir?))
end
- def read
- begin
- File.open(file_path, "rb") {|f| f.read}
- rescue Errno::ENOENT
- raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
- end
- end
+ # Inherited from FileSystemEntry but seems unused
+ ## def read
+ ## begin
+ ## File.open(file_path, "rb") {|f| f.read}
+ ## rescue Errno::ENOENT
+ ## raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!)
+ ## end
+ ## end
- def write(content)
- File.open(file_path, "wb") do |file|
- file.write(content)
- end
- end
+ # Inherited from FileSystemEntry but seems unused
+ ## def write(content)
+ ## File.open(file_path, "wb") do |file|
+ ## file.write(content)
+ ## end
+ ## end
# Overridden in superclass (ChefRepositoryFileSystemEntry)
## protected