chef 0.8.10 → 0.8.14

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of chef might be problematic. Click here for more details.

Files changed (105) hide show
  1. data/bin/chef-client +2 -2
  2. data/bin/chef-solo +1 -2
  3. data/bin/knife +1 -2
  4. data/bin/shef +2 -5
  5. data/lib/chef.rb +11 -7
  6. data/lib/chef/application.rb +25 -20
  7. data/lib/chef/application/client.rb +12 -7
  8. data/lib/chef/application/knife.rb +7 -1
  9. data/lib/chef/application/solo.rb +1 -1
  10. data/lib/chef/applications.rb +4 -0
  11. data/lib/chef/cache/checksum.rb +7 -6
  12. data/lib/chef/certificate.rb +2 -2
  13. data/lib/chef/client.rb +28 -4
  14. data/lib/chef/config.rb +4 -3
  15. data/lib/chef/cookbook_loader.rb +6 -1
  16. data/lib/chef/daemon.rb +2 -0
  17. data/lib/chef/data_bag_item.rb +2 -1
  18. data/lib/chef/exceptions.rb +5 -0
  19. data/lib/chef/file_cache.rb +18 -18
  20. data/lib/chef/index_queue/indexable.rb +5 -3
  21. data/lib/chef/knife.rb +45 -13
  22. data/lib/chef/knife/client_list.rb +1 -1
  23. data/lib/chef/knife/client_show.rb +1 -1
  24. data/lib/chef/knife/configure.rb +47 -36
  25. data/lib/chef/knife/cookbook_list.rb +1 -1
  26. data/lib/chef/knife/cookbook_metadata.rb +22 -27
  27. data/lib/chef/knife/cookbook_metadata_from_file.rb +40 -0
  28. data/lib/chef/knife/cookbook_show.rb +2 -2
  29. data/lib/chef/knife/cookbook_site_download.rb +57 -0
  30. data/lib/chef/knife/cookbook_site_list.rb +55 -0
  31. data/lib/chef/knife/cookbook_site_search.rb +50 -0
  32. data/lib/chef/knife/cookbook_site_show.rb +56 -0
  33. data/lib/chef/knife/cookbook_site_vendor.rb +114 -0
  34. data/lib/chef/knife/cookbook_test.rb +103 -0
  35. data/lib/chef/knife/cookbook_upload.rb +29 -38
  36. data/lib/chef/knife/data_bag_edit.rb +1 -1
  37. data/lib/chef/knife/data_bag_list.rb +2 -2
  38. data/lib/chef/knife/data_bag_show.rb +1 -1
  39. data/lib/chef/knife/ec2_instance_data.rb +1 -1
  40. data/lib/chef/knife/index_rebuild.rb +2 -2
  41. data/lib/chef/knife/node_from_file.rb +1 -1
  42. data/lib/chef/knife/node_list.rb +2 -2
  43. data/lib/chef/knife/node_run_list_add.rb +1 -1
  44. data/lib/chef/knife/node_run_list_remove.rb +1 -1
  45. data/lib/chef/knife/node_show.rb +1 -1
  46. data/lib/chef/knife/rackspace_server_create.rb +156 -0
  47. data/lib/chef/knife/rackspace_server_delete.rb +57 -0
  48. data/lib/chef/knife/rackspace_server_list.rb +59 -0
  49. data/lib/chef/knife/role_from_file.rb +1 -1
  50. data/lib/chef/knife/role_list.rb +1 -1
  51. data/lib/chef/knife/role_show.rb +1 -1
  52. data/lib/chef/knife/search.rb +1 -1
  53. data/lib/chef/knife/ssh.rb +21 -4
  54. data/lib/chef/knife/terremark_server_create.rb +152 -0
  55. data/lib/chef/knife/terremark_server_delete.rb +87 -0
  56. data/lib/chef/knife/terremark_server_list.rb +77 -0
  57. data/lib/chef/mixin/command.rb +11 -9
  58. data/lib/chef/mixin/params_validate.rb +1 -1
  59. data/lib/chef/mixin/recipe_definition_dsl_core.rb +4 -1
  60. data/lib/chef/mixin/template.rb +6 -5
  61. data/lib/chef/mixin/xml_escape.rb +3 -3
  62. data/lib/chef/mixins.rb +16 -0
  63. data/lib/chef/node.rb +53 -52
  64. data/lib/chef/openid_registration.rb +0 -1
  65. data/lib/chef/platform.rb +171 -137
  66. data/lib/chef/provider.rb +2 -2
  67. data/lib/chef/provider/cron.rb +22 -22
  68. data/lib/chef/provider/deploy/revision.rb +5 -1
  69. data/lib/chef/provider/erl_call.rb +2 -2
  70. data/lib/chef/provider/file.rb +44 -23
  71. data/lib/chef/provider/group/dscl.rb +6 -4
  72. data/lib/chef/provider/mdadm.rb +0 -4
  73. data/lib/chef/provider/mount/mount.rb +20 -8
  74. data/lib/chef/provider/package.rb +1 -1
  75. data/lib/chef/provider/package/freebsd.rb +22 -18
  76. data/lib/chef/provider/package/rubygems.rb +7 -10
  77. data/lib/chef/provider/remote_directory.rb +15 -0
  78. data/lib/chef/provider/remote_file.rb +73 -50
  79. data/lib/chef/provider/script.rb +10 -8
  80. data/lib/chef/provider/service/windows.rb +129 -0
  81. data/lib/chef/provider/subversion.rb +1 -1
  82. data/lib/chef/provider/template.rb +51 -50
  83. data/lib/chef/providers.rb +80 -0
  84. data/lib/chef/recipe.rb +2 -4
  85. data/lib/chef/resource.rb +21 -7
  86. data/lib/chef/resource/cron.rb +14 -5
  87. data/lib/chef/resource/deploy.rb +52 -45
  88. data/lib/chef/resource/execute.rb +1 -1
  89. data/lib/chef/resource/file.rb +16 -8
  90. data/lib/chef/resource/mount.rb +1 -1
  91. data/lib/chef/resource/remote_directory.rb +19 -10
  92. data/lib/chef/resource/scm.rb +23 -16
  93. data/lib/chef/resource/service.rb +10 -1
  94. data/lib/chef/resources.rb +60 -0
  95. data/lib/chef/rest.rb +234 -189
  96. data/lib/chef/rest/auth_credentials.rb +78 -0
  97. data/lib/chef/{application/server.rb → rest/cookie_jar.rb} +18 -6
  98. data/lib/chef/rest/rest_request.rb +151 -0
  99. data/lib/chef/role.rb +38 -46
  100. data/lib/chef/streaming_cookbook_uploader.rb +8 -2
  101. data/lib/chef/tasks/chef_repo.rake +14 -4
  102. data/lib/chef/util/file_edit.rb +0 -1
  103. data/lib/chef/webui_user.rb +0 -1
  104. metadata +46 -9
  105. data/distro/suse/etc/init.d/chef-client +0 -121
