[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

dpkg-divert problem analysis and proposals for a solution



Hi,

[Please CC the replies to me. Thanks.]

Here's my analysis of the dpkg-divert problem (bugs #237509 and
#241339/#241463).

In summary, I believe that dpkg-divert does nothing wrong. However,
additional documentation of handling diversions on upgrades
(particularly, their removal) seems to be necessary. For those too lazy to
read through the whole message, possible solutions are given in the end.

Experiments in the unstable chroot. The /etc/apt/sources.list file:

deb ftp://ftp3.nrc.ca/debian sid main contrib non-free
deb ftp://ftp3.nrc.ca/debian testing main contrib non-free
deb http://snapshot.debian.net/archive pool desktop-base
deb-src http://snapshot.debian.net/archive pool desktop-base

The problem manifests itself when the file is first diverted, then attempt
is made to remove a diversion during upgrade. It can be illustrated in
desktop-base case by first creating a file
/usr/share/pixmaps/splash/gnome-splash.png (which can come from a
gnome-session, for example):

root@bobcat:/# mkdir /usr/share/pixmaps/splash
root@bobcat:/# touch /usr/share/pixmaps/splash/gnome-splash.png

Then install the older version of desktop-base:

root@bobcat:/# apt-get install desktop-base=0.3.10
Reading Package Lists... Done
Building Dependency Tree... Done
Suggested packages:
  gnome kde wmaker
Recommended packages:
  www-browser
The following NEW packages will be installed:
  desktop-base
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0B/543kB of archives.
After unpacking 688kB of additional disk space will be used.
Selecting previously deselected package desktop-base.
(Reading database ... 10695 files and directories currently installed.)
Unpacking desktop-base (from .../desktop-base_0.3.10_all.deb) ...
Adding `diversion of /usr/share/pixmaps/splash/gnome-splash.png to /usr/share/pixmaps/splash/gnome-splash.png.orig by desktop-base'
Setting up desktop-base (0.3.10) ...

The diversion of the file has been added:

root@bobcat:/# dpkg-divert --list
diversion of /usr/share/pixmaps/splash/gnome-splash.png to /usr/share/pixmaps/splash/gnome-splash.png.orig by desktop-base
root@bobcat:/#

The modifications are seen in the directory as well:

root@bobcat:/# ls -al /usr/share/pixmaps/splash/
total 8
drwxr-xr-x    2 root     root         4096 Apr  5 03:10 .
drwxr-xr-x    3 root     root         4096 Apr  5 03:10 ..
lrwxrwxrwx    1 root     root           30 Apr  5 03:10 gnome-splash.png -> /etc/alternatives/gnome-splash
-rw-r--r--    1 root     root            0 Apr  5 03:10 gnome-splash.png.orig
root@bobcat:/#

Now we go ahead and upgrade desktop-base to 0.3.11:

root@bobcat:/# apt-get install desktop-base=0.3.11
Reading Package Lists... Done
Building Dependency Tree... Done
Suggested packages:
  gnome kde wmaker
Recommended packages:
  www-browser
The following packages will be upgraded:
  desktop-base
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0B/543kB of archives.
After unpacking 45.1kB disk space will be freed.
(Reading database ... 10721 files and directories currently installed.)
Preparing to replace desktop-base 0.3.10 (using .../desktop-base_0.3.11_all.deb) ...
Removing `diversion of /usr/share/pixmaps/splash/gnome-splash.png to /usr/share/pixmaps/splash/gnome-splash.png.orig by desktop-base'
dpkg-divert: rename involves overwriting `/usr/share/pixmaps/splash/gnome-splash.png' with
  different file `/usr/share/pixmaps/splash/gnome-splash.png.orig', not allowed
dpkg: error processing /var/cache/apt/archives/desktop-base_0.3.11_all.deb (--unpack):
 subprocess pre-installation script returned error exit status 2
Errors were encountered while processing:
 /var/cache/apt/archives/desktop-base_0.3.11_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

Obviously, the upgrade was not handled very well. The preinst of the
dekstop-base 0.3.11 reads:

if [ "${1}" = "upgrade" ]; then
    if dpkg --compare-versions ${2} lt 0.3.11 && dpkg --compare-versions ${2} gt
 0.3.5; then
        dpkg-divert --rename \
            --remove /usr/share/pixmaps/splash/gnome-splash.png

        update-alternatives --remove gnome-splash \
            /usr/share/images/desktop-base/Splash-Debian.png
        update-alternatives --remove gnome-splash \
            /usr/share/images/desktop-base/Splash-EvolvingTux.png
        update-alternatives --remove gnome-splash \
            /usr/share/images/desktop-base/Splash-Debian_red.png
    fi
fi

The problem is, that both files gnome-splash.png.orig and gnome-splash.png
are present in the /usr/share/pixmaps/splash. dpkg-divert is instructed to
basically move the original (.orig) file in place of the diverted one and
refuses to do it (I do not think it is a bug). It is more of a documentation
problem. I see two possible ways around the problem:

1. Before removing a diversion, remove the file (in this case
/usr/share/pixmaps/splash/gnome-splash.png), if it is still exists. Then
diversion removal will go smoothly. This is essentially equivalent to letting
dpkg-divert to overwrite files when removing diversions, which does not seem
as such a good idea (even though I cannot immediately come up with good
arguments, why).

2. Document the necessity of properly handling diversions on upgrades. So far
policy contains only a mention, that the diversions should be created in
preinst and removed in postrm. The problem is that the postrm is not run on
upgrades. The cleanest way out of this problem (IMO) is to advise maintainers
to remove all the diversions, created by the package in prerm, if it is called
with "upgrade" option, and recreate them in new preinst, if necessary. Removal
of the diversion in this case is accomplished by just not recreating it in the
preinst of the new version.

Best regards,

Jurij Smakov                                        jurij@wooyd.org
Key: http://www.wooyd.org/pgpkey/                   KeyID: C99E03CC



Reply to: