This chapter describes the internals of dpkg itself. Although the low-level
formats are quite simple, what dpkg does in certain cases often does not make
sense.
This describes the /var/lib/dpkg/updates directory. The function of this
directory is somewhat strange, and seems only to be used internally. A
function called cleanupdates is called whenever the database is scanned. This
function in turn uses scandir(3), to sort the files in this
directory. Files who names do not consist entirely of digits are discarded.
dpkg also causes a fatal error if any of the filenames are different lengths.
After having scanned the directory, dpkg in turn parses each file the same way
it parses the status file (they are sorted by the scandir to be in numerical
order). After having done this, it then writes the status information back to
the "status" file, and removes all the "updates" files.
These files are created internally by dpkg's "checkpoint" function,
and are cleaned up when dpkg exits cleanly.
Juding by the use of the updates directory I would call it a Journal. Inorder
to effeciently ensure the complete integrity of the status file dpkg will
"checkpoint" or journal all of it's activities in the updates
directory. By merging the contents of the updates directory (in order!!)
against the original status file it can get the precise current state of the
system, even in the event of a system failure while dpkg is running.
The other option would be to sync-rewrite the status file after each operation,
which would kill performance.
It is very important that any program that uses the status file abort if the
updates directory is not empty! The user should be informed to run dpkg
manually (what options though??) to correct the situation.
First, the status file is read. This gives dpkg an initial idea of the
packages that are there. Next, the updates files are read in, overriding the
status file, and if necessary, the status file is re-written, and updates files
are removed. Finally, the available file is read. The available file is read
with flags which preclude dpkg from updating any status information from it,
though - installed version, etc., and is also told to record that the packages
it reads this time are available, not installed.
Version numbers consist of three parts: the epoch, the upstream version, and
the Debian revision. Dpkg compares these parts in that order. If the epochs
are different, it returns immediately, and so on.
However, the important part is how it compares the versions which are
essentially stored as just strings. These are compared in two distinct parts:
those consisting of numerical characters (which are evaluated, and then
compared), and those consisting of other characters. When comparing
non-numerical parts, they are compared as the character values (ASCII), but
non-alphabetical characters are considered "greater than"
alphabetical ones. Also note that longer strings (after excluding differences
where numerical values are equal) are considered "greater than"
shorter ones.
Here are a few examples of how these rules apply:-