@@ -18,9 +18,9 @@
18
18
  # See the License for the specific language governing permissions and
19
19
  # limitations under the License.
20
20
 
21
- $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
22
-
23
21
  require 'rubygems'
22
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
23
+ require 'chef'
24
24
  require 'chef/application/client'
25
25
 
26
26
  Chef::Application::Client.new.run
@@ -18,9 +18,8 @@
18
18
  # See the License for the specific language governing permissions and
19
19
  # limitations under the License.
20
20
 
21
- $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
22
-
23
21
  require 'rubygems'
22
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
24
23
  require 'chef/application/solo'
25
24
 
26
25
  Chef::Application::Solo.new.run
data/bin/knife CHANGED
@@ -18,9 +18,8 @@
18
18
  # See the License for the specific language governing permissions and
19
19
  # limitations under the License.
20
20
 
21
- $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
22
-
23
21
  require 'rubygems'
22
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
24
23
  require 'chef/application/knife'
25
24
 
26
25
  Chef::Application::Knife.new.run
data/bin/shef CHANGED
@@ -26,11 +26,8 @@ require "irb"
26
26
  require "irb/completion"
27
27
 
28
28
  # TODO::EVIL
29
- begin
30
- require "#{File.dirname(__FILE__)}/../lib/chef"
31
- rescue LoadError
32
- # the bin got moved, e.g., by rubygems
33
- end
29
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
30
+
34
31
  require "chef/shef"
