diff options
author | John Keiser <john@johnkeiser.com> | 2016-01-12 17:11:11 -0800 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2016-01-13 13:40:13 -0800 |
commit | 6d97b322563f882a41fe6739a89d8075f63612d2 (patch) | |
tree | be0b84e3ccdee8f0cefe1dd7285ce4151d800558 /lib | |
parent | b750db5517c5c88e52f7bad9e75b9f7ababe9e42 (diff) | |
download | chef-6d97b322563f882a41fe6739a89d8075f63612d2.tar.gz |
Split versioned cookbook dir from unversioned
Diffstat (limited to 'lib')
5 files changed, 77 insertions, 25 deletions
diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb index 51de0bfd86..4bc7842f8c 100644 --- a/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb @@ -28,23 +28,23 @@ class Chef module ChefFS module FileSystem module ChefServer + # Unversioned cookbook. + # + # /cookbooks/NAME + # + # Children look like: + # + # - metadata.rb + # - attributes/ + # - libraries/ + # - recipes/ + # class CookbookDir < BaseFSDir def initialize(name, parent, options = {}) super(name, parent) @exists = options[:exists] - # If the name is apache2-1.0.0 and versioned_cookbooks is on, we know - # the actual cookbook_name and version. - if root.versioned_cookbooks - if name =~ VALID_VERSIONED_COOKBOOK_NAME - @cookbook_name = $1 - @version = $2 - else - @exists = false - end - else - @cookbook_name = name - @version = root.cookbook_version # nil unless --cookbook-version specified in download/diff - end + @cookbook_name = name + @version = root.cookbook_version # nil unless --cookbook-version specified in download/diff end attr_reader :cookbook_name, :version @@ -61,10 +61,6 @@ class Chef :root_files => { } } - # See Erchef code - # https://github.com/opscode/chef_objects/blob/968a63344d38fd507f6ace05f73d53e9cd7fb043/src/chef_regex.erl#L94 - VALID_VERSIONED_COOKBOOK_NAME = /^([.a-zA-Z0-9_-]+)-(\d+\.\d+\.\d+)$/ - def add_child(child) @children << child end diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb index 060999339d..5fd8111d7a 100644 --- a/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb @@ -49,7 +49,7 @@ class Chef def children @children ||= begin - result = root.get_json(api_path).keys.map { |cookbook_name| CookbookDir.new(cookbook_name, self, :exists => true) } + result = root.get_json(api_path).keys.map { |cookbook_name| CookbookDir.new(cookbook_name, self, exists: true) } result.sort_by(&:name) end end diff --git a/lib/chef/chef_fs/file_system/chef_server/versioned_cookbook_dir.rb b/lib/chef/chef_fs/file_system/chef_server/versioned_cookbook_dir.rb new file mode 100644 index 0000000000..25b3fa38cc --- /dev/null +++ b/lib/chef/chef_fs/file_system/chef_server/versioned_cookbook_dir.rb @@ -0,0 +1,45 @@ +# +# Author:: John Keiser (<jkeiser@opscode.com>) +# Copyright:: Copyright (c) 2012 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'chef/chef_fs/file_system/chef_server/versioned_cookbook_dir' + +class Chef + module ChefFS + module FileSystem + module ChefServer + class VersionedCookbookDir < CookbookDir + # See Erchef code + # https://github.com/opscode/chef_objects/blob/968a63344d38fd507f6ace05f73d53e9cd7fb043/src/chef_regex.erl#L94 + VALID_VERSIONED_COOKBOOK_NAME = /^([.a-zA-Z0-9_-]+)-(\d+\.\d+\.\d+)$/ + + def initialize(name, parent, options = {}) + super(name, parent) + # If the name is apache2-1.0.0 and versioned_cookbooks is on, we know + # the actual cookbook_name and version. + if name =~ VALID_VERSIONED_COOKBOOK_NAME + @cookbook_name = $1 + @version = $2 + else + @exists = false + end + end + end + end + end + end +end diff --git a/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb b/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb index 3ead25f533..bccb34bb37 100644 --- a/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb @@ -17,23 +17,33 @@ # require 'chef/chef_fs/file_system/chef_server/cookbooks_dir' +require 'chef/chef_fs/file_system/chef_server/versioned_cookbook_dir' class Chef module ChefFS module FileSystem module ChefServer - # cookbooks/ - # apache2-1.0.0/ - # apache2-1.0.1/ - # mysql-2.0.5/ + # /cookbooks + # + # Its children look like: + # + # - apache2-1.0.0 + # - apache2-1.0.1 + # - mysql-2.0.5 + # class VersionedCookbooksDir < CookbooksDir + def make_child_entry(name) + result = @children.select { |child| child.name == name }.first if @children + result || VersionedCookbookDir.new(name, self) + end + def children @children ||= begin result = [] root.get_json("#{api_path}/?num_versions=all").each_pair do |cookbook_name, cookbooks| cookbooks['versions'].each do |cookbook_version| - result << CookbookDir.new("#{cookbook_name}-#{cookbook_version['version']}", self, :exists => true) + result << VersionedCookbookDir.new("#{cookbook_name}-#{cookbook_version['version']}", self) end end result.sort_by(&:name) @@ -81,7 +91,7 @@ class Chef end def can_have_child?(name, is_dir) - is_dir && name =~ Chef::ChefFS::FileSystem::ChefServer::CookbookDir::VALID_VERSIONED_COOKBOOK_NAME + is_dir && name =~ Chef::ChefFS::FileSystem::ChefServer::VersionedCookbookDir::VALID_VERSIONED_COOKBOOK_NAME end end end diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb index 91b8652de3..1ebb8b42cf 100644 --- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb @@ -18,6 +18,7 @@ require 'chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry' require 'chef/chef_fs/file_system/chef_server/cookbook_dir' +require 'chef/chef_fs/file_system/chef_server/versioned_cookbook_dir' require 'chef/chef_fs/file_system/not_found_error' require 'chef/cookbook/chefignore' require 'chef/cookbook/cookbook_version_loader' @@ -74,7 +75,7 @@ class Chef # Exposed as a class method so that it can be used elsewhere def self.canonical_cookbook_name(entry_name) - name_match = Chef::ChefFS::FileSystem::ChefServer::CookbookDir::VALID_VERSIONED_COOKBOOK_NAME.match(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 |