1 ALPM library overview & internals
2 =================================
4 Here is a list of the main objects and files from the ALPM (i.e. Arch Linux
5 Package Management) library. This document, while not exhaustive, also
6 indicates some limitations (on purpose, or sometimes due to its poor design) of
7 the library at the present time.
9 There is one special file,"alpm.h", which is the public interface that
10 should be distributed and installed on systems with the library. Only
11 structures, data and functions declared within this file are made available to
12 the frontend. Lots of structures are of an opaque type and their fields are
13 only accessible in read-only mode, through some clearly defined functions.
15 In addition to "alpm.h", the interfaces of "alpm_list.h" have also been made
16 available to the frontend, for allowing it to manipulate the lists returned by
19 Several structures and functions have been renamed compared to pacman 2.9 code.
20 This was done at first for the sake of naming scheme consistency, and then
21 primarily because of potential namespace conflicts between library and frontend
22 spaces. Indeed, it is not possible to have two different functions with the
23 same name declared in both spaces. To avoid such conflicts, internal function
24 names have been prepended with "_alpm_".
26 In a general manner, public library functions are named "alpm_<type>_<action>"
27 (examples: alpm_trans_commit(), alpm_release(), alpm_pkg_get_name(), ...).
28 Internal (and thus private) functions should be named "_alpm_XXX" for instance
29 (examples: _alpm_needbackup(), _alpm_runscriplet(), ...). Functions defined and
30 used inside a single file should be defined as "static".
35 alpm_initialize() is used to initialize library internals and to create
36 a transparent handle object. Before its call, the library can't be used.
38 alpm_release() just does the opposite (memory used by the library, and the
39 handle is freed). After its call, the library is no longer available.
44 The library does not use any configuration file. It is up to the front end to
45 configure the library as needed; the handle holds a number of configuration
48 All of the following options have a alpm_option_get_* and alpm_option_set_*
49 function for getting and setting the value. They cannot be set before the
50 library is initialized.
52 * logcb: The callback function for "log" operations.
53 * dlcb: The callback function for download progress of each package.
54 * totaldlcb: The callback function for overall download progress.
55 * root: The root directory for pacman to install to (Default: /)
56 * dbpath: The toplevel database directory (Default: /var/lib/pacman)
57 * logfile: The base path to pacman's log file (Default: /var/log/pacman.log)
58 * usesyslog: Log to syslog instead of `logfile` for file-base logging.
59 * xfercommand: The command to use for downloading instead of pacman's internal
60 downloading functionality.
61 * nopassiveftp: Do not use passive FTP commands for ftp connections.
63 The following options also have `alpm_option_{add,remove}_*` functions, as the
64 values are list structures.
65 NOTE: The add and remove functions are NOT plural, as they are in English:
66 alpm_option_{get,set}_noupgrades -> alpm_option_{add,remove}_noupgrade.
68 * cachedirs: Paths to pacman's download caches (Default: /var/cache/pacman/pkg)
69 * noupgrades: Files which will never be touched by pacman (extracted as .pacnew)
70 * noextracts: Files which will never be extracted at all (no .pacnew file)
71 * ignorepkgs: Packages to ignore when upgrading.
72 * ignoregrps: Groups to ignore when upgrading.
73 * holdpkgs: Important packages which need a confirmation before being removed.
75 The following options are read-only, having ONLY alpm_option_get_* functions:
77 * lockfile: The file used for locking the database
78 (Default: <dbpath>/db.lck)
79 * localdb: A pmdb_t structure for the local (installed) database
80 * syncdbs: A list of pmdb_t structures to which pacman can sync from.
82 The following options are write-only, having ONLY alpm_option_set_* functions:
84 * usedelta: Download delta files instead of complete packages if possible.
88 The transaction structure permits easy manipulations of several packages
89 at a time (i.e. adding, upgrade and removal operations).
91 A transaction can be initiated with a type (SYNC, UPGRADE or REMOVE),
92 and some flags (NODEPS, FORCE, CASCADE, ...).
94 Note: there can only be one type at a time: a transaction is either
95 created to add packages to the system, or either created to remove packages.
96 The frontend can't request for mixed operations: it has to run several
97 transactions, one at a time, in such a case.
99 The flags allow to tweak the library behaviour during its resolution.
100 Note, that some options of the handle can also modify the behavior of a
101 transaction (NOUPGRADE, IGNOREPKG, ...).
103 Note: once a transaction has been initiated, it is not possible anymore
104 to modify its type or its flags.
106 One can also add some targets to a transaction (alpm_trans_addtarget()).
107 These targets represent the list of packages to be handled.
109 Then, a transaction needs to be prepared (alpm_trans_prepare()). It
110 means that the various targets added, will be inspected and challenged
111 against the set of already installed packages (dependency checking, etc...)
113 Last, a callback is associated with each transaction. During the
114 transaction resolution, each time a new step is started or done (i.e
115 dependency or conflict checking, package adding or removal, ...), the
116 callback is called, allowing the frontend to be aware of the progress of
117 the resolution. Can be useful to implement a progress bar.
122 libalpm maintains two caches for each DB. One is a general package cache, the
123 other is a group cache (for package groups). These caches are loaded on demand,
124 and freed when the library is.
126 It is important to note that, as a general rule, package structures should NOT
127 be freed manually, as they SHOULD be part of the cache. The cache of a
128 database is always updated by the library after an operation changing the
129 database content (adding and/or removal of packages). Beware frontends ;)
134 The package structure maintains all information for a package. In general,
135 packages should never be freed from front-ends, as they should always be part
136 of the package cache.
138 The 'origin' data member indicates whether the package is from a file (i.e. -U
139 operations) or from the package cache. In the case of a file, all data members
140 available are present in the structure. Packages indicated as being from the
141 cache have data members filled on demand. For this reason, the alpm_pkg_get_*
142 functions will load the data from the DB as needed.
147 The library provides a global variable pm_errno.
148 It aims at being to the library what errno is for C system calls.
150 Almost all public library functions are returning an integer value: 0
151 indicating success, -1 indicating a failure.
152 If -1 is returned, the variable pm_errno is set to a meaningful value
153 Wise frontends should always care for these returned values.
155 Note: the helper function alpm_strerror() can also be used to translate one
156 specified error code into a more friendly sentence, and alpm_strerrorlast()
157 does the same for the last error encountered (represented by pm_errno).
162 The alpm_list_t structure is a doubly-linked list for use with the libalpm
163 routines. This type is provided publicly so that frontends are free to use it
164 if they have no native list type (C++, glib, python, etc all have list types).
165 See the proper man pages for alpm_list_t references.
169 PACMAN frontend overview & internals
170 ====================================
172 Here are some words about the frontend responsibilities.
173 The library can operate only a small set of well defined operations and
176 High level features are left to the frontend ;)
178 For instance, during a sysupgrade, the library returns the whole list of
179 packages to be upgraded, without any care for its content.
180 The frontend can inspect the list and perhaps notice that "pacman"
181 itself has to be upgraded. In such a case, the frontend can choose to
182 perform a special action.
185 [MAIN] (see pacman.c)
187 Calls for alpm_initialize(), and alpm_release().
188 Read the configuration file, and parse command line arguments.
189 Based on the action requested, it initiates the appropriate transactions
190 (see pacman_upgrade(), pacman_remove(), pacman_sync() in files upgrade.c,
191 remove.c and sync.c).
194 [CONFIGURATION] (see conf.h)
196 The frontend is using a configuration file, usually "/etc/pacman.conf". Some
197 of these options are only useful for the frontend only (mainly the ones used to
198 control the output like showsize or totaldownload, or the behavior with
199 cleanmethod and syncfirst). The rest is used to configure the library.
202 [UPGRADE/REMOVE/SYNC]
204 The file pacman.c has been divided into several smaller files, namely
205 upgrade.c, remove.c, sync.c and query.c, to hold the big parts: pacman_upgrade,
206 pacman_remove, pacman_sync.
208 These 3 functions have been split to ease the code reading.
212 API CHANGES BETWEEN 3.1 AND 3.2
213 ===============================
216 - alpm_db_whatprovides()
217 - alpm_splitdep (no longer public)
218 - trans->targets was removed, so alpm_trans_get_targets() as well
220 PM_ERR_OPT_*, PM_ERR_PKG_INSTALLED, PM_ERR_DLT_CORRUPTED,
221 PM_ERR_LIBARCHIVE_ERROR
222 - event: PM_TRANS_EVT_EXTRACT_DONE
223 - PM_TRANS_TYPE_ADD pmtranstype_t (add transaction)
224 - PM_TRANS_FLAG_DEPENDSONLY pmtransflag_t
227 - alpm_grp_get_pkgs returns with pmpkg_t list, not package-name list
228 - Swap parameters on PM_TRANS_CONV_INSTALL_IGNOREPKG callback function
229 - download callback API changed: alpm_cb_download, alpm_cb_totaldl split
230 (+ new alpm_option_get_totaldlcb(), alpm_option_set_totaldlcb() functions)
231 - unsigned long->off_t changes where size is used
232 - pmsyncpkg_t struct changes:
233 - pmsynctype_t and alpm_sync_get_type() were removed
234 - alpm_sync_get_data() was removed
235 - alpm_sync_get_removes() was added
238 - alpm_delta_get_from_md5sum(), alpm_delta_get_to_md5sum()
239 - alpm_miss_get_causingpkg() (new causingpkg field in pmdepmissing_t)
240 - alpm_checkdbconflicts()
241 - alpm_sync_newversion()
244 PM_ERR_DLT_INVALID, PM_ERR_LIBARCHIVE, PM_ERR_LIBDOWNLOAD and
245 PM_ERR_EXTERNAL_DOWNLOAD
247 PM_TRANS_FLAG_ALLEXPLICIT, PM_TRANS_FLAG_UNNEEDED and
248 PM_TRANS_FLAG_RECURSEALL