35
32
 
36
33
  # dirty hack to make IRB initialize shef
@@ -16,22 +16,25 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- $:.unshift(File.dirname(__FILE__)) unless
20
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
21
-
22
- require 'rubygems'
23
19
  require 'extlib'
24
20
  require 'chef/exceptions'
25
21
  require 'chef/log'
26
22
  require 'chef/config'
27
- Dir[File.join(File.dirname(__FILE__), 'chef/mixin/**/*.rb')].sort.each { |lib| require lib }
23
+ require 'chef/providers'
24
+ require 'chef/resources'
25
+
26
+ require 'chef/compile'
27
+ require 'chef/daemon'
28
+ require 'chef/runner'
29
+ require 'chef/webui_user'
30
+ require 'chef/openid_registration'
28
31
 
29
32
  class Chef
30
- VERSION = '0.8.10'
33
+ VERSION = "0.8.14"
31
34
  end
32
35
 
33
36
  # Adds a Dir.glob to Ruby 1.8.5, for compat
34
- if RUBY_VERSION < "1.8.6"
37
+ if RUBY_VERSION < "1.8.6" || RUBY_PLATFORM =~ /mswin|mingw32|windows/
35
38
  class Dir
36
39
  class << self
37
40
  alias_method :glob_, :glob
@@ -41,6 +44,7 @@ if RUBY_VERSION < "1.8.6"
41
44
  pattern.is_a? Array and !pattern.empty?
42
45
  ) or pattern.is_a? String
43
46
  )
47
+ pattern.gsub!(/\\/, "/") if RUBY_PLATFORM =~ /mswin|mingw32|windows/
44
48
  [pattern].flatten.inject([]) { |r, p| r + glob_(p, flags) }
45
49
  end
46
50
  alias_method :[], :glob
@@ -6,9 +6,9 @@
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
8
8
  # You may obtain a copy of the License at
9
- #
9
+ #
10
10
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
  # Unless required by applicable law or agreed to in writing, software
13
13
  # distributed under the License is distributed on an "AS IS" BASIS,
14
14
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,10 +22,10 @@ require 'mixlib/cli'
22
22
 
23
23
  class Chef::Application
24
24
  include Mixlib::CLI
25
-
26
- def initialize
25
+
26
+ def initialize
27
27
  super
28
-
28
+
29
29
  trap("TERM") do
30
30
  Chef::Application.fatal!("SIGTERM received, stopping", 1)
31
31
  end
@@ -33,23 +33,28 @@ class Chef::Application
33
33
  trap("INT") do
34
34
  Chef::Application.fatal!("SIGINT received, stopping", 2)
35
35
  end
36
-
37
- trap("HUP") do
38
- Chef::Log.info("SIGHUP received, reconfiguring")
39
- reconfigure
36
+
37
+ unless RUBY_PLATFORM =~ /mswin|mingw32|windows/
38
+ trap("HUP") do
39
+ Chef::Log.info("SIGHUP received, reconfiguring")
40
+ reconfigure
41
+ end
40
42
  end
41
-
43
+
42
44
  at_exit do
43
- # tear down the logger
44
- end
45
+ # tear down the logger
46
+ end
47
+
48
+ # Always switch to a readable directory. Keeps subsequent Dir.chdir() {}
49
+ # from failing due to permissions when launched as a less privileged user.
45
50
  end
46
-
51
+
47
52
  # Reconfigure the application. You'll want to override and super this method.
48
53
  def reconfigure
49
54
  configure_chef
50
55
  configure_logging
51
56
  end
52
-
57
+
53
58
  # Get this party started
54
59
  def run
55
60
  reconfigure
@@ -60,25 +65,25 @@ class Chef::Application
60
65
  # Parse the configuration file
61
66
  def configure_chef
62
67
  parse_options
