diff options
author | John Keiser <jkeiser@opscode.com> | 2014-04-22 17:01:14 -0700 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2014-04-22 17:01:14 -0700 |
commit | d89b956b954c5c62bb59fe5cf84a932206a76e85 (patch) | |
tree | fbc86e85e4225c393075f0c6af8ad2776b7f8b35 /lib/chef/chef_fs | |
parent | fac536adc158c680424b43f841cc730d7b2abd01 (diff) | |
download | chef-d89b956b954c5c62bb59fe5cf84a932206a76e85.tar.gz |
Don't include .uploaded-cookbook-version.json in knife upload
of cookbooks
Diffstat (limited to 'lib/chef/chef_fs')
3 files changed, 45 insertions, 19 deletions
diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb index 566ca9f9a2..28f0af4695 100644 --- a/lib/chef/chef_fs/chef_fs_data_store.rb +++ b/lib/chef/chef_fs/chef_fs_data_store.rb @@ -23,7 +23,7 @@ require 'chef/chef_fs/file_pattern' require 'chef/chef_fs/file_system' require 'chef/chef_fs/file_system/not_found_error' require 'chef/chef_fs/file_system/memory_root' - +require 'fileutils' class Chef module ChefFS class ChefFSDataStore @@ -209,7 +209,7 @@ class Chef select { |name, version| name == path[1] }. map { |name, version| version } end - if result == [] + if result.empty? raise ChefZero::DataStore::DataNotFoundError.new(path) end result @@ -260,12 +260,13 @@ class Chef end def write_cookbook(path, data, *options) - # Create a little Chef::ChefFS memory filesystem with the data if Chef::Config.versioned_cookbooks - cookbook_path = "cookbooks/#{path[1]}-#{path[2]}" + cookbook_path = File.join('cookbooks', "#{path[1]}-#{path[2]}") else - cookbook_path = "cookbooks/#{path[1]}" + cookbook_path = File.join('cookbooks', path[1]) end + + # Create a little Chef::ChefFS memory filesystem with the data cookbook_fs = Chef::ChefFS::FileSystem::MemoryRoot.new('uploading') cookbook = JSON.parse(data, :create_additions => false) cookbook.each_pair do |key, value| @@ -273,19 +274,22 @@ class Chef value.each do |file| if file.is_a?(Hash) && file.has_key?('checksum') file_data = @memory_store.get(['file_store', 'checksums', file['checksum']]) - cookbook_fs.add_file("#{cookbook_path}/#{file['path']}", file_data) + cookbook_fs.add_file(File.join(cookbook_path, file['path']), file_data) end end end end - # 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}"), cookbook_fs, chef_fs, nil, {:purge => true}) - # Create the .uploaded-cookbook-version.json - cookbook_entry = Chef::ChefFS::FileSystem.resolve_path(chef_fs, cookbook_path) - cookbook_entry.write_uploaded_cookbook_version(data) + cookbooks = chef_fs.child('cookbooks') + if !cookbooks.exists? + cookbooks = chef_fs.create_child('cookbooks') + end + # We are calling a cookbooks-specific API, so get multiplexed_dirs out of the way if it is there + if cookbooks.respond_to?(:multiplexed_dirs) + cookbooks = cookbooks.write_dir + end + cookbooks.write_cookbook(cookbook_path, data, cookbook_fs) end def split_name_version(entry_name) diff --git a/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb b/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb index dc5f6c03ac..629c1d9acb 100644 --- a/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb @@ -45,8 +45,9 @@ class Chef loader.load_cookbooks return loader.cookbook_version - rescue - Chef::Log.error("Could not read #{path_for_printing} into a Chef object: #{$!}\n#{$!.backtrace.join("\n")}") + rescue => e + Chef::Log.error("Could not read #{path_for_printing} into a Chef object: #{e}") + Chef::Log.error(e.backtrace.join("\n")) end nil end @@ -83,10 +84,12 @@ class Chef self.class.canonical_cookbook_name(entry_name) end - def write_uploaded_cookbook_version(data) - File.open("#{file_path}/#{Chef::Cookbook::CookbookVersionLoader::UPLOADED_COOKBOOK_VERSION_FILE}", 'w') do |file| - file.write(data) - end + def uploaded_cookbook_version_path + File.join(file_path, Chef::Cookbook::CookbookVersionLoader::UPLOADED_COOKBOOK_VERSION_FILE) + end + + def can_upload? + File.exists?(uploaded_cookbook_version_path) || children.size > 0 end protected diff --git a/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb b/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb index 6e16f18f24..7c60b51114 100644 --- a/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb @@ -43,7 +43,7 @@ class Chef map { |child_name| make_child(child_name) }. select do |entry| # empty cookbooks and cookbook directories are ignored - if entry.children.size == 0 + if !entry.can_upload? Chef::Log.warn("Cookbook '#{entry.name}' is empty or entirely chefignored at #{entry.path_for_printing}") false else @@ -59,6 +59,25 @@ class Chef is_dir && !name.start_with?('.') end + def write_cookbook(cookbook_path, cookbook_version_json, from_fs) + cookbook_name = File.basename(cookbook_path) + child = make_child(cookbook_name) + + # 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, child, nil, {:purge => true}) + + # Write out .uploaded-cookbook-version.json + cookbook_file_path = File.join(file_path, cookbook_name) + if !File.exists?(cookbook_file_path) + FileUtils.mkdir_p(cookbook_file_path) + end + uploaded_cookbook_version_path = File.join(cookbook_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 + protected def make_child(child_name) |