Skip to content

Commit 8da98f5

Browse files
committed
Files that start with . and .. are now found via the cookbook loader - fixes CHEF-87
1 parent 86f39b1 commit 8da98f5

7 files changed

Lines changed: 131 additions & 79 deletions

File tree

chef/bin/chef-solo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ require 'rubygems'
2828

2929
config = {
3030
:config_file => "/etc/chef/solo.rb",
31-
:log_level => :info,
31+
:log_level => :info
3232
}
3333

3434
Chef::Config[:solo] = true
@@ -38,7 +38,7 @@ opts = OptionParser.new do |opts|
3838
opts.on("-c CONFIG", "--config CONFIG", "The Chef Config file to use") do |c|
3939
config[:config_file] = c
4040
end
41-
opts.on("-r RECIPEURL", "--recipes RECIPEURL", "Pull down a remote gzipped tarball of recipes and untar it into the proer place.") do |r|
41+
opts.on("-r RECIPEURL", "--recipe-url RECIPEURL", "Pull down a remote gzipped tarball of recipes and untar it into the proer place.") do |r|
4242
config[:recipes] = r
4343
end
4444
opts.on("-j JSON_ATTRIBS", "--json-attributes JSON_ATTRIBS", "Load attributes from a JSON file") do |j|

chef/lib/chef/cookbook_loader.rb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,23 @@ def load_cookbooks
6464
cookbook_settings[cookbook_name][:recipe_files],
6565
cookbook_settings[cookbook_name][:ignore_regexes]
6666
)
67+
load_files_unless_basename(
68+
File.join(cookbook, "libraries", "*.rb"),
69+
cookbook_settings[cookbook_name][:lib_files],
70+
cookbook_settings[cookbook_name][:ignore_regexes]
71+
)
6772
load_cascading_files(
68-
File.join(cookbook, "templates", "**", "*.erb"),
73+
"*.erb",
6974
File.join(cookbook, "templates"),
7075
cookbook_settings[cookbook_name][:template_files],
7176
cookbook_settings[cookbook_name][:ignore_regexes]
7277
)
7378
load_cascading_files(
74-
File.join(cookbook, "files", "**", "*"),
79+
"*",
7580
File.join(cookbook, "files"),
7681
cookbook_settings[cookbook_name][:remote_files],
7782
cookbook_settings[cookbook_name][:ignore_regexes]
7883
)
79-
load_cascading_files(
80-
File.join(cookbook, "libraries", "**", "*.rb"),
81-
File.join(cookbook, "libraries"),
82-
cookbook_settings[cookbook_name][:lib_files],
83-
cookbook_settings[cookbook_name][:ignore_regexes]
84-
)
8584
end
8685
end
8786
cookbook_settings.each_key do |cookbook|
@@ -125,7 +124,11 @@ def load_ignore_file(ignore_file)
125124
end
126125

127126
def load_cascading_files(file_glob, base_path, result_array, ignore_regexes)
128-
Dir[file_glob].each do |file|
127+
Dir[
128+
File.join(base_path, "**/.[!.]#{file_glob}"),
129+
File.join(base_path, "**/.??#{file_glob}"),
130+
File.join(base_path, "**/#{file_glob}")
131+
].each do |file|
129132
next if skip_file(file, ignore_regexes)
130133
file =~ /^#{base_path}\/(.+)$/
131134
singlecopy = $1