63
-
68
+
64
69
  Chef::Config.from_file(config[:config_file]) if !config[:config_file].nil? && File.exists?(config[:config_file]) && File.readable?(config[:config_file])
65
70
  Chef::Config.merge!(config)
66
71
  end
67
-
72
+
68
73
  # Initialize and configure the logger
69
74
  def configure_logging
70
75
  Chef::Log.init(Chef::Config[:log_location])
71
76
  Chef::Log.level = Chef::Config[:log_level]
72
77
  end
73
-
78
+
74
79
  # Called prior to starting the application, by the run method
75
80
  def setup_application
76
- raise Chef::Exceptions::Application, "#{self.to_s}: you must override setup_application"
81
+ raise Chef::Exceptions::Application, "#{self.to_s}: you must override setup_application"
77
82
  end
78
-
83
+
79
84
  # Actually run the application
80
85
  def run_application
81
- raise Chef::Exceptions::Application, "#{self.to_s}: you must override run_application"
86
+ raise Chef::Exceptions::Application, "#{self.to_s}: you must override run_application"
82
87
  end
83
88
 
84
89
  class << self
@@ -113,12 +113,18 @@ class Chef::Application::Client < Chef::Application
113
113
  :description => "The chef server URL",
114
114
  :proc => nil
115
115
 
116
- option :validation_token,
117
- :short => "-t TOKEN",
118
- :long => "--token TOKEN",
119
- :description => "Set the openid validation token",
120
- :proc => nil
121
-
116
+ option :validation_key,
117
+ :short => "-K KEY_FILE",
118
+ :long => "--validation_key KEY_FILE",
119
+ :description => "Set the validation key file location, used for registering new clients",
120
+ :proc => nil
121
+
122
+ option :client_key,
123
+ :short => "-k KEY_FILE",
124
+ :long => "--client_key KEY_FILE",
125
+ :description => "Set the client key file location",
126
+ :proc => nil
127
+
122
128
  option :version,
123
129
  :short => "-v",
124
130
  :long => "--version",
@@ -185,7 +191,6 @@ class Chef::Application::Client < Chef::Application
185
191
 
186
192
  @chef_client = Chef::Client.new
187
193
  @chef_client.json_attribs = @chef_client_json
188
- @chef_client.validation_token = Chef::Config[:validation_token]
189
194
  @chef_client.node_name = Chef::Config[:node_name]
190
195
  end
191
196
 
@@ -94,7 +94,13 @@ class Chef::Application::Knife < Chef::Application
94
94
  :short => "-p",
95
95
  :long => "--print-after",
96
96
  :description => "Show the data after a destructive operation"
97
-
97
+
98
+ option :format,
99
+ :short => "-f FORMAT",
100
+ :long => "--format FORMAT",
101
+ :description => "Which format to use for output",
102
+ :default => "json"
103
+
98
104
  option :version,
99
105
  :short => "-v",
100
106
  :long => "--version",
@@ -158,7 +158,7 @@ class Chef::Application::Solo < Chef::Application
158
158
  end
159
159
 
160
160
  if Chef::Config[:recipe_url]
