Page 1 of 1

patch command

Posted: Fri May 29, 2009 12:52 pm
by mciv
I've got a patch problem I can't figure out. I've created a diff file that works from the command line.

Code: Select all

patch -i my.diff config.inc.php
But when I include the patch command inside a script it fails in three places. My guess is some weird spacing issue but I'm stumped as to how to correct it. This is the patch part of the script.

Code: Select all

--- config.inc.php 2009-05-29 01:01:39.000000000 -0400 +++ config.inc.php.new 2009-05-29 10:30:31.000000000 -0400 @@ -26,7 +26,7 @@ * * @var global constant */ - define("DB_USERNAME", "root"); + define("DB_USERNAME", "badgerbank"); /** * Database password @@ -34,7 +34,7 @@ * @var global constant */ - define("DB_PASSWORD", ""); + define("DB_PASSWORD", "badgerbank"); /** * Database host address @@ -69,4 +69,4 @@ // Report ALL Errors error_reporting(E_ALL); -?> +?>

Re: patch command

Posted: Fri May 29, 2009 1:28 pm
by gmw
How exactly do you include it in the script?
I have had issues with quotes sometimes

eg. whether to use:

patch -p0 -f -E << 'EOF'
<patch content>
EOF

OR

patch -p0 -f -E << EOF
<patch content>
EOF

I am not aware of all the subtleties myself :roll:

Re: patch command

Posted: Fri May 29, 2009 1:33 pm
by mciv
I've tried it multiple ways. With quotes. Without quotes.

Re: patch command

Posted: Fri May 29, 2009 1:37 pm
by gmw
Have you checked silly things (like being in the right directory, or that the file has the right permissions).

Note: one-click install scripts run as apache user

Re: patch command

Posted: Fri May 29, 2009 1:43 pm
by mciv
At this point I'm just running a local script and all the other commands such as wget and tar work correctly. Patch appears to find the file so I think the directory is ok. It just fails at each of three hunks.

Re: patch command

Posted: Sun Jun 21, 2009 8:59 pm
by cpg
did you make any progress on this?

this part (when hunks fail), is particularly difficult. wish we could make it easier ...

a patch is really the output of

Code: Select all

diff -u
fed to the patch program, like this:

Code: Select all

patch -p0 -l <<'EOF' ... output of diff -u ... EOF
one tricky thing is that if the 'EOF' is not put with quotes around it (i.e. just EOF), then there will be extension of $variables inside the patch code.

in many cases of patching php and similar languages, that can create havoc.

Re: patch command

Posted: Sun Jun 21, 2009 9:13 pm
by gmw
The issue in this case ended up being some invisible characters (linefeeds and tabs in particular).

That said, the application itself is very buggy.