chef/lib/chef/mixin/find_preferred_file.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ def find_preferred_file(cookbook_id, file_type, file_name, fqdn, platform, versi
8787
break if to_send
8888
end
8989

90+
unless to_send
91+
raise Chef::Exception::FileNotFound, "Cannot find a preferred file for #{file_name}!"
92+
end
93+
9094
to_send
9195
end
9296

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I am here to test .dotfiles work in file directories.

chef/spec/unit/cookbook_loader_spec.rb

Lines changed: 83 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -27,91 +27,106 @@
2727
@cl = Chef::CookbookLoader.new()
2828
end
2929

30-
it "should be a Chef::CookbookLoader object" do
31-
@cl.should be_kind_of(Chef::CookbookLoader)
30+
describe "initialize" do
31+
it "should be a Chef::CookbookLoader object" do
32+
@cl.should be_kind_of(Chef::CookbookLoader)
33+
end
3234
end
3335

34-
it "should return cookbook objects with []" do
35-
@cl[:openldap].should be_a_kind_of(Chef::Cookbook)
36-
end
36+
describe "[]" do
37+
it "should return cookbook objects with []" do
38+
@cl[:openldap].should be_a_kind_of(Chef::Cookbook)
39+
end
3740

38-
it "should raise an exception if it cannot find a cookbook with []" do
39-
lambda { @cl[:monkeypoop] }.should raise_error(ArgumentError)
40-
end
4141

42-
it "should allow you to look up available cookbooks with [] and a symbol" do
43-
@cl[:openldap].name.should eql(:openldap)
44-
end
42+
it "should raise an exception if it cannot find a cookbook with []" do
43+
lambda { @cl[:monkeypoop] }.should raise_error(ArgumentError)
44+
end
4545

46-
it "should allow you to look up available cookbooks with [] and a string" do
47-
@cl["openldap"].name.should eql(:openldap)
48-
end
46+
it "should allow you to look up available cookbooks with [] and a symbol" do
47+
@cl[:openldap].name.should eql(:openldap)
48+
end
4949

50-
it "should allow you to iterate over cookbooks with each" do
51-
seen = Hash.new
52-
@cl.each do |cb|
53-
seen[cb.name] = true
50+
it "should allow you to look up available cookbooks with [] and a string" do
51+
@cl["openldap"].name.should eql(:openldap)
5452
end
55-
seen.should have_key(:openldap)
56-
seen.should have_key(:apache2)
5753
end
5854

59-
it "should find all the cookbooks in the cookbook path" do
60-
Chef::Config.cookbook_path << File.join(File.dirname(__FILE__), "..", "data", "hidden-cookbooks")
61-
@cl.load_cookbooks
62-
@cl.detect { |cb| cb.name == :openldap }.should_not eql(nil)
63-
@cl.detect { |cb| cb.name == :apache2 }.should_not eql(nil)
55+
describe "each" do
56+
it "should allow you to iterate over cookbooks with each" do
57+
seen = Hash.new
58+
@cl.each do |cb|
59+
seen[cb.name] = true
60+
end
61+
seen.should have_key(:openldap)
62+
seen.should have_key(:apache2)
63+
end
6464
end
6565

66-
it "should allow you to override an attribute file via cookbook_path" do
67-
@cl[:openldap].attribute_files.detect { |f|
68-
f =~ /cookbooks\/openldap\/attributes\/default.rb/
69-
}.should_not eql(nil)
70-
@cl[:openldap].attribute_files.detect { |f|
71-
f =~ /kitchen\/openldap\/attributes\/default.rb/
72-
}.should eql(nil)
73-
end
66+
describe "load_cookbooks" do
67+
it "should find all the cookbooks in the cookbook path" do
68+
Chef::Config.cookbook_path << File.join(File.dirname(__FILE__), "..", "data", "hidden-cookbooks")
69+
@cl.load_cookbooks
70+
@cl.detect { |cb| cb.name == :openldap }.should_not eql(nil)
71+
@cl.detect { |cb| cb.name == :apache2 }.should_not eql(nil)
72+
end
7473

75-
it "should load different attribute files from deeper paths" do
76-
@cl[:openldap].attribute_files.detect { |f|
77-
f =~ /kitchen\/openldap\/attributes\/robinson.rb/
78-
}.should_not eql(nil)
79-
end
74+
it "should allow you to override an attribute file via cookbook_path" do
75+
@cl[:openldap].attribute_files.detect { |f|
76+
f =~ /cookbooks\/openldap\/attributes\/default.rb/
77+
}.should_not eql(nil)
78+
@cl[:openldap].attribute_files.detect { |f|
79+
f =~ /kitchen\/openldap\/attributes\/default.rb/
80+
}.should eql(nil)
81+
end
8082

81-
it "should allow you to override a definition file via cookbook_path" do
82-
@cl[:openldap].definition_files.detect { |f|
83-
f =~ /cookbooks\/openldap\/definitions\/client.rb/
84-
}.should_not eql(nil)
85-
@cl[:openldap].definition_files.detect { |f|
86-
f =~ /kitchen\/openldap\/definitions\/client.rb/
87-
}.should eql(nil)
88-
end
83+
it "should load different attribute files from deeper paths" do
84+
@cl[:openldap].attribute_files.detect { |f|
85+
f =~ /kitchen\/openldap\/attributes\/robinson.rb/
86+
}.should_not eql(nil)
87+
end
8988

90-
it "should load definition files from deeper paths" do
91-
@cl[:openldap].definition_files.detect { |f|
92-
f =~ /kitchen\/openldap\/definitions\/drewbarrymore.rb/
93-
}.should_not eql(nil)
94-
end
89+
it "should allow you to override a definition file via cookbook_path" do
90+
@cl[:openldap].definition_files.detect { |f|
91+
f =~ /cookbooks\/openldap\/definitions\/client.rb/
92+
}.should_not eql(nil)
93+
@cl[:openldap].definition_files.detect { |f|
94+
f =~ /kitchen\/openldap\/definitions\/client.rb/
95+
}.should eql(nil)
96+
end
9597

96-
it "should allow you to override a recipe file via cookbook_path" do
97-
@cl[:openldap].recipe_files.detect { |f|
98-
f =~ /cookbooks\/openldap\/recipes\/gigantor.rb/
99-
}.should_not eql(nil)
100-
@cl[:openldap].recipe_files.detect { |f|
101-
f =~ /kitchen\/openldap\/recipes\/gigantor.rb/
102-
}.should eql(nil)
103-
end
98+
it "should load definition files from deeper paths" do
99+
@cl[:openldap].definition_files.detect { |f|
100+
f =~ /kitchen\/openldap\/definitions\/drewbarrymore.rb/
101+
}.should_not eql(nil)
102+
end
104103

105-
it "should load recipe files from deeper paths" do
106-
@cl[:openldap].recipe_files.detect { |f|
107-
f =~ /kitchen\/openldap\/recipes\/woot.rb/
108-
}.should_not eql(nil)
109-
end
104+
it "should allow you to override a recipe file via cookbook_path" do
105+
@cl[:openldap].recipe_files.detect { |f|
106+
f =~ /cookbooks\/openldap\/recipes\/gigantor.rb/
107+
}.should_not eql(nil)
108+
@cl[:openldap].recipe_files.detect { |f|
109+
f =~ /kitchen\/openldap\/recipes\/gigantor.rb/
110+
}.should eql(nil)
111+
end
112+
113+
it "should load recipe files from deeper paths" do
114+
@cl[:openldap].recipe_files.detect { |f|
115+
f =~ /kitchen\/openldap\/recipes\/woot.rb/
116+
}.should_not eql(nil)
117+
end
110118

111-
it "should allow you to have an 'ignore' file, which skips loading files in later cookbooks" do
112-
@cl[:openldap].recipe_files.detect { |f|
113-
f =~ /kitchen\/openldap\/recipes\/ignoreme.rb/
114-
}.should eql(nil)
119+
it "should allow you to have an 'ignore' file, which skips loading files in later cookbooks" do
120+
@cl[:openldap].recipe_files.detect { |f|
121+
f =~ /kitchen\/openldap\/recipes\/ignoreme.rb/
122+
}.should eql(nil)
123+
end
124+
125+
it "should find files that start with a ." do
126+
@cl[:openldap].remote_files.detect { |f|
127+
f =~ /\.dotfile$/
128+
}.should =~ /\.dotfile$/
129+
end
115130
end
116131

117132
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is an example dotfile!
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# Cookbook Name:: CHEF-87
3+
# Recipe:: default
4+
#
5+
# Copyright 2009, Opscode
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
remote_file "/tmp/.dotfile" do
21+
source ".dotfile"
22+
end
23+
24+
execute "cat /tmp/.dotfile"
25+
26+
file "/tmp/.dotfile" do
27+
action :delete
28+
end

0 commit comments

Comments
 (0)