]> git.saurik.com Git - apt.git/blame - doc/dpkg-tech.dbk
use an enum instead of strings as IndexTarget::Option interface
[apt.git] / doc / dpkg-tech.dbk
CommitLineData
271733ee 1<?xml version="1.0" encoding="UTF-8"?>
271733ee
GJ
2<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
5abbf5bb 4<!ENTITY % aptent SYSTEM "apt.ent"> %aptent;
271733ee 5<!ENTITY % aptverbatiment SYSTEM "apt-verbatim.ent"> %aptverbatiment;
5abbf5bb 6<!ENTITY % aptvendor SYSTEM "apt-vendor.ent"> %aptvendor;
271733ee
GJ
7]>
8
9<book lang="en">
10
11<title>dpkg technical manual</title>
12
13<bookinfo>
14
15<authorgroup>
16 <author>
17 <personname>Tom Lees</personname><email>tom@lpsg.demon.co.uk</email>
18 </author>
19</authorgroup>
20
21<releaseinfo>Version &apt-product-version;</releaseinfo>
22
23<abstract>
24<para>
25This document describes the minimum necessary workings for the APT dselect
26replacement. It gives an overall specification of what its external interface
27must look like for compatibility, and also gives details of some internal
28quirks.
29</para>
30</abstract>
31
32<copyright><year>1997</year><holder>Tom Lees</holder></copyright>
33
34<legalnotice>
35<title>License Notice</title>
36<para>
37APT and this document are free software; you can redistribute them and/or
38modify them under the terms of the GNU General Public License as published by
39the Free Software Foundation; either version 2 of the License, or (at your
40option) any later version.
41</para>
42<para>
43For more details, on Debian systems, see the file
44/usr/share/common-licenses/GPL for the full license.
45</para>
46</legalnotice>
47
48</bookinfo>
49
50<chapter id="ch1"><title>Quick summary of dpkg's external interface</title>
51
52<section id="control"><title>Control files</title>
53<para>
54The basic dpkg package control file supports the following major features:-
55</para>
56<itemizedlist>
57<listitem>
58<para>
595 types of dependencies:-
60</para>
61<itemizedlist>
62<listitem>
63<para>
64Pre-Depends, which must be satisfied before a package may be unpacked
65</para>
66</listitem>
67<listitem>
68<para>
69Depends, which must be satisfied before a package may be configured
70</para>
71</listitem>
72<listitem>
73<para>
74Recommends, to specify a package which if not installed may severely limit the
75usefulness of the package
76</para>
77</listitem>
78<listitem>
79<para>
80Suggests, to specify a package which may increase the productivity of the
81package
82</para>
83</listitem>
84<listitem>
85<para>
86Conflicts, to specify a package which must NOT be installed in order for the
87package to be configured
88</para>
89</listitem>
90<listitem>
91<para>
92Breaks, to specify a package which is broken by the package and which should
93therefore not be configured while broken
94</para>
95</listitem>
96</itemizedlist>
97<para>
98Each of these dependencies can specify a version and a depedency on that
99version, for example "&lt;= 0.5-1", "== 2.7.2-1", etc. The comparators
100available are:-
101</para>
102<itemizedlist>
103<listitem>
104<para>
105"&lt;&lt;" - less than
106</para>
107</listitem>
108<listitem>
109<para>
110"&lt;=" - less than or equal to
111</para>
112</listitem>
113<listitem>
114<para>
115"&gt;&gt;" - greater than
116</para>
117</listitem>
118<listitem>
119<para>
120"&gt;=" - greater than or equal to
121</para>
122</listitem>
123<listitem>
124<para>
125"==" - equal to
126</para>
127</listitem>
128</itemizedlist>
129</listitem>
130<listitem>
131<para>
132The concept of "virtual packages", which many other packages may provide,
133using the Provides mechanism. An example of this is the "httpd" virtual
134package, which all web servers should provide. Virtual package names may be
135used in dependency headers. However, current policy is that virtual packages
136do not support version numbers, so dependencies on virtual packages with
137versions will always fail.
138</para>
139</listitem>
140<listitem>
141<para>
142Several other control fields, such as Package, Version, Description, Section,
143Priority, etc., which are mainly for classification purposes. The package
144name must consist entirely of lowercase characters, plus the characters '+',
145'-', and '.'. Fields can extend across multiple lines - on the second and
146subsequent lines, there is a space at the beginning instead of a field name
147and a ':'. Empty lines must consist of the text " .", which will be ignored,
148as will the initial space for other continuation lines. This feature is
149usually only used in the Description field.
150</para>
151</listitem>
152</itemizedlist>
153</section>
154
155<section id="s1.2"><title>The dpkg status area</title>
156<para>
157The "dpkg status area" is the term used to refer to the directory where dpkg
158keeps its various status files (GNU would have you call it the dpkg shared
159state directory). This is always, on Debian systems, /var/lib/dpkg. However,
160the default directory name should not be hard-coded, but #define'd, so that
161alteration is possible (it is available via configure in dpkg 1.4.0.9 and
162above). Of course, in a library, code should be allowed to override the
163default directory, but the default should be part of the library (so that
164the user may change the dpkg admin dir simply by replacing the library).
165</para>
166<para>
167Dpkg keeps a variety of files in its status area. These are discussed later
168on in this document, but a quick summary of the files is here:-
169</para>
170<itemizedlist>
171<listitem>
172<para>
173available - this file contains a concatenation of control information from all
174the packages which dpkg knows about. This is updated using the dpkg commands
175"--update-avail &lt;file&gt;", "--merge-avail &lt;file&gt;", and
176"--clear-avail".
177</para>
178</listitem>
179<listitem>
180<para>
181status - this file contains information on the following things for every
182package:-
183</para>
184<itemizedlist>
185<listitem>
186<para>
187Whether it is installed, not installed, unpacked, removed, failed
188configuration, or half-installed (deconfigured in favour of another package).
189</para>
190</listitem>
191<listitem>
192<para>
193Whether it is selected as install, hold, remove, or purge.
194</para>
195</listitem>
196<listitem>
197<para>
198If it is "ok" (no installation problems), or "not-ok".
199</para>
200</listitem>
201<listitem>
202<para>
203It usually also contains the section and priority (so that dselect may classify
204packages not in available)
205</para>
206</listitem>
207<listitem>
208<para>
209For packages which did not initially appear in the "available" file when they
210were installed, the other control information for them.
211</para>
212</listitem>
213</itemizedlist>
214<para>
215The exact format for the "Status:" field is:
216</para>
217<screen>
218 Status: Want Flag Status
219</screen>
220<para>
221Where <replaceable>Want</replaceable> may be one of
222<emphasis>unknown</emphasis>, <emphasis>install</emphasis>,
223<emphasis>hold</emphasis>, <emphasis>deinstall</emphasis>,
224<emphasis>purge</emphasis>. <replaceable>Flag</replaceable> may
9227645d
GJ
225be one of <emphasis>ok</emphasis>, <emphasis>reinstreq</emphasis>.
226<replaceable>Status</replaceable> may
227be one of <emphasis>not-installed</emphasis>, <emphasis>config-files</emphasis>,
228<emphasis>half-installed</emphasis>, <emphasis>unpacked</emphasis>,
229<emphasis>half-configured</emphasis> and <emphasis>installed</emphasis>.
271733ee
GJ
230The states are as follows:-
231</para>
232<variablelist>
233<varlistentry>
234<term>not-installed</term>
235<listitem>
236<para>
237No files are installed from the package, it has no config files left, it
238uninstalled cleanly if it ever was installed.
239</para>
240</listitem>
241</varlistentry>
242<varlistentry>
243<term>unpacked</term>
244<listitem>
245<para>
246The basic files have been unpacked (and are listed in
247/var/lib/dpkg/info/[package].list. There are config files present, but the
248postinst script has _NOT_ been run.
249</para>
250</listitem>
251</varlistentry>
252<varlistentry>
253<term>half-configured</term>
254<listitem>
255<para>
256The package was installed and unpacked, but the postinst script failed in some
257way.
258</para>
259</listitem>
260</varlistentry>
261<varlistentry>
262<term>installed</term>
263<listitem>
264<para>
265All files for the package are installed, and the configuration was also
266successful.
267</para>
268</listitem>
269</varlistentry>
270<varlistentry>
271<term>half-installed</term>
272<listitem>
273<para>
274An attempt was made to remove the packagem but there was a failure in the
275prerm script.
276</para>
277</listitem>
278</varlistentry>
279<varlistentry>
280<term>config-files</term>
281<listitem>
282<para>
283The package was "removed", not "purged". The config files are left, but
284nothing else.
285</para>
286</listitem>
287</varlistentry>
271733ee
GJ
288</variablelist>
289<para>
290The two last items are only left in dpkg for compatibility - they are
291understood by it, but never written out in this form.
292</para>
293<para>
294Please see the dpkg source code, <literal>lib/parshelp.c</literal>,
295<emphasis>statusinfos</emphasis>, <emphasis>eflaginfos</emphasis> and
296<emphasis>wantinfos</emphasis> for more details.
297</para>
298</listitem>
299<listitem>
300<para>
301info - this directory contains files from the control archive of every
302package currently installed. They are installed with a prefix of
303"&lt;packagename&gt;.". In addition to this, it also contains a file
304called &lt;package&gt;.list for every package, which contains a list
305of files. Note also that the control file is not copied into here; it
306is instead found as part of status or available.
307</para>
308</listitem>
309<listitem>
310<para>
311methods - this directory is reserved for "method"-specific files - each
312"method" has a subdirectory underneath this directory (or at least,
313it can have). In addition, there is another subdirectory "mnt", where
314misc. filesystems (floppies, CD-ROMs, etc.) are mounted.
315</para>
316</listitem>
317<listitem>
318<para>
319alternatives - directory used by the "update-alternatives" program. It
320contains one file for each "alternatives" interface, which contains
321information about all the needed symlinked files for each alternative.
322</para>
323</listitem>
324<listitem>
325<para>
326diversions - file used by the "dpkg-divert" program. Each diversion takes
327three lines. The first is the package name (or ":" for user diversion), the
328second the original filename, and the third the diverted filename.
329</para>
330</listitem>
331<listitem>
332<para>
333updates - directory used internally by dpkg. This is discussed later, in the
334section <xref linkend="updates"/>.
335</para>
336</listitem>
337<listitem>
338<para>
339parts - temporary directory used by dpkg-split
340</para>
341</listitem>
342</itemizedlist>
343</section>
344
345<section id="s1.3"><title>The dpkg library files</title>
346<para>
347These files are installed under /usr/lib/dpkg (usually), but
348/usr/local/lib/dpkg is also a possibility (as Debian policy dictates). Under
349this directory, there is a "methods" subdirectory. The methods subdirectory in
350turn contains any number of subdirectories for each general method processor
351(note that one set of method scripts can, and is, used for more than one of
352the methods listed under dselect).
353</para>
354<para>
355The following files may be found in each of these subdirectories:-
356</para>
357<itemizedlist>
358<listitem>
359<para>
360names - One line per method, two-digit priority to appear on menu at
361beginning, followed by a space, the name, and then another space and
362the short description.
363</para>
364</listitem>
365<listitem>
366<para>
367desc.&lt;name&gt; - Contains the long description displayed by dselect
368when the cursor is put over the &lt;name&gt; method.
369</para>
370</listitem>
371<listitem>
372<para>
373setup - Script or program which sets up the initial values to be used
374by this method. Called with first argument as the status area directory
375(/var/lib/dpkg), second argument as the name of the method (as in the
376directory name), and the third argument as the option (as in the names file).
377</para>
378</listitem>
379<listitem>
380<para>
381install - Script/program called when the "install" option of dselect is run
382with this method. Same arguments as for setup.
383</para>
384</listitem>
385<listitem>
386<para>
387update - Script/program called when the "update" option of dselect is
388run. Same arguments as for setup/install.
389</para>
390</listitem>
391</itemizedlist>
392</section>
393
394<section id="s1.4"><title>The "dpkg" command-line utility</title>
395
396<section id="s1.4.1"><title>"Documented" command-line interfaces</title>
397<para>
398As yet unwritten. You can refer to the other manuals for now. See
399<citerefentry><refentrytitle>dpkg</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
400</para>
401</section>
402
403<section id="s1.4.2"><title>Environment variables which dpkg responds to</title>
404<itemizedlist>
405<listitem>
406<para>
407DPKG_NO_TSTP - if set to a non-null value, this variable causes dpkg to run a
408child shell process instead of sending itself a SIGTSTP, when the user selects
409to background the dpkg process when it asks about conffiles.
410</para>
411</listitem>
412<listitem>
413<para>
414SHELL - used to determine which shell to run in the case when DPKG_NO_TSTP
415is set.
416</para>
417</listitem>
418<listitem>
419<para>
420CC - used as the C compiler to call to determine the target architecture. The
421default is "gcc".
422</para>
423</listitem>
424<listitem>
425<para>
426PATH - dpkg checks that it can find at least the following files in the path
427when it wants to run package installation scripts, and gives an error if it
428cannot find all of them:-
429</para>
430<itemizedlist>
431<listitem>
432<para>
433ldconfig
434</para>
435</listitem>
436<listitem>
437<para>
438start-stop-daemon
439</para>
440</listitem>
441<listitem>
442<para>
443install-info
444</para>
445</listitem>
446<listitem>
447<para>
448update-rc.d
449</para>
450</listitem>
451</itemizedlist>
452</listitem>
453</itemizedlist>
454</section>
455
456<section id="s1.4.3"><title>Assertions</title>
457<para>
458The dpkg utility itself is required for quite a number of packages, even if
459they have been installed with a tool totally separate from dpkg. The reason
460for this is that some packages, in their pre-installation scripts, check that
461your version of dpkg supports certain features. This was broken from the
462start, and it should have actually been a control file header "Dpkg-requires",
463or similar. What happens is that the configuration scripts will abort or
464continue according to the exit code of a call to dpkg, which will stop them
465from being wrongly configured.
466</para>
467<para>
468These special command-line options, which simply return as true or false are
469all prefixed with "--assert-". Here is a list of them (without the prefix):-
470</para>
471<itemizedlist>
472<listitem>
473<para>
474support-predepends - Returns success or failure according to whether a version
475of dpkg which supports predepends properly (1.1.0 or above) is installed,
476according to the database.
477</para>
478</listitem>
479<listitem>
480<para>
481working-epoch - Return success or failure according to whether a version of
482dpkg which supports epochs in version properly (1.4.0.7 or above) is installed,
483according to the database.
484</para>
485</listitem>
486</itemizedlist>
487<para>
488Both these options check the status database to see what version of the
489"dpkg" package is installed, and check it against a known working version.
490</para>
491</section>
492
493<section id="s1.4.4"><title>--predep-package</title>
494<para>
495This strange option is described as follows in the source code:
496</para>
497<screen>
498/* Print a single package which:
499 * (a) is the target of one or more relevant predependencies.
500 * (b) has itself no unsatisfied pre-dependencies.
501 * If such a package is present output is the Packages file entry,
502 * which can be massaged as appropriate.
503 * Exit status:
504 * 0 = a package printed, OK
505 * 1 = no suitable package available
506 * 2 = error
507 */
508</screen>
509<para>
510On further inspection of the source code, it appears that what is does is
511this:-
512</para>
513<itemizedlist>
514<listitem>
515<para>
516Looks at the packages in the database which are selected as "install",
517and are installed.
518</para>
519</listitem>
520<listitem>
521<para>
522It then looks at the Pre-Depends information for each of these packages
523from the available file. When it find a package for which any of the
524pre-dependencies are not satisfied, it breaks from the loop through the
525packages.
526</para>
527</listitem>
528<listitem>
529<para>
530It then looks through the unsatisfied pre-dependencies, and looks for
531packages which would satisfy this pre-dependency, stopping on the first
532it finds. If it finds none, it bombs out with an error.
533</para>
534</listitem>
535<listitem>
536<para>
537It then continues this for every dependency of the initial package.
538</para>
539</listitem>
540</itemizedlist>
541<para>
542Eventually, it writes out the record of all the packages to satisfy the
543pre-dependencies. This is used by the disk method to make sure that its
544dependency ordering is correct. What happens is that all pre-depending
545packages are first installed, then it runs dpkg -iGROEB on the directory,
546which installs in the order package files are found. Since pre-dependencies
547mean that a package may not even be unpacked unless they are satisfied, it
548is necessary to do this (usually, since all the package files are unpacked
549in one phase, the configured in another, this is not needed).
550</para>
551</section>
552
553</section>
554
555</chapter>
556
557<chapter id="ch2"><title>dpkg-deb and .deb file internals</title>
558<para>
559This chapter describes the internals to the "dpkg-deb" tool, which is used by
560"dpkg" as a back-end. dpkg-deb has its own tar extraction functions, which is
561the source of many problems, as it does not support long filenames, using
562extension blocks.
563</para>
564
565<section id="s2.1"><title>The .deb archive format</title>
566<para>
567The main principal of the new-format Debian archive (I won't describe the old
568format - for that have a look at deb-old.5), is that the archive really is an
569archive - as used by "ar" and friends. However, dpkg-deb uses this format
570internally, rather than calling "ar". Inside this archive, there are usually
571the following members:-
572</para>
573<itemizedlist>
574<listitem>
575<para>
576debian-binary
577</para>
578</listitem>
579<listitem>
580<para>
581control.tar.gz
582</para>
583</listitem>
584<listitem>
585<para>
586data.tar.gz
587</para>
588</listitem>
589</itemizedlist>
590<para>
591The debian-binary member consists simply of the string "2.0", indicating
592the format version. control.tar.gz contains the control files (and scripts),
593and the data.tar.gz contains the actual files to populate the filesystem
594with. Both tarfiles extract straight into the current directory. Information
595on the tar formats can be found in the GNU tar info page. Since dpkg-deb
596calls "tar -cf" to build packages, the Debian packages use the GNU extensions.
597</para>
598</section>
599
600<section id="s2.2"><title>The dpkg-deb command-line</title>
601<para>
602dpkg-deb documents itself thoroughly with its '--help' command-line
603option. However, I am including a reference to these for
604completeness. dpkg-deb supports the following options:-
605</para>
606<itemizedlist>
607<listitem>
608<para>
609--build (-b) &lt;dir&gt; - builds a .deb archive, takes a directory which
610contains all the files as an argument. Note that the directory
611&lt;dir&gt;/DEBIAN will be packed separately into the control archive.
612</para>
613</listitem>
614<listitem>
615<para>
616--contents (-c) &lt;debfile&gt; - Lists the contents of the "data.tar.gz"
617member.
618</para>
619</listitem>
620<listitem>
621<para>
622--control (-e) &lt;debfile&gt; - Extracts the control archive into a directory
623called DEBIAN. Alternatively, with another argument, it will extract it into a
624different directory.
625</para>
626</listitem>
627<listitem>
628<para>
629--info (-I) &lt;debfile&gt; - Prints the contents of the "control" file in the
630control archive to stdout. Alternatively, giving it other arguments will cause
631it to print the contents of those files instead.
632</para>
633</listitem>
634<listitem>
635<para>
636--field (-f) &lt;debfile&gt; &lt;field&gt; ... - Prints any number of fields
637from the "control" file. Giving it extra arguments limits the fields it prints
638to only those specified. With no command-line arguments other than a filename,
639it is equivalent to -I and just the .deb filename.
640</para>
641</listitem>
642<listitem>
643<para>
644--extract (-x) &lt;debfile&gt; &lt;dir&gt; - Extracts the data archive of a
645debian package under the directory &lt;dir&gt;.
646</para>
647</listitem>
648<listitem>
649<para>
650--vextract (-X) &lt;debfile&gt; &lt;dir&gt; - Same as --extract, except it
651is equivalent of giving tar the '-v' option - it prints the filenames as it
652extracts them.
653</para>
654</listitem>
655<listitem>
656<para>
657--fsys-tarfile &lt;debfile&gt; - This option outputs a gunzip'd version of
658data.tar.gz to stdout.
659</para>
660</listitem>
661<listitem>
662<para>
663--new - sets the archive format to be used to the new Debian format
664</para>
665</listitem>
666<listitem>
667<para>
668--old - sets the archive format to be used to the old Debian format
669</para>
670</listitem>
671<listitem>
672<para>
673--debug - Tells dpkg-deb to produce debugging output
674</para>
675</listitem>
676<listitem>
677<para>
678--nocheck - Tells dpkg-deb not to check the sanity of the control file
679</para>
680</listitem>
681<listitem>
682<para>
683--help (-h) - Gives a help message
684</para>
685</listitem>
686<listitem>
687<para>
688--version - Shows the version number
689</para>
690</listitem>
691<listitem>
692<para>
693--licence/--license (UK/US spellings) - Shows a brief outline of the GPL
694</para>
695</listitem>
696</itemizedlist>
697
698<section id="s2.2.1"><title>Internal checks used by dpkg-deb when building packages</title>
699<para>
700Here is a list of the internal checks used by dpkg-deb when building
701packages. It is in the order they are done.
702</para>
703<itemizedlist>
704<listitem>
705<para>
706First, the output Debian archive argument, if it is given, is checked using
707stat. If it is a directory, an internal flag is set. This check is only made
708if the archive name is specified explicitly on the command-line. If the
709argument was not given, the default is the directory name, with ".deb"
710appended.
711</para>
712</listitem>
713<listitem>
714<para>
715Next, the control file is checked, unless the --nocheck flag was specified on
716the command-line. dpkg-deb will bomb out if the second argument to --build was
717a directory, and --nocheck was specified. Note that dpkg-deb will not be able
718to determine the name of the package in this case. In the control file, the
719following things are checked:-
720</para>
721<itemizedlist>
722<listitem>
723<para>
724The package name is checked to see if it contains any invalid characters (see
725<xref linkend="control"/> for this).
726</para>
727</listitem>
728<listitem>
729<para>
730The priority field is checked to see if it uses standard values, and
731user-defined values are warned against. However, note that this check is now
732redundant, since the control file no longer contains the priority - the
733changes file now does this.
734</para>
735</listitem>
736<listitem>
737<para>
738The control file fields are then checked against the standard list of fields
739which appear in control files, and any "user-defined" fields are reported as
740warnings.
741</para>
742</listitem>
743<listitem>
744<para>
745dpkg-deb then checks that the control file contains a valid version number.
746</para>
747</listitem>
748</itemizedlist>
749</listitem>
750<listitem>
751<para>
752After this, in the case where a directory was specified to build the .deb file
753in, the filename is created as "directory/pkg_ver.deb" or
754"directory/pkg_ver_arch.deb", depending on whether the control file contains
755an architecture field.
756</para>
757</listitem>
758<listitem>
759<para>
760Next, dpkg-deb checks for the &lt;dir&gt;/DEBIAN directory. It complains if it
761doesn't exist, or if it has permissions &lt; 0755, or &gt; 0775.
762</para>
763</listitem>
764<listitem>
765<para>
766It then checks that all the files in this subdir are either symlinks or plain
767files, and have permissions between 0555 and 0775.
768</para>
769</listitem>
770<listitem>
771<para>
772The conffiles file is then checked to see if the filenames are too
773long. Warnings are produced for each that is. After this, it checks
774that the package provides initial copies of each of these conffiles,
775and that they are all plain files.
776</para>
777</listitem>
778</itemizedlist>
779</section>
780
781</section>
782
783</chapter>
784
785<chapter id="ch3"><title>dpkg internals</title>
786<para>
787This chapter describes the internals of dpkg itself. Although the low-level
788formats are quite simple, what dpkg does in certain cases often does not make
789sense.
790</para>
791
792<section id="updates"><title>Updates</title>
793<para>
794This describes the /var/lib/dpkg/updates directory. The function of this
795directory is somewhat strange, and seems only to be used internally. A
796function called cleanupdates is called whenever the database is scanned. This
797function in turn uses
798<citerefentry><refentrytitle>scandir</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
799to sort the files in this directory. Files who names do not consist entirely
800of digits are discarded. dpkg also causes a fatal error if any of the
801filenames are different lengths.
802</para>
803<para>
804After having scanned the directory, dpkg in turn parses each file the same way
805it parses the status file (they are sorted by the scandir to be in numerical
806order). After having done this, it then writes the status information back to
807the "status" file, and removes all the "updates" files.
808</para>
809<para>
810These files are created internally by dpkg's "checkpoint" function, and are
811cleaned up when dpkg exits cleanly.
812</para>
813<para>
814Juding by the use of the updates directory I would call it a Journal. Inorder
815to efficiently ensure the complete integrity of the status file dpkg will
816"checkpoint" or journal all of it's activities in the updates directory. By
817merging the contents of the updates directory (in order!!) against the original
818status file it can get the precise current state of the system, even in the
819event of a system failure while dpkg is running.
820</para>
821<para>
822The other option would be to sync-rewrite the status file after each operation,
823which would kill performance.
824</para>
825<para>
826It is very important that any program that uses the status file abort if the
827updates directory is not empty! The user should be informed to run dpkg
828manually (what options though??) to correct the situation.
829</para>
830</section>
831
832<section id="s3.2"><title>What happens when dpkg reads the database</title>
833<para>
834First, the status file is read. This gives dpkg an initial idea of the
835packages that are there. Next, the updates files are read in, overriding the
836status file, and if necessary, the status file is re-written, and updates files
837are removed. Finally, the available file is read. The available file is read
838with flags which preclude dpkg from updating any status information from it,
839though - installed version, etc., and is also told to record that the packages
840it reads this time are available, not installed.
841</para>
842<para>
843More information on updates is given above.
844</para>
845</section>
846
847<section id="s3.3"><title>How dpkg compares version numbers</title>
848<para>
849Version numbers consist of three parts: the epoch, the upstream version, and
850the Debian revision. Dpkg compares these parts in that order. If the epochs
851are different, it returns immediately, and so on.
852</para>
853<para>
854However, the important part is how it compares the versions which are
855essentially stored as just strings. These are compared in two distinct
856parts: those consisting of numerical characters (which are evaluated, and
857then compared), and those consisting of other characters. When comparing
858non-numerical parts, they are compared as the character values (ASCII),
859but non-alphabetical characters are considered "greater than" alphabetical
860ones. Also note that longer strings (after excluding differences where
861numerical values are equal) are considered "greater than" shorter ones.
862</para>
863<para>
864Here are a few examples of how these rules apply:-
865</para>
866<screen>
86715 &gt; 10
8680010 == 10
869
870d.r &gt; dsr
87132.d.r == 0032.d.r
872d.rnr &lt; d.rnrn
873</screen>
874</section>
875
876</chapter>
877
878</book>