class Gem::Patcher

Public Class Methods

new(gemfile, output_dir) click to toggle source
# File lib/rubygems/patcher.rb, line 14
def initialize(gemfile, output_dir)
  @gemfile    = gemfile
  @output_dir = output_dir

  # @target_dir is a temporary directory where the gem files live
  tmpdir      = Dir.mktmpdir
  basename    = File.basename(gemfile, '.gem')
  @target_dir = File.join(tmpdir, basename)
end

Public Instance Methods

apply_patch(patch, strip_number) click to toggle source
# File lib/rubygems/patcher.rb, line 48
def apply_patch(patch, strip_number)
  patch_path = File.expand_path(patch)
  info 'Path to the patch to apply: ' + patch_path

  # Apply the patch by calling 'patch -pNUMBER < patch'
  Dir.chdir @target_dir do
    IO.popen("patch --verbose -p#{strip_number} < #{patch_path} 2>&1") do |out|
      std = out.readlines
      out.close
      info std

      unless $?.nil?
        if $?.exitstatus == 0
          @output << "Succesfully patched with #{patch}"
        else
          @output << "Error: Unable to patch with #{patch}."

          unless Gem.configuration.really_verbose
            @output << "Run gem patch with --verbose option to swich to verbose mode."
          end
        end
      end
    end
  end
end
patch_with(patches, strip_number) click to toggle source

Patch the gem, move the new patched gem to the working directory and return the path

# File lib/rubygems/patcher.rb, line 27
def patch_with(patches, strip_number)
  @output = []

  check_patch_command_is_installed
  extract_gem

  # Apply all patches
  patches.each do |patch|
    info 'Applying patch ' + patch
    apply_patch(patch, strip_number)
  end

  build_patched_gem

  new_gem_path = File.join(@output_dir, @package.spec.file_name)
  FileUtils.mv((File.join @target_dir, @package.spec.file_name), new_gem_path)

  # Return the path to the patched gem
  new_gem_path
end
print_results() click to toggle source