Community Documentation

Common problems

Last updated April 22, 2010. Created by Heine on April 24, 2006.
Edited by add1sun, ax. Log in to edit this page.

UNIX vs. Windows end-of-line encoding

Text files originating from UNIX systems use a single linefeed character (LF) to mark the end of a line, whereas Windows systems use a carriage return followed by a linefeed (CRLF).

The GnuWin32 patch program may crash on a patchfile with Unix end-of-line encoding throwing the error "Assertion failed: hunk, file [path]/patch.c, line 339".

Most patches downloaded from drupal.org are UNIX text files. When you use patch on Windows, you need to convert line-endings using a unix2dos utility or a decent text-editor.

One way to do this is to open the file with WORDPAD, choose "Save as" and select as type Text document.

Patch can't find the target file

This usually means that you are either executing patch in the wrong directory or that the patch was made relative to another directory. Open the patchfile and locate the lines describing the changed files to determine the path:

--- modules/codefilter/codefilter.module Tue Mar 28 15:04:48 2006
+++ modules/codefilter/codefilter.module Sun Apr 23 15:51:32 2006

The above patch appears to be made relative to the drupal root directory so you can execute the following command from the Drupal root:

patch -p0 < file.patch

The number after -p determines the number of path elements that should be ignored. This is very useful when you need to apply a patch that was made against an old and new directory:

--- olddir/modules/codefilter/codefilter.module Tue Mar 28 15:04:48 2006
+++ newdir/modules/codefilter/codefilter.module Sun Apr 23 15:51:32 2006

You can apply this patch from the Drupal root by stripping the first path element; 'olddir' / 'newdir':

patch -p1 < file.patch

patch unexpectedly ends in middle of line
Applying some patches generates the error:

patch unexpectedly ends in middle of line

This error seems to occur when the patch file ends on a line that includes nothing but whitespace characters. Patch files should always end with a Unix return character. If you encounter this error, check to see that the last line of your patch does not contain whitespace characters.

References: http://drupal.org/node/122734 and http://drupal.org/node/118660

Comments

As a fast solution you can

As a fast solution you can use following command for applying the patch (end line safe)

patch {file} {patch} --verbose --binary

Note that by using --binary patch.exe will no longer affected by line ending characters issue

sina.salek.ws
Feel freedom with open source softwares

sina.salek.ws, Software Manager & Lead developer
Feel freedom with open source softwares

Patch files sometime patch multiple files

If you get a "Patch can't find the target file", but the first hunk seems to have worked, then your patch file might require a second file. The patch will give you a little prompt like "file to patch>".

Look at the output just above the prompt and enter the location of the file that caused patch to choke.

Patch does not preserve selinux context

It is the bug in Red Hat Enterprise Linux:

"Bug 229329 - patch does not preserve context - resets to tmp_t" https://bugzilla.redhat.com/show_bug.cgi?id=229329
So, after applying the patch webserver can't read patched file and receives "Permission Denied" error.

Bug is still in development, but workaround found by me (for particular case only):

#/sbin/restorecon -v [filename]

Archive

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.