Patches
Introduction
This page describes how to create and apply diff patches in universal format. Check the Links section for more extensive tutorials. Feel free to extend the information.
Patching
What's patching? As Wikipedia says: "A patch is a small piece of software designed to update or fix problems with a computer program or its supporting data. This includes fixing bugs, replacing graphics and improving the usability or performance." Patching is the process of applying those patches. We use them to update applications (mainly Moodle) with customizations easily, automatizing the process instead of having to add the code manually, saving lot of time and problems. But they can also be used on other scenarios, like updating "production" applications or solving issues with applications deployed from a binary installer.
Create a Patch
To create a patch you need to have the original file and the modified one, and place them in the same relatives path they will be when applied. As a example if you want to make a patch of "alfresco/tomcat/conf/server.xml" you will create:
old/tomcat/conf/server.xml #original file new/tomcat/conf/server.xml #modified file
Be careful as both files must have the same number of "/" in its path, so it's safer to create those "old" and "new" folders than use "real" paths. If you do otherwise, you can have problems when applying the patches. Then you can run:
diff -Naur old/tomcat/conf/server.xml new/tomcat/conf/server.xml >name.patch
this command will create a uniffied patch name "name.patch".
Apply a patch
To apply a patch created in the above section patch after installing the target program you must go to the root folder of the application and then run:
cat name.patch | patch -p1 --dry-run #to test the patch cat name.patch | patch -p1 #to apply the patch
this will read the patch file, use the relative paths embedded on them (in the example: tomcat/conf) and apply the patch. You should always test the patch first to detect possible errors, to be on the safe side.