diff options
Diffstat (limited to 'chef/lib/chef.rb')
-rw-r--r-- | chef/lib/chef.rb | 76 |
1 files changed, 3 insertions, 73 deletions
diff --git a/chef/lib/chef.rb b/chef/lib/chef.rb index f38947b380..8e477693a3 100644 --- a/chef/lib/chef.rb +++ b/chef/lib/chef.rb @@ -34,76 +34,6 @@ require 'chef/run_status' require 'chef/handler' require 'chef/handler/json_file' -# Adds a Dir.glob to Ruby 1.8.5, for compat -if RUBY_VERSION < "1.8.6" || RUBY_PLATFORM =~ /mswin|mingw32|windows/ - class Dir - class << self - alias_method :glob_, :glob - def glob(pattern, flags=0) - raise ArgumentError unless ( - !pattern.nil? and ( - pattern.is_a? Array and !pattern.empty? - ) or pattern.is_a? String - ) - pattern.gsub!(/\\/, "/") if RUBY_PLATFORM =~ /mswin|mingw32|windows/ - [pattern].flatten.inject([]) { |r, p| r + glob_(p, flags) } - end - alias_method :[], :glob - end - end -end - - -# On ruby 1.9, Strings are aware of multibyte characters, so #size and length -# give the actual number of characters. In Chef::REST, we need the bytesize -# so we can correctly set the Content-Length headers, but ruby 1.8.6 and lower -# don't define String#bytesize. Monkey patching time! -class String - unless method_defined?(:bytesize) - alias :bytesize :size - end -end - - -# Tempfile has a horrible bug where it causes an IOError: closed stream in its -# finalizer, leading to intermittent application crashes with confusing stack -# traces. Here we monkey patch the fix into place. You can track the bug on -# ruby's redmine: http://redmine.ruby-lang.org/issues/show/3119 -class Tempfile - # Tempfile has changes between 1.8.x and 1.9.x - # so we monkey patch separately - if RUBY_VERSION =~ /^1\.8/ - def unlink - # keep this order for thread safeness - begin - File.unlink(@tmpname) if File.exist?(@tmpname) - @@cleanlist.delete(@tmpname) - @tmpname = nil - ObjectSpace.undefine_finalizer(self) - rescue Errno::EACCES - # may not be able to unlink on Windows; just ignore - end - end - alias delete unlink - - - # There is a patch for this, to be merged into 1.9 at some point. - # When that happens, we'll want to also check the RUBY_PATCHLEVEL - elsif RUBY_VERSION =~ /^1\.9/ - def unlink - # keep this order for thread safeness - return unless @tmpname - begin - if File.exist?(@tmpname) - File.unlink(@tmpname) - end - # remove tmpname from remover - @data[0] = @data[2] = nil - @tmpname = nil - rescue Errno::EACCES - # may not be able to unlink on Windows; just ignore - end - end - alias delete unlink - end -end +require 'chef/monkey_patches/tempfile' +require 'chef/monkey_patches/dir' +require 'chef/monkey_patches/string' |