chef 11.6.0.hotfix.1 → 11.6.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +15 -0
  2. data/distro/common/html/chef-client.8.html +4 -4
  3. data/distro/common/html/chef-expander.8.html +4 -4
  4. data/distro/common/html/chef-expanderctl.8.html +4 -4
  5. data/distro/common/html/chef-server-webui.8.html +4 -4
  6. data/distro/common/html/chef-server.8.html +4 -4
  7. data/distro/common/html/chef-shell.1.html +4 -4
  8. data/distro/common/html/chef-solo.8.html +4 -4
  9. data/distro/common/html/chef-solr.8.html +4 -4
  10. data/distro/common/html/knife-bootstrap.1.html +4 -4
  11. data/distro/common/html/knife-client.1.html +4 -4
  12. data/distro/common/html/knife-configure.1.html +4 -4
  13. data/distro/common/html/knife-cookbook-site.1.html +4 -4
  14. data/distro/common/html/knife-cookbook.1.html +4 -4
  15. data/distro/common/html/knife-data-bag.1.html +4 -4
  16. data/distro/common/html/knife-environment.1.html +4 -4
  17. data/distro/common/html/knife-exec.1.html +4 -4
  18. data/distro/common/html/knife-index.1.html +4 -4
  19. data/distro/common/html/knife-node.1.html +4 -4
  20. data/distro/common/html/knife-role.1.html +4 -4
  21. data/distro/common/html/knife-search.1.html +4 -4
  22. data/distro/common/html/knife-ssh.1.html +4 -4
  23. data/distro/common/html/knife-status.1.html +4 -4
  24. data/distro/common/html/knife-tag.1.html +4 -4
  25. data/distro/common/html/knife.1.html +4 -4
  26. data/distro/common/man/man1/chef-shell.1 +1 -1
  27. data/distro/common/man/man1/knife-bootstrap.1 +1 -1
  28. data/distro/common/man/man1/knife-client.1 +1 -1
  29. data/distro/common/man/man1/knife-configure.1 +1 -1
  30. data/distro/common/man/man1/knife-cookbook-site.1 +1 -1
  31. data/distro/common/man/man1/knife-cookbook.1 +1 -1
  32. data/distro/common/man/man1/knife-data-bag.1 +1 -1
  33. data/distro/common/man/man1/knife-environment.1 +1 -1
  34. data/distro/common/man/man1/knife-exec.1 +1 -1
  35. data/distro/common/man/man1/knife-index.1 +1 -1
  36. data/distro/common/man/man1/knife-node.1 +1 -1
  37. data/distro/common/man/man1/knife-role.1 +1 -1
  38. data/distro/common/man/man1/knife-search.1 +1 -1
  39. data/distro/common/man/man1/knife-ssh.1 +1 -1
  40. data/distro/common/man/man1/knife-status.1 +1 -1
  41. data/distro/common/man/man1/knife-tag.1 +1 -1
  42. data/distro/common/man/man1/knife.1 +1 -1
  43. data/distro/common/man/man8/chef-client.8 +1 -1
  44. data/distro/common/man/man8/chef-expander.8 +1 -1
  45. data/distro/common/man/man8/chef-expanderctl.8 +1 -1
  46. data/distro/common/man/man8/chef-server-webui.8 +1 -1
  47. data/distro/common/man/man8/chef-server.8 +1 -1
  48. data/distro/common/man/man8/chef-solo.8 +1 -1
  49. data/distro/common/man/man8/chef-solr.8 +1 -1
  50. data/lib/chef/application/client.rb +2 -0
  51. data/lib/chef/application/solo.rb +1 -0
  52. data/lib/chef/application/windows_service.rb +1 -0
  53. data/lib/chef/client.rb +6 -28
  54. data/lib/chef/config.rb +1 -1
  55. data/lib/chef/cookbook/cookbook_version_loader.rb +19 -10
  56. data/lib/chef/cookbook/file_system_file_vendor.rb +7 -4
  57. data/lib/chef/cookbook/metadata.rb +10 -1
  58. data/lib/chef/cookbook/syntax_check.rb +4 -4
  59. data/lib/chef/cookbook_uploader.rb +1 -1
  60. data/lib/chef/cookbook_version.rb +10 -6
  61. data/lib/chef/deprecation/provider/template.rb +1 -1
  62. data/lib/chef/exceptions.rb +0 -2
  63. data/lib/chef/formatters/error_descriptor.rb +4 -5
  64. data/lib/chef/knife/cookbook_site_share.rb +0 -1
  65. data/lib/chef/knife/cookbook_test.rb +0 -1
  66. data/lib/chef/provider/file.rb +1 -2
  67. data/lib/chef/provider/package/yum.rb +1 -2
  68. data/lib/chef/provider/remote_file/cache_control_data.rb +6 -12
  69. data/lib/chef/resource/file.rb +0 -2
  70. data/lib/chef/resource_reporter.rb +2 -5
  71. data/lib/chef/scan_access_control.rb +1 -6
  72. data/lib/chef/util/diff.rb +5 -31
  73. data/lib/chef/version.rb +1 -1
  74. data/lib/chef/win32/api/file.rb +0 -7
  75. data/spec/data/cookbooks/not-nginx/attributes/default.rb +1 -0
  76. data/spec/data/cookbooks/not-nginx/metadata.rb +1 -0
  77. data/spec/data/kitchen/no-really-not-nginx/attributes/default.rb +1 -0
  78. data/spec/data/kitchen/no-really-not-nginx/metadata.rb +1 -0
  79. data/spec/functional/knife/exec_spec.rb +2 -2
  80. data/spec/functional/resource/user_spec.rb +14 -6
  81. data/spec/spec_helper.rb +0 -32
  82. data/spec/support/platform_helpers.rb +0 -12
  83. data/spec/support/shared/functional/file_resource.rb +10 -87
  84. data/spec/support/shared/unit/provider/file.rb +2 -4
  85. data/spec/unit/cookbook/metadata_spec.rb +56 -50
  86. data/spec/unit/cookbook_loader_spec.rb +22 -1
  87. data/spec/unit/provider/package/rubygems_spec.rb +1 -1
  88. data/spec/unit/provider/package/yum_spec.rb +36 -17
  89. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +0 -50
  90. data/spec/unit/resource_reporter_spec.rb +1 -52
  91. data/spec/unit/scan_access_control_spec.rb +2 -4
  92. data/spec/unit/util/diff_spec.rb +11 -351
  93. metadata +9 -93
  94. data/spec/data/apt/chef-integration-test-1.0/debian/changelog +0 -5
  95. data/spec/data/apt/chef-integration-test-1.0/debian/compat +0 -1
  96. data/spec/data/apt/chef-integration-test-1.0/debian/control +0 -13
  97. data/spec/data/apt/chef-integration-test-1.0/debian/copyright +0 -34
  98. data/spec/data/apt/chef-integration-test-1.0/debian/files +0 -1
  99. data/spec/data/apt/chef-integration-test-1.0/debian/rules +0 -13
  100. data/spec/data/apt/chef-integration-test-1.0/debian/source/format +0 -1
  101. data/spec/data/apt/chef-integration-test-1.1/debian/changelog +0 -11
  102. data/spec/data/apt/chef-integration-test-1.1/debian/compat +0 -1
  103. data/spec/data/apt/chef-integration-test-1.1/debian/control +0 -13
  104. data/spec/data/apt/chef-integration-test-1.1/debian/copyright +0 -34
  105. data/spec/data/apt/chef-integration-test-1.1/debian/files +0 -1
  106. data/spec/data/apt/chef-integration-test-1.1/debian/rules +0 -13
  107. data/spec/data/apt/chef-integration-test-1.1/debian/source/format +0 -1
  108. data/spec/data/apt/chef-integration-test_1.0-1_amd64.changes +0 -22
  109. data/spec/data/apt/chef-integration-test_1.0-1_amd64.deb +0 -0
  110. data/spec/data/apt/chef-integration-test_1.0.orig.tar.gz +0 -0
  111. data/spec/data/apt/chef-integration-test_1.1-1_amd64.changes +0 -22
  112. data/spec/data/apt/chef-integration-test_1.1-1_amd64.deb +0 -0
  113. data/spec/data/apt/chef-integration-test_1.1.orig.tar.gz +0 -0
  114. data/spec/data/apt/var/www/apt/conf/distributions +0 -7
  115. data/spec/data/apt/var/www/apt/conf/incoming +0 -4
  116. data/spec/data/apt/var/www/apt/conf/pulls +0 -3
  117. data/spec/data/apt/var/www/apt/db/checksums.db +0 -0
  118. data/spec/data/apt/var/www/apt/db/contents.cache.db +0 -0
  119. data/spec/data/apt/var/www/apt/db/packages.db +0 -0
  120. data/spec/data/apt/var/www/apt/db/references.db +0 -0
  121. data/spec/data/apt/var/www/apt/db/release.caches.db +0 -0
  122. data/spec/data/apt/var/www/apt/db/version +0 -4
  123. data/spec/data/apt/var/www/apt/dists/sid/Release +0 -19
  124. data/spec/data/apt/var/www/apt/dists/sid/main/binary-amd64/Packages +0 -16
  125. data/spec/data/apt/var/www/apt/dists/sid/main/binary-amd64/Packages.gz +0 -0
  126. data/spec/data/apt/var/www/apt/dists/sid/main/binary-amd64/Release +0 -5
  127. data/spec/data/apt/var/www/apt/dists/sid/main/binary-i386/Packages +0 -0
  128. data/spec/data/apt/var/www/apt/pool/main/c/chef-integration-test/chef-integration-test_1.0-1_amd64.deb +0 -0
  129. data/spec/data/apt/var/www/apt/pool/main/c/chef-integration-test/chef-integration-test_1.1-1_amd64.deb +0 -0
  130. data/spec/data/cookbooks/preseed/files/default/preseed-file.seed +0 -1
  131. data/spec/data/cookbooks/preseed/templates/default/preseed-template.seed +0 -1
  132. data/spec/functional/provider/remote_file/cache_control_data_spec.rb +0 -101
  133. data/spec/functional/resource/package_spec.rb +0 -297
