Diff

From WebOS Internals

Revision as of 21:44, 20 July 2009 by FreeTim (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Using Diff

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

  1. Make a backup of the file to your own folder on the pre
  2. Take the file you need to apply (the patch) and place it onto the pre (more detail needed here)---- I'll add later
  3. 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,

  1. Make the file system read-write instead of read-only, then
  2. 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 )
  3. Change to the directory where the DESTINATION system file is located using cd command
  4. Make a backup copy of the file somewhere safe (I copy it to my home directory) using cp command then finally,
  5. call patch command:


The command is

patch --strip=1 --remove-empty-files < /usr/home/somepatchfile.pl || echo "failures!"

The options I'm using are:

 --strip=1   

This fixes file path slashes. Just use it.

 --remove-empty-files      

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 conform­ing 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


References

.

Personal tools
Google AdSense