class Drupid::Patch

Attributes

cached_location[R]
descr[R]
md5[R]
url[R]

Public Class Methods

new(url, descr, md5 = nil) click to toggle source
   # File lib/drupid/patch.rb
31 def initialize url, descr, md5 = nil
32   @url = url
33   @descr = descr
34   @md5 = md5
35   @cached_location = nil
36 end

Public Instance Methods

apply() click to toggle source

Applies this patch in the current directory. Raises an error if the patch cannot be applied.

   # File lib/drupid/patch.rb
54 def apply
55   debug "Applying patch at #{Dir.pwd}"
56   raise "Patch not fetched." if !(@cached_location and @cached_location.exist?)
57   patch_levels = ['-p1', '-p0']
58   patched = false
59   output = ''
60   # First try with git apply
61   patch_levels.each do |pl|
62     begin
63       runBabyRun 'git', ['apply', '--check', pl, @cached_location], :redirect_stderr_to_stdout => true
64       runBabyRun 'git', ['apply', pl, @cached_location], :redirect_stderr_to_stdout => true
65       patched = true
66       break
67     rescue => ex
68       output << ex.to_s
69     end
70   end
71   if not patched
72     patch_levels.each do |pl|
73       begin
74         runBabyRun 'patch', ['--no-backup-if-mismatch', '-f', pl, '-d', Dir.pwd, '-i', @cached_location], :redirect_stderr_to_stdout => true
75         patched = true
76         break
77       rescue => ex
78         output << ex.to_s
79       end
80     end
81   end
82   if not patched
83     if descr and descr != @cached_location.basename.to_s
84       d = " (#{descr})"
85     else
86       d = ''
87     end
88     raise "Patch #{@cached_location.basename}#{d} could not be applied.\n" + output
89   end
90   return true
91 end
fetch() click to toggle source

Downloads the patch into the current directory.

   # File lib/drupid/patch.rb
39 def fetch
40   dst = Pathname.pwd+File.basename(@url.to_s)
41   blah "Fetching patch..."
42   begin
43     curl @url.to_s, '-o', dst
44   rescue => ex
45     raise "Patch #{File.basename(@url.to_s)} could not be fetched."
46     debug ex.message
47   end
48   @cached_location = dst
49   debug "Patch downloaded into #{@cached_location}"
50 end