data/lib/chef/config.rb CHANGED
@@ -189,7 +189,7 @@ class Chef
189
189
  chef_server_url "https://localhost:443"
190
190
 
191
191
  rest_timeout 300
192
- yum_timeout 900
192
+ yum_timeout 120
193
193
  solo false
194
194
  splay nil
195
195
  why_run false
@@ -18,15 +18,14 @@ class Chef
18
18
  :provider_filenames]
19
19
 
20
20
 
21
- attr_reader :cookbook_name
21
+ attr_reader :cookbook_pathname
22
22
  attr_reader :cookbook_settings
23
23
  attr_reader :metadata_filenames
24
24
 
25
25
  def initialize(path, chefignore=nil)
26
26
  @cookbook_path = File.expand_path( path )
27
- @cookbook_name = File.basename( path )
27
+ @cookbook_pathname = File.basename( path )
28
28
  @chefignore = chefignore
29
- @metadata = Hash.new
30
29
  @relative_path = /#{Regexp.escape(@cookbook_path)}\/(.+)$/
31
30
  @cookbook_settings = {
32
31
  :attribute_filenames => {},
@@ -65,13 +64,18 @@ class Chef
65
64
  if empty?
66
65
  Chef::Log.warn "found a directory #{cookbook_name} in the cookbook path, but it contains no cookbook files. skipping."
67
66
  end
67
+
68
68
  @cookbook_settings
69
69
  end
70
70
 
71
+ def cookbook_name
72
+ metadata.name || @cookbook_pathname
73
+ end
74
+
71
75
  def cookbook_version
72
76
  return nil if empty?
73
77
 
74
- Chef::CookbookVersion.new(@cookbook_name.to_sym).tap do |c|
78
+ Chef::CookbookVersion.new(@cookbook_pathname.to_sym).tap do |c|
75
79
  c.root_dir = @cookbook_path
76
80
  c.attribute_filenames = cookbook_settings[:attribute_filenames].values
77
81
  c.definition_filenames = cookbook_settings[:definition_filenames].values
@@ -83,12 +87,16 @@ class Chef
83
87
  c.provider_filenames = cookbook_settings[:provider_filenames].values
84
88
  c.root_filenames = cookbook_settings[:root_filenames].values
85
89
  c.metadata_filenames = @metadata_filenames
86
- c.metadata = metadata(c)
90
+ c.metadata = load_metadata(c)
87
91
  end
88
92
  end
89
93
 
94
+ def metadata
95
+ @metadata ||= load_metadata(nil)
96
+ end
97
+
90
98
  # Generates the Cookbook::Metadata object
91
- def metadata(cookbook_version)
99
+ def load_metadata(cookbook_version)
92
100
  @metadata = Chef::Cookbook::Metadata.new(cookbook_version)
93
101
  @metadata_filenames.each do |metadata_file|
94
102
  case metadata_file
@@ -100,6 +108,7 @@ class Chef
100
108
  raise RuntimeError, "Invalid metadata file: #{metadata_file} for cookbook: #{cookbook_version}"
101
109
  end
102
110
  end
111
+ Chef::Log.warn "Inferring cookbook name from directory name (#@cookbook_pathname) is deprecated, please set a name in the metadata." unless @metadata.name
103
112
  @metadata
104
113
  end
105
114
 
@@ -150,18 +159,18 @@ class Chef
150
159
 
151
160
  def apply_ruby_metadata(file)
152
161
  begin
153
- @metadata.from_file(file)
162
+ metadata.from_file(file)
154
163
  rescue JSON::ParserError
155
- Chef::Log.error("Error evaluating metadata.rb for #@cookbook_name in " + file)
164
+ Chef::Log.error("Error evaluating metadata.rb for #{cookbook_name} in " + file)
156
165
  raise
157
166
  end
158
167
  end
159
168
 
160
169
  def apply_json_metadata(file)
161
170
  begin
162
- @metadata.from_json(IO.read(file))
171
+ metadata.from_json(IO.read(file))
163
172
  rescue JSON::ParserError
164
- Chef::Log.error("Couldn't parse cookbook metadata JSON for #@cookbook_name in " + file)
173
+ Chef::Log.error("Couldn't parse cookbook metadata JSON for #{cookbook_name} in " + file)
165
174
  raise
166
175
  end
167
176
  end
@@ -37,14 +37,17 @@ class Chef
37
37
  raise ArgumentError, "You must specify at least one repo path" if @repo_paths.empty?
38
38
  end
39
39
 
40
+ def cookbooks
41
+ @cookbooks ||= Chef::CookbookLoader.new(@repo_paths).load_cookbooks
42
+ end
43
+
40
44
  # Implements abstract base's requirement. It looks in the
41
45
  # Chef::Config.cookbook_path file hierarchy for the requested
42
46
  # file.
43
47
  def get_filename(filename)
44
- location = @repo_paths.inject(nil) do |memo, basepath|
45
- candidate_location = File.join(basepath, @cookbook_name, filename)
46
- memo = candidate_location if File.exist?(candidate_location)
47
- memo
48
+ if cookbooks.has_key?(@cookbook_name)
49
+ location = File.join(cookbooks[@cookbook_name].root_dir, filename)
50
+ location = nil unless File.exist?(location)
48
51
  end
49
52
  raise "File #{filename} does not exist for cookbook #{@cookbook_name}" unless location
50
53
 
@@ -91,7 +91,7 @@ class Chef
91
91
  # metadata<Chef::Cookbook::Metadata>
92
92
  def initialize(cookbook=nil, maintainer='YOUR_COMPANY_NAME', maintainer_email='YOUR_EMAIL', license='none')
93
93
  @cookbook = cookbook
94
- @name = cookbook ? cookbook.name : ""
94
+ @name = cookbook ? cookbook.name : nil
95
95
  @long_description = ""
96
96
  self.maintainer(maintainer)
97
97
  self.maintainer_email(maintainer_email)
@@ -468,6 +468,15 @@ class Chef
468
468
  @groupings = o[GROUPINGS] if o.has_key?(GROUPINGS)
469
469
  @recipes = o[RECIPES] if o.has_key?(RECIPES)
470
470
  @version = o[VERSION] if o.has_key?(VERSION)
471
+ #
472
+ # XXX: When a client (berkshelf in particular) uploads metadata without a name field, the hosted chef
473
+ # ruby server will subsequently return empty string ("") for the metadata.name. In erchef uploading
474
+ # metadata without a name field will simply not store or retrieve a name field so we get @name = nil.
475
+ # During the migration from ruby to erchef, metadata.name of "" was migrated faithfully even though it
476
+ # fails validation, and erchef will return this, so we still have to handle this case unless the
477
+ # database is sanitized to remove metadata.name == "".
478
+ #
479
+ @name = nil if !@name.nil? && @name.empty?
471
480
  self
472
481
  end
473
482
 
@@ -85,14 +85,14 @@ class Chef
85
85
  # validated.
86
86
  attr_reader :validated_files
87
87
 
88
- # Creates a new SyntaxCheck given the +cookbook_name+ and a +cookbook_path+.
88
+ # Creates a new SyntaxCheck given the +cookbook_pathname+ and a +cookbook_path+.
89
89
  # If no +cookbook_path+ is given, +Chef::Config.cookbook_path+ is used.
90
- def self.for_cookbook(cookbook_name, cookbook_path=nil)
90
+ def self.for_cookbook(cookbook_pathname, cookbook_path=nil)
91
91
  cookbook_path ||= Chef::Config.cookbook_path
92
92
  unless cookbook_path
93
- raise ArgumentError, "Cannot find cookbook #{cookbook_name} unless Chef::Config.cookbook_path is set or an explicit cookbook path is given"
93
+ raise ArgumentError, "Cannot find cookbook #{cookbook_pathname} unless Chef::Config.cookbook_path is set or an explicit cookbook path is given"
94
94
  end
95
- new(File.join(cookbook_path, cookbook_name.to_s))
95
+ new(File.join(cookbook_path, cookbook_pathname.to_s))
96
96
  end
97
97
 
98
98
  # Create a new SyntaxCheck object
@@ -159,7 +159,7 @@ class Chef
159
159
 
160
160
  def validate_cookbooks
161
161
  cookbooks.each do |cb|
162
- syntax_checker = Chef::Cookbook::SyntaxCheck.for_cookbook(cb.name, @user_cookbook_path)
162
+ syntax_checker = Chef::Cookbook::SyntaxCheck.for_cookbook(cb.pathname, @user_cookbook_path)
163
163
  Chef::Log.info("Validating ruby files")
164
164
  exit(1) unless syntax_checker.validate_ruby_files
165
165
  Chef::Log.info("Validating templates")
@@ -50,7 +50,7 @@ class Chef
50
50
  attr_accessor :resource_filenames
51
51
  attr_accessor :provider_filenames
52
52
  attr_accessor :root_filenames
53
- attr_accessor :name
53
+ attr_accessor :pathname
54
54
  attr_accessor :metadata
55
55
  attr_accessor :metadata_filenames
56
56
  attr_accessor :status
@@ -83,8 +83,8 @@ class Chef
83
83
  #
84
84
  # === Returns
85
85
  # object<Chef::CookbookVersion>:: Duh. :)
86
- def initialize(name)
87
- @name = name
86
+ def initialize(pathname)
87
+ @pathname = pathname
88
88
  @frozen = false
89
89
  @attribute_filenames = Array.new
90
90
  @definition_filenames = Array.new
@@ -104,6 +104,10 @@ class Chef
104
104
  @metadata = Chef::Cookbook::Metadata.new
105
105
  end
106
106
 
107
+ def name
108
+ metadata.name || @pathname
109
+ end
110
+
107
111
  def version
108
112
  metadata.version
109
113
  end
@@ -598,11 +602,11 @@ class Chef
598
602
  specificity = "default"
599
603
 
600
604
  if segment == :root_files
601
- matcher = segment_file.match(".+/#{Regexp.escape(name.to_s)}/(.+)")
605
+ matcher = segment_file.match(".+/#{Regexp.escape(pathname.to_s)}/(.+)")
602
606
  file_name = matcher[1]
603
607
  path = file_name
604
608
  elsif segment == :templates || segment == :files
605
- matcher = segment_file.match("/#{Regexp.escape(name.to_s)}/(#{Regexp.escape(segment.to_s)}/(.+?)/(.+))")
609
+ matcher = segment_file.match("/#{Regexp.escape(pathname.to_s)}/(#{Regexp.escape(segment.to_s)}/(.+?)/(.+))")
606
610
  unless matcher
607
611
  Chef::Log.debug("Skipping file #{segment_file}, as it isn't in any of the proper directories (platform-version, platform or default)")
608
612
  Chef::Log.debug("You probably need to move #{segment_file} into the 'default' sub-directory")
@@ -612,7 +616,7 @@ class Chef
612
616
  specificity = matcher[2]
613
617
  file_name = matcher[3]
614
618
  else
615
- matcher = segment_file.match("/#{Regexp.escape(name.to_s)}/(#{Regexp.escape(segment.to_s)}/(.+))")
619
+ matcher = segment_file.match("/#{Regexp.escape(pathname.to_s)}/(#{Regexp.escape(segment.to_s)}/(.+))")
616
620
  path = matcher[1]
617
621
  file_name = matcher[2]
618
622
  end
@@ -33,7 +33,7 @@ class Chef
33
33
 
34
34
  def template_finder
35
35
  @template_finder ||= begin
36
- Chef::Provider::TemplateFinder.new(run_context, cookbook_name, node)
36
+ TemplateFinder.new(run_context, cookbook_name, node)
37
37
  end
38
38
  end
39
39
 
@@ -160,8 +160,6 @@ class Chef
160
160
  # the symlink that is there either loops or points to a nonexistent file
161
161
  class InvalidSymlink < RuntimeError; end
162
162
 
163
- class ChildConvergeError < RuntimeError; end
164
-
165
163
  class MissingRole < RuntimeError
166
164
  NULL = Object.new
167
165
 
@@ -31,7 +31,7 @@ class Chef
31
31
  end
32
32
 
33
33
  def section(heading, text)
34
- @sections << {heading => text}
34
+ @sections << [heading, text]
35
35
  end
36
36
 
37
37
  def display(out)
@@ -40,9 +40,7 @@ class Chef
40
40
  out.puts "=" * 80
41
41
  out.puts "\n"
42
42
  sections.each do |section|
43
- section.each do |heading, text|
44
- display_section(heading, text, out)
45
- end
43
+ display_section(section, out)
46
44
  end
47
45
  end
48
46
 
@@ -55,7 +53,8 @@ class Chef
55
53
 
56
54
  private
57
55
 
58
- def display_section(heading, text, out)
56
+ def display_section(section, out)
57
+ heading, text = section
59
58
  out.puts heading
60
59
  out.puts "-" * heading.size
61
60
  out.puts text
@@ -23,7 +23,6 @@ class Chef
23
23
  class CookbookSiteShare < Knife
24
24
 
25
25
  deps do
26
- require 'chef/cookbook_loader'
27
26
  require 'chef/cookbook_uploader'
28
27
  require 'chef/cookbook_site_streaming_uploader'
29
28
  end
@@ -25,7 +25,6 @@ class Chef
25
25
  class CookbookTest < Knife
26
26
 
27
27
  deps do
28
- require 'chef/cookbook_loader'
29
28
  require 'chef/cookbook/syntax_check'
30
29
  end
31
30
 
@@ -74,7 +74,7 @@ class Chef
74
74
  # Let children resources override constructing the @current_resource
75
75
  @current_resource ||= Chef::Resource::File.new(@new_resource.name)
76
76
  @current_resource.path(@new_resource.path)
77
- if ::File.exists?(@current_resource.path) && ::File.file?(::File.realpath(@current_resource.path))
77
+ if real_file?(@current_resource.path) && ::File.exists?(@current_resource.path)
78
78
  if @action != :create_if_missing && @current_resource.respond_to?(:checksum)
79
79
  @current_resource.checksum(checksum(@current_resource.path))
80
80
  end
@@ -292,7 +292,6 @@ class Chef
292
292
  converge_by(description) do
293
293
  unlink(@new_resource.path)
294
294
  end
295
- @current_resource.checksum = nil
296
295
  @file_unlinked = true
297
296
  end
298
297
  end
@@ -759,7 +759,7 @@ class Chef
759
759
  @rpmdb << pkg
760
760
  end
761
761
 
762
- error = status.stderr
762
+ error = status.stderr.readlines
763
763
  rescue Mixlib::ShellOut::CommandTimeout => e
764
764
  Chef::Log.error("#{helper} exceeded timeout #{Chef::Config[:yum_timeout]}")
765
765
  raise(e)
@@ -947,7 +947,6 @@ class Chef
947
947
  end # YumCache
948
948
 
949
949
  include Chef::Mixin::GetSourceFromPackage
950
- include Chef::Mixin::ShellOut
951
950
 
952
951
  def initialize(new_resource, run_context)
953
952
  super
@@ -87,12 +87,11 @@ class Chef
87
87
  end
88
88
 
89
89
  def load
90
- if previous_cc_data = load_data
91
- apply(previous_cc_data)
92
- self
93
- else
94
- false
95
- end
90
+ previous_cc_data = load_data
91
+ apply(previous_cc_data)
92
+ self
93
+ rescue Chef::Exceptions::FileNotFound
94
+ false
96
95
  end
97
96
 
98
97
  def validate!(current_copy_checksum)
@@ -140,8 +139,6 @@ class Chef
140
139
 
141
140
  def load_data
142
141
  Chef::JSONCompat.from_json(load_json_data)
143
- rescue Chef::Exceptions::FileNotFound, Yajl::ParseError
144
- false
145
142
  end
146
143
 
147
144
  def load_json_data
@@ -149,10 +146,7 @@ class Chef
149
146
  end
150
147
 
151
148
  def sanitized_cache_file_basename
152
- # Scrub and truncate in accordance with the goals of keeping the name
153
- # human-readable but within the bounds of local file system
154
- # path length limits
155
- scrubbed_uri = uri.gsub(/\W/, '_')[0..63]
149
+ scrubbed_uri = uri.gsub(/\W/, '_')
156
150
  uri_md5 = Chef::Digester.instance.generate_md5_checksum(StringIO.new(uri))
157
151
  "#{scrubbed_uri}-#{uri_md5}.json"
158
152
  end
@@ -36,8 +36,6 @@ class Chef
36
36
  state_attrs :checksum, :owner, :group, :mode
37
37
  end
38
38
 
39
- attr_writer :checksum
40
-
41
39
  provides :file, :on_platforms => :all
42
40
 
43
41
  def initialize(name, run_context=nil)
@@ -64,11 +64,8 @@ class Chef
64
64
  else
65
65
  #as_hash["result"] = "failed"
66
66
  end
67
- if new_resource.cookbook_name
68
- as_hash["cookbook_name"] = new_resource.cookbook_name
69
- as_hash["cookbook_version"] = new_resource.cookbook_version.version
70
- end
71
-
67
+ as_hash["cookbook_name"] = new_resource.cookbook_name
68
+ as_hash["cookbook_version"] = new_resource.cookbook_version.version
72
69
  as_hash
73
70
  end
74
71
 
@@ -127,12 +127,7 @@ class Chef
127
127
  end
128
128
 
129
129
  def stat
130
- @stat ||= if @new_resource.instance_of?(Chef::Resource::Link)
131
- ::File.lstat(@new_resource.path)
132
- else
133
- realpath = ::File.realpath(@new_resource.path)
134
- ::File.stat(realpath)
135
- end
130
+ @stat ||= @new_resource.instance_of?(Chef::Resource::Link) ? ::File.lstat(@new_resource.path) : ::File.stat(@new_resource.path)
136
131
  end
137
132
  end
138
133
  end
@@ -22,10 +22,6 @@ class Chef
22
22
  class Diff
23
23
  include Chef::Mixin::ShellOut
24
24
 
25
- # @todo: to_a, to_s, to_json, inspect defs, accessors for @diff and @error
26
- # @todo: move coercion to UTF-8 into to_json
27
- # @todo: replace shellout to diff -u with diff-lcs gem
28
-
29
25
  def for_output
30
26
  # formatted output to a terminal uses arrays of strings and returns error strings
31
27
  @diff.nil? ? [ @error ] : @diff
@@ -79,13 +75,8 @@ class Chef
79
75
 
80
76
  begin
81
77
  # -u: Unified diff format
82
- # LC_ALL: in ruby 1.9 we want to set nil which is a magic option to mixlib-shellout to
83
- # pass through the LC_ALL locale. in ruby 1.8 we force to 7-bit 'C' locale
84
- # (which is the mixlib-shellout default for all rubies all the time).
85
78
  Chef::Log.debug("running: diff -u #{old_file} #{new_file}")
86
- locale = ( Object.const_defined? :Encoding ) ? nil : 'C'
87
- result = shell_out("diff -u #{old_file} #{new_file}", :env => {'LC_ALL' => locale})
88
-
79
+ result = shell_out("diff -u #{old_file} #{new_file}")
89
80
  rescue Exception => e
90
81
  # Should *not* receive this, but in some circumstances it seems that
91
82
  # an exception can be thrown even using shell_out instead of shell_out!
@@ -103,18 +94,7 @@ class Chef
103
94
  if result.stdout.length > diff_output_threshold
104
95
  return "(long diff of over #{diff_output_threshold} characters, diff output suppressed)"
105
96
  else
106
- diff_str = result.stdout
107
- if Object.const_defined? :Encoding # ruby >= 1.9
108
- if ( diff_str.encoding == Encoding::ASCII_8BIT &&
109
- diff_str.encoding != Encoding.default_external &&
110
- RUBY_VERSION.to_f < 2.0 )
111
- # @todo mixlib-shellout under ruby 1.9 hands back an ASCII-8BIT encoded string, which needs to
112
- # be fixed to the default external encoding -- this should be moved into mixlib-shellout
113
- diff_str = diff_str.force_encoding(Encoding.default_external)
114
- end
115
- diff_str.encode!('UTF-8', :invalid => :replace, :undef => :replace, :replace => '?')
116
- end
117
- @diff = diff_str.split("\n")
97
+ @diff = result.stdout.split("\n")
118
98
  @diff.delete("\")
119
99
  return "(diff available)"
120
100
  end
@@ -126,16 +106,10 @@ class Chef
126
106
  end
127
107
 
128
108
  def is_binary?(path)
129
- File.open(path) do |file|
130
- # XXX: this slurps into RAM, but we should have already checked our diff has a reasonable size
131
- buff = file.read
109
+ ::File.open(path) do |file|
110
+ buff = file.read(Chef::Config[:diff_filesize_threshold])
132
111
  buff = "" if buff.nil?
133
- begin
134
- return buff !~ /\A[\s[:print:]]*\z/m
135
- rescue ArgumentError => e
136
- return true if e.message =~ /invalid byte sequence/
137
- raise
138
- end
112
+ return buff !~ /^[\r[:print:]]*$/
139
113
  end
140
114
  end
141
115