Class: Chef::ChefFS::FileSystem::Repository::ChefRepositoryFileSystemCookbookDir
- Inherits:
-
ChefRepositoryFileSystemCookbookEntry
- Object
- ChefRepositoryFileSystemCookbookEntry
- Chef::ChefFS::FileSystem::Repository::ChefRepositoryFileSystemCookbookDir
- Defined in:
- lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb
Overview
Represents ROOT/cookbooks/:cookbook
Direct Known Subclasses
ChefRepositoryFileSystemCookbookArtifactDir, ChefRepositoryFileSystemVersionedCookbookDir
Instance Attribute Summary
Attributes inherited from ChefRepositoryFileSystemCookbookEntry
#file_path, #name, #parent, #path, #recursive, #ruby_only
Class Method Summary collapse
-
.canonical_cookbook_name(entry_name) ⇒ Object
Exposed as a class method so that it can be used elsewhere.
Instance Method Summary collapse
- #can_have_child?(name, is_dir) ⇒ Boolean
- #can_upload? ⇒ Boolean
- #canonical_cookbook_name(entry_name) ⇒ Object
-
#chef_object ⇒ Object
Customizations of base class.
- #children ⇒ Object
- #create(file_contents = nil) ⇒ Object
- #dir? ⇒ Boolean
-
#fs_entry_valid? ⇒ Boolean
API Required by Respository::Directory.
- #name_valid? ⇒ Boolean
- #uploaded_cookbook_version_path ⇒ Object
- #write(cookbook_path, cookbook_version_json, from_fs) ⇒ Object
Methods inherited from ChefRepositoryFileSystemCookbookEntry
#child, #compare_to, #create_child, #delete, #exists?, #initialize, #path_for_printing, #read, #root, #write_pretty_json
Constructor Details
This class inherits a constructor from Chef::ChefFS::FileSystem::Repository::ChefRepositoryFileSystemCookbookEntry
Class Method Details
.canonical_cookbook_name(entry_name) ⇒ Object
Exposed as a class method so that it can be used elsewhere
112 113 114 115 116 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 112 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? return name_match[1] end |
Instance Method Details
#can_have_child?(name, is_dir) ⇒ Boolean
101 102 103 104 105 106 107 108 109 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 101 def can_have_child?(name, is_dir) if is_dir # Only the given directories will be uploaded. return Chef::ChefFS::FileSystem::ChefServer::CookbookDir::COOKBOOK_SEGMENT_INFO.keys.include?(name.to_sym) && name != "root_files" elsif name == Chef::Cookbook::CookbookVersionLoader::UPLOADED_COOKBOOK_VERSION_FILE return false end super(name, is_dir) end |
#can_upload? ⇒ Boolean
126 127 128 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 126 def can_upload? File.exists?(uploaded_cookbook_version_path) || children.size > 0 end |
#canonical_cookbook_name(entry_name) ⇒ Object
118 119 120 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 118 def canonical_cookbook_name(entry_name) self.class.canonical_cookbook_name(entry_name) end |
#chef_object ⇒ Object
Customizations of base class
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 82 def chef_object begin cb = cookbook_version if !cb Chef::Log.error("Cookbook #{file_path} empty.") raise "Cookbook #{file_path} empty." end cb rescue => e Chef::Log.error("Could not read #{path_for_printing} into a Chef object: #{e}") Chef::Log.error(e.backtrace.join("\n")) raise end end |
#children ⇒ Object
97 98 99 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 97 def children super.select { |entry| !(entry.dir? && entry.children.size == 0 ) } end |
#create(file_contents = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 53 def create(file_contents = nil) if exists? raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, self) end begin Dir.mkdir(file_path) rescue Errno::EEXIST raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, self) end end |
#dir? ⇒ Boolean
49 50 51 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 49 def dir? true end |
#fs_entry_valid? ⇒ Boolean
API Required by Respository::Directory
35 36 37 38 39 40 41 42 43 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 35 def fs_entry_valid? return false unless File.directory?(file_path) && name_valid? if can_upload? true else Chef::Log.warn("Cookbook '#{name}' is empty or entirely chefignored at #{path_for_printing}") false end end |
#name_valid? ⇒ Boolean
45 46 47 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 45 def name_valid? !name.start_with?(".") end |
#uploaded_cookbook_version_path ⇒ Object
122 123 124 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 122 def uploaded_cookbook_version_path File.join(file_path, Chef::Cookbook::CookbookVersionLoader::UPLOADED_COOKBOOK_VERSION_FILE) end |
#write(cookbook_path, cookbook_version_json, from_fs) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 64 def write(cookbook_path, cookbook_version_json, from_fs) # Use the copy/diff algorithm to copy it down so we don't destroy # chefignored data. This is terribly un-thread-safe. Chef::ChefFS::FileSystem.copy_to(Chef::ChefFS::FilePattern.new("/#{cookbook_path}"), from_fs, self, nil, { :purge => true }) # Write out .uploaded-cookbook-version.json # cookbook_file_path = File.join(file_path, cookbook_name) <- this should be the same as self.file_path if !File.exists?(file_path) FileUtils.mkdir_p(file_path) end uploaded_cookbook_version_path = File.join(file_path, Chef::Cookbook::CookbookVersionLoader::UPLOADED_COOKBOOK_VERSION_FILE) File.open(uploaded_cookbook_version_path, "w") do |file| file.write(cookbook_version_json) end end |