- 1 Using Diff
- 1.1 Using Diff to Determine changes when you have two files
- 1.2 Using Diff to Patch An Existing File
- 1.3 Apply a Patch
- 1.4 Check for Differences after the Patch
- 1.5 If Differences Exist
- 1.6 References
Using Diff to Determine changes when you have two files
Let's say you need to know the differences between a new patch file and your existing file.
Here is the command:
diff - firstfile secondfile > differencesfile
- Here is a real in-use Example:
- We check out the stylesheets of the docviewer with a file in my home folder and we save the differences.
diff -u /usr/palm/applications/com.palm.app.docviewer/stylesheets /usr/home/mine/newstylesheet > /usr/home/mine/differences.txt
Using Diff to Patch An Existing File
Let's say you have downloaded a patch file for your Pre and you want to apply them. Here is the procedure
- Make a backup of the file to your own folder on the pre
- Take the file you need to apply (the patch) and place it onto the pre (more detail needed here)---- I'll add later
- Now you can change the production copy
Apply a Patch
Patch takes a patch file patchfile containing a difference listing produced by the diff program and applies those differences to one or more original files, producing patched versions. The patched versions are put in place of the originals. Patch tries to skip any leading garbage, apply the diff, and then skips any trailing garbage. So you could feed an article or message containing a diff listing to patch, and it should work.
A destination file is the file you will be overwriting/ patching into. The patch is the file that contains the changes and is in your /usr/home folder.
To apply a patch to a single file,
- Make the file system read-write instead of read-only, then
- Use WinSCP to transfer the patch to your Pre, put it in the /usr/home or some similar folder (I use /usr/home/FreeTim/somepatch )
- Change to the directory where the DESTINATION system file is located using cd command
- Make a backup copy of the file somewhere safe (I copy it to my home directory) using cp command then finally,
- call patch command:
The command is
patch --strip=1 --remove-empty-files < /usr/home/somepatchfile.pl || echo "failures!"
The options I'm using are:
This fixes file path slashes. Just use it.
This removes output files that are empty after the patches have been applied. Normally not needed for patch can examine the time stamps on the header to determine whether a file should exist after patching. If the input is not a context diff or if patch is conforming to POSIX, patch does not remove empty patched files unless this option is given.
In the above example, change the /usr/home/somepatchfile.pl to the folder of the file you have on the Pre you want to apply as a patch.
If this works (nothing is returned) then you can check for differences after the patch, if you like. But if nothing is returned, then it worked.
To apply a patch to a single file, change to the directory where the file is located and call patch:
cd /usr/var/palm/something patch --strip=1 --remove-empty-files < /usr/home/somepatchfile.pl || echo "failures!"
- No response indicates success
- You can optionally compare to determine success
Check for Differences after the Patch
Let's say you want to just make sure the patch took effect.
Here is an example command.
diff --unified --recursive --new-file newfile existingfile
- If there is no diff between "newfile" and "existingfile", you'll just be put back at your command prompt, showing that there are no differences - success!
- Otherwise differences will be displayed.
If Differences Exist
Your choices here are
- Use 'vi' and other commands to fix the files or
- Just copy your (previously saved) original back into place.
This Wiki page
This document is a rough initial draft-- FreeTim3
- 10-Minute Guide to Patch (external link) http://stephenjungels.com/jungels.net/articles/diff-patch-ten-minutes.html