Buy One Domain Name, Get One Free

Looking for a reliable and affordable Domain Name Registrar? Look no further than Dotster. And for a limited time, we're able to offer our visitors a buy one domain name, get one free promotion. Click here to take advantage of this offer.

Constant Contact E-Newsletter Service - get 60 days free!

Constant Contact has been in business since 1996 is one of the most reliable and trusted email marketing services around. Click here to activate your free 60 day trial courtesy of CWD Community.



Sep 22 2006

Patching Drupal Modules in Windows


Filed under: Content Management Systems » Drupal,
Tools:


How to Patch Drupal Modules in Windows

So you've got everything working except for one nagging little bug that's keeping your site from rocking the world. This is normally where patches come in. There are two kinds of patches - those that eventually get rolled into the production version of a module, and those that are temporary hacks to fix a longer term issue. I would recommend only using those you feel will eventually be rolled into the code, and if possible, avoid patches entirely for compatibility reasons. Too often a patch will fix a temporary issue that will later be solved in a different way and render your "patched" database structure obsolete. That being said, here's how to patch a Drupal module in Windows:

Download Cygwin

Cygwin is a Linux-like environment that runs in Windows. The dll (cygwin1.dll) acts as a Linux API emulation layer giving you basic Linux API functionality. The complete download comes with a collection of tools that provide a Linux command prompt look and feel. As a first step, you'll need to download and install the latest version of Cygwin:

» Cygwin.com

You can install the default packages, but make sure you include the "patchutils" package under the "Devel" section.

Common Cygwin Commands:

Here's a list of the commands you'll need to access the patch directory:

  • ls -al -- lists the contents of your current directory
  • cd .. -- moves you up to the parent directory (note the space between cd and .. if you come from a DOS background!)
  • cd foldername -- moves you to a specific folder visible from your current directory

Steps to Patch a Drupal Module in Cygwin

Here are the basic steps you'll need to follow to patch your module:

  • Copy the patch file and original module to the same directory, one you can access via the Cygwin commands above.
  • Run this command: patch filetobepatched < patchfile or patch -p0 < patchfile

Voila Smiling Post any questions or comments below.

Windows Vista

If you're using Windows Visa, run Cygwin as an administrator. You'll also need to uncheck the "read only" flag on files you modify, and adjust permissions (under the security tab) to allow full access for your user. Otherwise, you'll have trouble copying and uploading files - you'll get "permission denied" errors.

Average: 5 (4 votes)
Tools:



Failed to work for me

Hi, it didn't work for me and gave me a hideous error saying "3 out of 4 hunks failed, saving rejects to file". Any clue about it?

Version specific patches

Drupal patches are very version-specific. Make sure you're applying the patch to the module that matches the version # of the patch. If you're still seeing errors, try the patched module anyways - sometimes errors are thrown and the module still works.

Can't copy patch files in Vista?

Thanks for the Cygwin/ Drupal tutorial. I've got this installed on Windows Vista, with UAC turned on, and I was able to patch a file successfully. However, I can't copy it over to my Drupal directory, even if I use the bash "cp" command from within the bash shell. Any ideas?

Windows Vista security

Great question - run Cygwin as administrator and then update permissions on your patch file to allow full access to your user, and uncheck the "read only" box. I've updated our article to reflect this new information.

Patching Drupal modules

Excellent resource for us Windows users - thank you! I've been having to wait for patches to be rolled in to official releases. Not anymore - now I can apply updates right away. Thanks!!

Setting file permissions using Cygwin

Thank you for the link to cygwin. One question, though, how are file permissions set using Cygwin?

Thank you.

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <br> <br />
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.

More information about formatting options

CAPTCHA
This question is used to make sure you are a human visitor and to prevent spam submissions.