Discussed on IRC for a bit, this makes the following changes for clarity:
[pacman.git] / README
blobbb44fb7ade9ae155690092e834386e16983405c1
1 ==========================================================================
2 README:
4 Overview and internals of the ALPM library and the PACMAN frontend.
6 This document describes the state of the implementation before its CVS
7 import.
8 At this stage, the code is in pre-alpha state, but the design should not
9 change that much.
10 There's still need for some work to get the current code properly working.
11 The tag "ORE" was added in various places in the code, each time a point
12 remains unclear or is not yet implemented.
14 ==========================================================================
17 ALPM library overview & internals
18 =================================
20 Here is a list of the main objects and files from the ALPM (i.e. Arch
21 Linux Package Management) library.
22 This document, whilst not exhaustive, also indicates some limitations
23 (on purpose, or sometimes due to its poor design) of the library at the
24 present time.
26 Note: there is one special file ("alpm.h") which is the public interface
27 that should be distributed and installed on systems with the library.
28 Only structures, data and functions declared within this file are made
29 available to the frontend.
30 Lots of structures are of an opaque type and their fields are only
31 accessible in read-only mode, through some clearly defined functions.
33 Note: several structures and functions have been renamed compared to
34 pacman 2.9 code.
35 This was done at first for the sake of naming scheme consistency, and
36 then primarily because of potential namespace conflicts between library
37 and frontend spaces.
38 Indeed, it is not possible to have two different functions with the same
39 name declared in both spaces.
40 To avoid such conflicts, some function names have been prepended with
41 "_alpm_".
42 In a general manner, public library functions are named
43 "alpm_<type>_<action>" (examples: alpm_trans_commit(),
44 alpm_lib_release(), alpm_pkg_getinfo(), ...).
45 Internal (and thus private) functions should be named "_alpm_XXX" for
46 instance (examples: _alpm_needbackup(), _alpm_runscriplet(), ...).
47 As of now, this scheme is only applied to most sensitive functions
48 (mainly the ones from util.c), which have generic names, and thus, which
49 are likely to be redefined in the frontend.
50 One can consider that the frontend should have the priority in function
51 names choice, and that it is up to the library to hide its symbols to
52 avoid conflicts with the frontend ones.
53 Finally, functions defined and used inside a single file should be
54 defined as "static".
57 [HANDLE] (see handle.c)
59 The "handle" object is the heart of the library. It is a global
60 structure available from almost all other objects (althought some very
61 low level objects should not be aware of the handle object, like chained
62 list, package or groups structures.
64 There is only one instance, created by the frontend upon
65 "alpm_lib_init()" call, and destroyed upon "alpm_lib_release()" call.
67 alpm_lib_init() is used to initialize library internals and to create
68 the handle object (handle != NULL).
69 Before its call, the library can't be used.
70 alpm_lib_release() just does the opposite (memory used by the library is
71 freed, and handle is set to NULL).
72 After its call, the library is no more available.
74 The aim of the handle is to provide a central placeholder for essential
75 library parameters (filesystem root, pointers to database objects,
76 configuration parameters, ...)
78 The handle also allows to register a log callback usable by the frontend
79 to catch all sort of notifications from the library.
80 The frontend can choose the level of verbosity (i.e. the mask), or can
81 simply choose to not use the log callback.
82 A friendly frontend should care at least for WARNING and ERROR
83 notifications.
84 Other notifications can safely be ignored and are mainly available for
85 troubleshooting purpose.
87 Last, but not least, the handle holds a _unique_ transaction object.
90 [TRANSACTION] (see trans.c, and also alpm.c)
92 The transaction sturcture permits easy manipulations of several packages
93 at a time (i.e. adding, upgrade and removal operations).
95 A transaction can be initiatied with a type (ADD, UPGRADE or REMOVE),
96 and some flags (NODEPS, FORCE, CASCADE, ...).
98 Note: there can only be one type at a time: a transaction is either
99 created to add packages to the system, or either created to remove packages.
100 The frontend can't request for mixed operations: it has to run several
101 transactions, one at a time, in such a case.
103 The flags allow to tweak the library behaviour during its resolution.
104 Note, that some options of the handle can also modify the behavior of a
105 transaction (NOUPGRADE, IGNOREPKG, ...).
107 Note: once a transaction has been initiated, it is not possible anymore
108 to modify its type or its flags.
110 One can also add some targets to a transaction (alpm_trans_addtarget()).
111 These targets represent the list of packages to be handled.
113 Then, a transaction needs to be prepared (alpm_trans_prepare()). It
114 means that the various targets added, will be inspected and challenged
115 against the set of alreayd installed packages (dependency checkings,
117 Last, a callback is associated with each transaction. During the
118 transaction resolution, each time a new step is started or done (i.e
119 dependency or conflict checkings, package adding or removal, ...), the
120 callback is called, allowing the frontend to be aware of the progress of
121 the resolution. Can be useful to implement a progress bar.
124 [CONFIGURATION/OPTIONS] (see handle.c)
126 The library does not use any configuration file. The handle holds a
127 number of configuration options instead (IGNOREPKG, SYSLOG usage,
128 log file name, registered databases, ...).
129 It is up to the frontend to set the options of the library.
130 Options can be manipulated using calls to
131 alpm_set_option()/alpm_get_option().
133 Note: the file system root is a special option which can only be defined
134 when calling alpm_lib_init(). It can't be modified afterwards.
137 [CACHE] (see cache.c)
139 Compared to pacman 2.9, there is now one cache object connected to each
140 database object.
141 There are both a package and a group cache.
142 The cache is loaded only on demand (i.e the cache is loaded the first
143 time data from it should be used).
145 Note: the cache of a database is always updated by the library after
146 an operation changing the database content (adding and/or removal of
147 packages).
148 Beware frontends ;)
151 [PACKAGE] (see package.c, and also db.c)
153 The package structure is using three new fields, namely: origin, data,
154 infolevel.
155 The purpose of these fields is to know some extra info about data stored
156 in package structures.
158 For instance, where is the package coming from (i.e origin)?
159 Was it loaded from a file or loaded from the cache?
160 If it's coming from a file, then the field data holds the full path and
161 name of the file, and infolevel is set to the highest possible value
162 (all package fields are reputed to be known).
163 Otherwise, if the package comes from a database, data is a pointer to
164 the database structure hosting the package, and infolevel is set
165 according to the db_read() infolevel parameter (it is possible using
166 db_read() to only read a part of the package datas).
168 Indeed, to reduce database access, all packages data requested by the
169 frontend are comming from the cache. As a consequence, the library needs
170 to know exactly the level of information about packages it holds, and
171 then decide if more data needs to be fetched from the database.
173 In file alpm.c, have a look at alpm_pkg_getinfo() function to get an
174 overview.
177 [ERRORS] (error.c)
179 The library provides a global variable pm_errno.
180 It aims at being to the library what errno is for C system calls.
182 Almost all public library functions are returning an integer value: 0
183 indicating success, whereas -1 would indicate a failure.
184 If -1 is returned, the variable pm_errno is set to a meaningful value
185 (not always yet, but it should improve ;).
186 Wise frontends should always care for these returned values.
188 Note: the helper function alpm_strerror() can also be used to translate
189 the error code into a more friendly sentence.
192 [LIST] (see list.c, and especially list wrappers in alpm.c)
194 It is a double chained list structure, use only for the internal needs
195 of the library.
196 A frontend should be free to use its own data structures to manipulate
197 packages.
198 For instance, consider a graphical frontend using the gtk toolkit (and
199 as a consequence the glib library). The frontend will make use of the
200 glib chained lists or trees.
201 As a consequence, the library only provides a simple and very small
202 interface to retrieve pointers to its internal data (see functions
203 alpm_list_first(), alpm_list_next() and alpm_list_getdata()), giving to
204 the frontend the responsibility to copy and store the data retrieved
205 from the library in its own data structures.
208 PACMAN frontend overview & internals
209 ====================================
211 Here are some words about the frontend responsibilities.
212 The library can operate only a small set of well defined operations and
213 dumy operations.
215 High level features are left to the frontend ;)
217 For instance, during a sysupgrade, the library returns the whole list of
218 packages to be upgraded, without any care for its content.
219 The frontend can inspect the list and perhaps notice that "pacman"
220 itself has to be upgraded. In such a case, the frontend can choose to
221 perform a special action.
224 [MAIN] (see pacman.c)
226 Calls for alpm_lib_init(), and alpm_lib_release().
227 Read the configuration file, and parse command line arguments.
228 Based on the action requested, it initiates the appropriate transactions
229 (see pacman_add(), pacman_remove(), pacman_sync() in files add.c,
230 remove.c and sync.c).
233 [CONFIGURATION] (see conf.c)
235 The frontend is using a configuration file, usually "/etc/pacman.conf".
236 Part of these options are only usefull for the frontend only (mainly,
237 the download stuffs, and some options like HOLDPKG).
238 The rest is used to configure the library.
241 [ADD/UPGRADE/REMOVE/SYNC]
243 Nothing new here, excepted some reorganization.
245 The file pacman.c has been divided into several smaller files, namely
246 add.c, remove.c, sync.c and query.c, to hold the big parts: pacman_add,
247 pacman_remove, pacman_sync.
248 These 3 functions have been splitted too to ease the code reading.
251 [DONWLOAD] (see download.c)
253 The library is not providing download facilities. As a consequence, it
254 is up the the frontend to retrieve packages from Arch Linux servers.
255 To do so, pacman is linked against an improved version of libftp
256 supporting both http and ftp donwloads.
257 As a consequence, the frontend is repsonsible for the directory
258 /var/cache/pacman/pkgs.
259 One can consider that this cache is a facility provided by pacman.
261 Note: other frontends have to download packages by themselves too,
262 although the cache directory can be shared by several frontends.
265 [LIST] (see list.c)
267 Single chained list.
268 A minimalistic chained list implementation to store options from the
269 configuration file, and targets passed to pacman on the command line.
272 LIMITATIONS/BEHAVIOR CHANGES COMPARED TO PACMAN 2.9
273 ===================================================
275 Excepted missing features still needing to be implemented, one can
276 notice the following limitations:
278 - If pacman is out of date, the frontend displays a warning and recommends
279 to give up the on-going transanction. The frontend does not allow to
280 upgrade pacman itself on-the-fly, and thus it should be restarted with
281 only "pacman" as a target.
283 - ...