## Aggiornare i pacchetti

If you have been around Linux distributions for any amount of time, you have realized that there are sometimes bugs in programs. In the Debian and Ubuntu distributions, bugs are often fixed through the packaging by patching the source code. Sometimes there are bugs in the packaging itself that can cause difficulties.

To patch the program's source code, you could simply download the current Ubuntu source package (with apt-get source) and make the needed changes. You can then add a new entry to the `debian/changelog` using dch -i or dch -v <version>-<revision> to specify the new revision. When you run debuild -S from the source directory you will have a new source package with a new `.diff.gz` in the parent directory that contains your changes. A problem with this approach is that the distinction between source and patches is unclear.

A solution to this problem is to separate the changes to the source code into individual patches stored in the `debian` directory. One such patch system is called dpatch. The patches are stored in the `debian/patches/` directory and have a special format.

To create a dpatch, perform the following steps sequentially.

Create a temporary work space and two copies of the current source directory:

    mkdir tmp
    cd tmp
    cp -a ../<package>-<version> .
    cp -a <package>-<version> <package>-<version>.orig

Make the changes in the `<package>-<version>` directory.

Create a patch file using diff and place it in the `debian/patches` directory:

    diff -Nru  <package>-<version>.orig <package>-<version> > patch-file

Create the dpatch using dpatch patch-template and a file named `00list` that lists the dpatches:

    dpatch patch-template -p "01_patchname" "patch-file description" \
    	< patch-file > 01_patchname.dpatch
    echo 01_patchname.dpatch >00list

You can now place `01_patchname.dpatch` and `00list` in the `debian/patches` directory of your source package:

    mkdir ../<package>-<version>/debian/patches
    cp 01_patchname.dpatch 00list ../<package>-<version>/debian/patches
    cd ..
    rm -rf tmp

You can also edit a pre-existing patch using dpatch-edit-patch.

Once all the changes have been made, a changelog entry added, and dpatch added to the `debian/control` file (if needed), then you can rebuild the source package with debuild -S.

To get your fixed source package uploaded to the Ubuntu repositories, you will need to get your source package sponsored by a person who has upload rights. See la sezione chiamata “Caricamento e revisione” for more details. Sometimes, rather than giving the entire source package (.diff.gz, .dsc, and .orig.tar.gz), it is easier and more efficient to just give the difference between the source package that is currently in the repositories and your fixed source package. A tool has been created to do just that called debdiff. Using debdiff is similar to using diff but is made specifically for packaging. You can debdiff the source package by:

    debdiff <oldpackage>.dsc <newpackage>.dsc > package.debdiff

or the binary package by:

    debdiff <oldpackage>.deb <newpackage>.deb > package.debdiff

Debdiffs are great to attach to bug reports and have ready for a sponsor to upload.

Packaging With CDBS |  | Common Mistakes