summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-04-23 13:25:29 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2018-04-23 13:25:29 -0700
commit3ddf80846c2592f164fbcd83568f05563c0e757e (patch)
treec29eb573e50039dd2536ba008b93647363eb1d28
parentb2ab45f79b17349111657ef138b3b759d5473a0d (diff)
downloadchef-3ddf80846c2592f164fbcd83568f05563c0e757e.tar.gz
Revert "cookbooks metadata are used instead of directory name"lcg/actuall-test-cheffs
This reverts commit 85653e8f25c19273fde0d8d512db29ef13c2a579.
-rw-r--r--lib/chef/chef_fs/chef_fs_data_store.rb50
1 files changed, 32 insertions, 18 deletions
diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb
index cdb793f808..697c2db232 100644
--- a/lib/chef/chef_fs/chef_fs_data_store.rb
+++ b/lib/chef/chef_fs/chef_fs_data_store.rb
@@ -1,6 +1,6 @@
#
# Author:: John Keiser (<jkeiser@chef.io>)
-# Copyright:: Copyright 2012-2016, Chef Software Inc.
+# Copyright:: Copyright 2012-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -307,16 +307,11 @@ class Chef
# GET /cookbooks/NAME/VERSION or /cookbook_artifacts/NAME/IDENTIFIER
elsif %w{cookbooks cookbook_artifacts}.include?(path[0]) && path.length == 3
- with_entry([path[0]]) do |entry|
+ with_entry(path) do |entry|
cookbook_type = path[0]
- cookbook_entry = entry.children.select do |child|
- child.chef_object.full_name == "#{path[1]}-#{path[2]}" ||
- (child.chef_object.name.to_s == path[1] && child.chef_object.identifier == path[2])
- end[0]
- raise ChefZero::DataStore::DataNotFoundError.new(path) if cookbook_entry.nil?
result = nil
begin
- result = Chef::CookbookManifest.new(cookbook_entry.chef_object, policy_mode: cookbook_type == "cookbook_artifacts").to_hash
+ result = Chef::CookbookManifest.new(entry.chef_object, policy_mode: cookbook_type == "cookbook_artifacts").to_hash
rescue Chef::ChefFS::FileSystem::NotFoundError => e
raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e)
end
@@ -325,7 +320,12 @@ class Chef
if value.is_a?(Array)
value.each do |file|
if file.is_a?(Hash) && file.has_key?("checksum")
- relative = ["file_store", "repo", cookbook_type, cookbook_entry.name ]
+ relative = ["file_store", "repo", cookbook_type]
+ if chef_fs.versioned_cookbooks || cookbook_type == "cookbook_artifacts"
+ relative << "#{path[1]}-#{path[2]}"
+ else
+ relative << path[1]
+ end
relative += file[:path].split("/")
file["url"] = ChefZero::RestBase.build_uri(request.base_uri, relative)
end
@@ -519,7 +519,14 @@ class Chef
elsif %w{cookbooks cookbook_artifacts}.include?(path[0]) && path.length == 1
with_entry(path) do |entry|
begin
- entry.children.map { |child| child.chef_object.name.to_s }.uniq
+ if path[0] == "cookbook_artifacts"
+ entry.children.map { |child| child.name.rpartition("-")[0] }.uniq
+ elsif chef_fs.versioned_cookbooks
+ # /cookbooks/name-version -> /cookbooks/name
+ entry.children.map { |child| split_name_version(child.name)[0] }.uniq
+ else
+ entry.children.map { |child| child.name }
+ end
rescue Chef::ChefFS::FileSystem::NotFoundError
# If the cookbooks dir doesn't exist, we have no cookbooks (not 404)
[]
@@ -527,15 +534,22 @@ class Chef
end
elsif %w{cookbooks cookbook_artifacts}.include?(path[0]) && path.length == 2
- result = with_entry([ path[0] ]) do |entry|
- cookbooks = entry.children.map { |child| child.chef_object }
- cookbooks.select { |cookbook| cookbook.name.to_s == path[1] }.
- map { |cookbook| cookbook.version }
- end
- if result.empty?
- raise ChefZero::DataStore::DataNotFoundError.new(path)
+ if chef_fs.versioned_cookbooks || path[0] == "cookbook_artifacts"
+ result = with_entry([ path[0] ]) do |entry|
+ # list /cookbooks/name = filter /cookbooks/name-version down to name
+ entry.children.map { |child| split_name_version(child.name) }.
+ select { |name, version| name == path[1] }.
+ map { |name, version| version }
+ end
+ if result.empty?
+ raise ChefZero::DataStore::DataNotFoundError.new(path)
+ end
+ result
+ else
+ # list /cookbooks/name = <single version>
+ version = get_single_cookbook_version(path)
+ [version]
end
- result
else
result = with_entry(path) do |entry|