161
- cookbooks_path = Chef::Config[:cookbook_path].detect{|e| e =~ /\/cookbooks\/*$/ }
161
+ cookbooks_path = Array(Chef::Config[:cookbook_path]).detect{|e| e =~ /\/cookbooks\/*$/ }
162
162
  recipes_path = File.expand_path(File.join(cookbooks_path, '..'))
163
163
  target_file = File.join(recipes_path, 'recipes.tgz')
164
164
 
@@ -0,0 +1,4 @@
1
+ require 'chef/application/agent'
2
+ require 'chef/application/client'
3
+ require 'chef/application/knife'
4
+ require 'chef/application/solo'
@@ -28,8 +28,9 @@ class Chef
28
28
  instance.checksum_for_file(*args)
29
29
  end
30
30
 
31
- def checksum_for_file(file)
32
- key, fstat = filename_to_key(file), File.stat(file)
31
+ def checksum_for_file(file, key=nil)
32
+ key ||= generate_key(file)
33
+ fstat = File.stat(file)
33
34
  lookup_checksum(key, fstat) || generate_checksum(key, file, fstat)
34
35
  end
35
36
 
@@ -48,6 +49,10 @@ class Chef
48
49
  checksum
49
50
  end
50
51
 
52
+ def generate_key(file, group="chef")
53
+ "#{group}-file-#{file.gsub(/(#{File::SEPARATOR}|\.)/, '-')}"
54
+ end
55
+
51
56
  private
52
57
 
53
58
  def file_unchanged?(cached, fstat)
@@ -59,10 +64,6 @@ class Chef
59
64
  IO.foreach(file) {|line| digest.update(line) }
60
65
  digest.hexdigest
61
66
  end
62
-
63
- def filename_to_key(file)
64
- "chef-file-#{file.gsub(/(#{File::SEPARATOR}|\.)/, '-')}"
65
- end
66
67
 
67
68
  end
68
69
  end
@@ -128,11 +128,11 @@ class Chef
128
128
  return client_cert.public_key, client_keypair
129
129
  end
130
130
 
131
- def gen_validation_key(name=Chef::Config[:validation_client_name], key_file=Chef::Config[:validation_key])
131
+ def gen_validation_key(name=Chef::Config[:validation_client_name], key_file=Chef::Config[:validation_key], admin=false)
132
132
  # Create the validation key
133
133
  api_client = Chef::ApiClient.new
134
134
  api_client.name(name)
135
- api_client.admin(true)
135
+ api_client.admin(admin)
136
136
 
137
137
  begin
138
138
  # If both the couch record and file exist, don't do anything. Otherwise,
@@ -37,12 +37,11 @@ class Chef
37
37
  include Chef::Mixin::GenerateURL
38
38
  include Chef::Mixin::Checksum
39
39
 
40
- attr_accessor :node, :registration, :json_attribs, :validation_token, :node_name, :ohai, :rest
40
+ attr_accessor :node, :registration, :json_attribs, :node_name, :ohai, :rest
41
41
 
42
42
  # Creates a new Chef::Client.
43
43
  def initialize()
44
44
  @node = nil
45
- @validation_token = nil
46
45
  @registration = nil
47
46
  @json_attribs = nil
48
47
  @node_name = nil
@@ -85,7 +84,6 @@ class Chef
85
84
  build_node(@node_name)
86
85
  save_node
87
86
  sync_cookbooks
88
- save_node
89
87
  converge
90
88
  save_node
91
89
 
@@ -274,7 +272,7 @@ class Chef
274
272
  Chef::FileCache.list.each do |cache_file|
275
273
  if cache_file =~ /^cookbooks\/(.+?)\//
276
274
  unless cookbook_hash.has_key?($1)
277
- Chef::Log.info("Removing #{cache_file} from the cache; it's cookbook is no longer needed on this client.")
275
+ Chef::Log.info("Removing #{cache_file} from the cache; its cookbook is no longer needed on this client.")
278
276
  Chef::FileCache.delete(cache_file)
279
277
  end
280
278
  end
@@ -312,6 +310,22 @@ class Chef
312
310
  Chef::Log.debug("Compiling recipes for node #{@node_name}")
313
311
  unless solo
314
312
  Chef::Config[:cookbook_path] = File.join(Chef::Config[:file_cache_path], "cookbooks")
313
+ Chef::Log.warn("Node #{@node_name} has an empty run list.") if @node.run_list.empty?
314
+ else
315
+ # Check for cookbooks in the path given
316
+ # Chef::Config[:cookbook_path] can be a string or an array
317
+ # if it's an array, go through it and check each one, raise error at the last one if no files are found
318
+ Chef::Log.fatal "BUGBUG: cookbook_path: #{Chef::Config[:cookbook_path]}"
319
+ Array(Chef::Config[:cookbook_path]).each_with_index do |cookbook_path, index|
320
+ if directory_not_empty?(cookbook_path)
321
+ Chef::Log.fatal "BUGBUG: cb path not empty: #{cookbook_path}"
322
+ break
323
+ else
324
+ msg = "No cookbook found in #{Chef::Config[:cookbook_path].inspect}, make sure cookboook_path is set correctly."
325
+ Chef::Log.fatal(msg)
326
+ raise Chef::Exceptions::CookbookNotFound, msg if is_last_element?(index, Chef::Config[:cookbook_path])
327
+ end
328
+ end
315
329
  end
316
330
  compile = Chef::Compile.new(@node)
317
331
 
@@ -319,6 +333,16 @@ class Chef
319
333
  Chef::Runner.new(@node, compile.collection, compile.definitions, compile.cookbook_loader).converge
320
334
  true
321
335
  end
336
+
337
+ private
338
+
339
+ def directory_not_empty?(path)
340
+ File.exists?(path) && (Dir.entries(path).size > 2)
341
+ end
342
+
343
+ def is_last_element?(index, object)
344
+ object.kind_of?(Array) ? index == object.size - 1 : true
345
+ end
322
346
 
323
347
  end
324
348
  end
@@ -143,15 +143,14 @@ class Chef
143
143
  search_url "http://localhost:4000"
144
144
  solo false
145
145
  splay nil
146
- ssl_client_cert ""
147
- ssl_client_key ""
146
+ ssl_client_cert nil
147
+ ssl_client_key nil
148
148
  ssl_verify_mode :verify_none
149
149
  ssl_ca_path nil
150
150
  ssl_ca_file nil
151
151
  template_url "http://localhost:4000"
152
152
  umask 0022
153
153
  user nil
154
- validation_token nil
155
154
  role_path "/var/chef/roles"
156
155
  role_url "http://localhost:4000"
157
156
  recipe_url nil
@@ -197,5 +196,7 @@ class Chef
197
196
  cache_type "BasicFile"
198
197
  cache_options({ :path => "/var/chef/cache/checksums", :skip_expires => true })
199
198
 
199
+ # Arbitrary knife configuration data
200
+ knife Hash.new
200
201
  end
201
202
  end
@@ -114,7 +114,12 @@ class Chef
114
114
  @cookbook[cookbook].provider_files = cookbook_settings[cookbook][:provider_files].values
115
115
  @metadata[cookbook] = Chef::Cookbook::Metadata.new(@cookbook[cookbook])
116
116
  cookbook_settings[cookbook][:metadata_files].each do |meta_json|
117
- @metadata[cookbook].from_json(IO.read(meta_json))
117
+ begin
118
+ @metadata[cookbook].from_json(IO.read(meta_json))
119
+ rescue JSON::ParserError
120
+ puts "Couldn't parse JSON in " + meta_json
121
+ raise
122
+ end
118
123
  end
119
124
  end
120
125
  end
@@ -121,6 +121,8 @@ class Chef
121
121
  # Change process user/group to those specified in Chef::Config
122
122
  #
123
123
  def change_privilege
124
+ Dir.chdir("/")
125
+
124
126
  if Chef::Config[:user] and Chef::Config[:group]
125
127
  Chef::Log.info("About to change privilege to #{Chef::Config[:user]}:#{Chef::Config[:group]}")
126
128
  _change_privilege(Chef::Config[:user], Chef::Config[:group])
@@ -22,7 +22,8 @@ require 'chef/config'
22
22
  require 'chef/mixin/params_validate'
23
23
  require 'chef/mixin/from_file'
24
24
  require 'chef/couchdb'
25
- require 'chef/data_bag_item'
25
+ require 'chef/index_queue'
26
+ require 'chef/data_bag'
26
27
  require 'extlib'
27
28
  require 'json'
28
29
 
@@ -37,5 +37,10 @@ class Chef
37
37
  class CannotWritePrivateKey < RuntimeError; end
38
38
  class RoleNotFound < RuntimeError; end
39
39
  class ValidationFailed < ArgumentError; end
40
+ class InvalidPrivateKey < ArgumentError; end
41
+ class ConfigurationError < ArgumentError; end
42
+ class RedirectLimitExceeded < RuntimeError; end
43
+ class AmbiguousRunlistSpecification < ArgumentError; end
44
+ class CookbookNotFound < RuntimeError; end
40
45
  end
41
46
  end
@@ -6,9 +6,9 @@
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
8
8
  # You may obtain a copy of the License at
9
- #
9
+ #
10
10
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
  # Unless required by applicable law or agreed to in writing, software
13
13
  # distributed under the License is distributed on an "AS IS" BASIS,
14
14
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,7 +26,7 @@ class Chef
26
26
  class << self
27
27
  include Chef::Mixin::ParamsValidate
28
28
  include Chef::Mixin::CreatePath
29
-
29
+
30
30
  # Write a file to the File Cache.
31
31
  #
32
32
  # === Parameters
@@ -47,7 +47,7 @@ class Chef
47
47
  :contents => { :kind_of => String },
48
48
  }
49
49
  )
50
-
50
+
51
51
  file_path_array = File.split(path)
52
52
  file_name = file_path_array.pop
53
53
  cache_path = create_cache_path(File.join(file_path_array))
@@ -56,7 +56,7 @@ class Chef
56
56
  io.close
57
57
  true
58
58
  end
59
-
59
+
60
60
  # Move a file in to the cache. Useful with the REST raw file output.
61
61
  #
62
62
  # === Parameteres
@@ -73,19 +73,19 @@ class Chef
73
73
  :path => { :kind_of => String },
74
74
  }
75
75
  )
76
-
76
+
77
77
  file_path_array = File.split(path)
78
78
  file_name = file_path_array.pop
79
79
  if File.exists?(file) && File.writable?(file)
80
80
  FileUtils.mv(
81
- file,
81
+ file,
82
82
  File.join(create_cache_path(File.join(file_path_array), true), file_name)
83
83
  )
84
84
  else
85
85
  raise RuntimeError, "Cannot move #{file} to #{path}!"
86
86
  end
87
87
  end
88
-
88
+
89
89
  # Read a file from the File Cache
90
90
  #
91
91
  # === Parameters
@@ -116,7 +116,7 @@ class Chef
116
116
  cache_path
117
117
  end
118
118
  end
119
-
119
+
120
120
  # Delete a file from the File Cache
121
121
  #
122
122
  # === Parameters
@@ -140,7 +140,7 @@ class Chef
140
140
  end
141
141
  true
142
142
  end
143
-
143
+
144
144
  # List all the files in the Cache
145
145
  #
146
146
  # === Returns
@@ -149,19 +149,19 @@ class Chef
149
149
  keys = Array.new
150
150
  Dir[File.join(Chef::Config[:file_cache_path], '**', '*')].each do |f|
151
151
  if File.file?(f)
152
- path = f.match("^#{Chef::Config[:file_cache_path]}\/(.+)")[1]
152
+ path = f.match("^#{Dir[Chef::Config[:file_cache_path]].first}\/(.+)")[1]
153
153
  keys << path
154
154
  end
155
155
  end
156
156
  keys
157
157
  end
158
-
158
+
159
159
  # Whether or not this file exists in the Cache
160
160
  #
161
161
  # === Parameters
162
- # path:: The path to the file you want to check - is relative
162
+ # path:: The path to the file you want to check - is relative
163
163
  # to Chef::Config[:file_cache_path]
164
- #
164
+ #
165
165
  # === Returns
166
166
  # True:: If the file exists
167
167
  # False:: If it does not
@@ -181,25 +181,25 @@ class Chef
181
181
  false
182
182
  end
183
183
  end
184
-
184
+
185
185
  # Create a full path to a given file in the cache. By default,
186
186
  # also creates the path if it does not exist.
187
187
  #
188
188
  # === Parameters
189
189
  # path:: The path to create, relative to Chef::Config[:file_cache_path]
190
190
  # create_if_missing:: True by default - whether to create the path if it does not exist
191
- #
191
+ #
192
192
  # === Returns
193
193
  # String:: The fully expanded path
194
194
  def create_cache_path(path, create_if_missing=true)
195
195
  cache_dir = File.expand_path(File.join(Chef::Config[:file_cache_path], path))
196
196
  if create_if_missing
197
- create_path(cache_dir)
197
+ create_path(cache_dir)
198
198
  else
199
199
  cache_dir
200
200
  end
201
201
  end
202
-
202
+
203
203
  end
204
204
  end
205
205
  end