Class: Chef::ChefFS::FileSystem::Repository::ChefRepositoryFileSystemCookbookDir
Overview
Represents ROOT/cookbooks/:cookbook
Instance Attribute Summary
#file_path, #name, #parent, #path, #recursive, #ruby_only
Class Method Summary
collapse
Instance Method Summary
collapse
#child, #compare_to, #create_child, #delete, #exists?, #initialize, #path_for_printing, #read, #root, #write_pretty_json
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
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)
Chef::ChefFS::FileSystem.copy_to(Chef::ChefFS::FilePattern.new("/#{cookbook_path}"), from_fs, self, nil, { :purge => true })
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
|