Allow specifying shell for running scriptlets
[pacman-ng.git] / lib / libalpm / alpm.h
blobca6509280a91f5e737e308d93c7e46dfbeaf1685
1 /*
2 * alpm.h
4 * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
5 * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
6 * Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
7 * Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
8 * Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef _ALPM_H
24 #define _ALPM_H
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
30 #include <stdint.h> /* int64_t */
31 #include <sys/types.h> /* off_t */
32 #include <stdarg.h> /* va_list */
34 #include <alpm_list.h>
37 * Arch Linux Package Management library
40 /** @addtogroup alpm_api Public API
41 * The libalpm Public API
42 * @{
45 typedef int64_t alpm_time_t;
48 * Enumerations
49 * These ones are used in multiple contexts, so are forward-declared.
52 /** Package install reasons. */
53 typedef enum _alpm_pkgreason_t {
54 /** Explicitly requested by the user. */
55 ALPM_PKG_REASON_EXPLICIT = 0,
56 /** Installed as a dependency for another package. */
57 ALPM_PKG_REASON_DEPEND = 1
58 } alpm_pkgreason_t;
60 /** Location a package object was loaded from. */
61 typedef enum _alpm_pkgfrom_t {
62 PKG_FROM_FILE = 1,
63 PKG_FROM_LOCALDB,
64 PKG_FROM_SYNCDB
65 } alpm_pkgfrom_t;
67 /** Types of version constraints in dependency specs. */
68 typedef enum _alpm_depmod_t {
69 /** No version constraint */
70 ALPM_DEP_MOD_ANY = 1,
71 /** Test version equality (package=x.y.z) */
72 ALPM_DEP_MOD_EQ,
73 /** Test for at least a version (package>=x.y.z) */
74 ALPM_DEP_MOD_GE,
75 /** Test for at most a version (package<=x.y.z) */
76 ALPM_DEP_MOD_LE,
77 /** Test for greater than some version (package>x.y.z) */
78 ALPM_DEP_MOD_GT,
79 /** Test for less than some version (package<x.y.z) */
80 ALPM_DEP_MOD_LT
81 } alpm_depmod_t;
83 /**
84 * File conflict type.
85 * Whether the conflict results from a file existing on the filesystem, or with
86 * another target in the transaction.
88 typedef enum _alpm_fileconflicttype_t {
89 ALPM_FILECONFLICT_TARGET = 1,
90 ALPM_FILECONFLICT_FILESYSTEM
91 } alpm_fileconflicttype_t;
93 /** PGP signature verification options */
94 typedef enum _alpm_siglevel_t {
95 ALPM_SIG_PACKAGE = (1 << 0),
96 ALPM_SIG_PACKAGE_OPTIONAL = (1 << 1),
97 ALPM_SIG_PACKAGE_MARGINAL_OK = (1 << 2),
98 ALPM_SIG_PACKAGE_UNKNOWN_OK = (1 << 3),
100 ALPM_SIG_DATABASE = (1 << 10),
101 ALPM_SIG_DATABASE_OPTIONAL = (1 << 11),
102 ALPM_SIG_DATABASE_MARGINAL_OK = (1 << 12),
103 ALPM_SIG_DATABASE_UNKNOWN_OK = (1 << 13),
105 ALPM_SIG_USE_DEFAULT = (1 << 31)
106 } alpm_siglevel_t;
108 /** PGP signature verification status return codes */
109 typedef enum _alpm_sigstatus_t {
110 ALPM_SIGSTATUS_VALID,
111 ALPM_SIGSTATUS_KEY_EXPIRED,
112 ALPM_SIGSTATUS_SIG_EXPIRED,
113 ALPM_SIGSTATUS_KEY_UNKNOWN,
114 ALPM_SIGSTATUS_KEY_DISABLED,
115 ALPM_SIGSTATUS_INVALID
116 } alpm_sigstatus_t;
118 /** PGP signature verification status return codes */
119 typedef enum _alpm_sigvalidity_t {
120 ALPM_SIGVALIDITY_FULL,
121 ALPM_SIGVALIDITY_MARGINAL,
122 ALPM_SIGVALIDITY_NEVER,
123 ALPM_SIGVALIDITY_UNKNOWN
124 } alpm_sigvalidity_t;
127 * Structures
130 typedef struct __alpm_handle_t alpm_handle_t;
131 typedef struct __alpm_db_t alpm_db_t;
132 typedef struct __alpm_pkg_t alpm_pkg_t;
133 typedef struct __alpm_trans_t alpm_trans_t;
135 /** Dependency */
136 typedef struct _alpm_depend_t {
137 char *name;
138 char *version;
139 unsigned long name_hash;
140 alpm_depmod_t mod;
141 } alpm_depend_t;
143 /** Missing dependency */
144 typedef struct _alpm_depmissing_t {
145 char *target;
146 alpm_depend_t *depend;
147 /* this is used only in the case of a remove dependency error */
148 char *causingpkg;
149 } alpm_depmissing_t;
151 /** Conflict */
152 typedef struct _alpm_conflict_t {
153 unsigned long package1_hash;
154 unsigned long package2_hash;
155 char *package1;
156 char *package2;
157 alpm_depend_t *reason;
158 } alpm_conflict_t;
160 /** File conflict */
161 typedef struct _alpm_fileconflict_t {
162 char *target;
163 alpm_fileconflicttype_t type;
164 char *file;
165 char *ctarget;
166 } alpm_fileconflict_t;
168 /** Package group */
169 typedef struct _alpm_group_t {
170 /** group name */
171 char *name;
172 /** list of alpm_pkg_t packages */
173 alpm_list_t *packages;
174 } alpm_group_t;
176 /** Package upgrade delta */
177 typedef struct _alpm_delta_t {
178 /** filename of the delta patch */
179 char *delta;
180 /** md5sum of the delta file */
181 char *delta_md5;
182 /** filename of the 'before' file */
183 char *from;
184 /** filename of the 'after' file */
185 char *to;
186 /** filesize of the delta file */
187 off_t delta_size;
188 /** download filesize of the delta file */
189 off_t download_size;
190 } alpm_delta_t;
192 /** File in a package */
193 typedef struct _alpm_file_t {
194 char *name;
195 off_t size;
196 mode_t mode;
197 } alpm_file_t;
199 /** Package filelist container */
200 typedef struct _alpm_filelist_t {
201 size_t count;
202 alpm_file_t *files;
203 } alpm_filelist_t;
205 /** Local package or package file backup entry */
206 typedef struct _alpm_backup_t {
207 char *name;
208 char *hash;
209 } alpm_backup_t;
211 typedef struct _alpm_pgpkey_t {
212 void *data;
213 char *fingerprint;
214 char *uid;
215 char *name;
216 char *email;
217 alpm_time_t created;
218 alpm_time_t expires;
219 unsigned int length;
220 unsigned int revoked;
221 char pubkey_algo;
222 } alpm_pgpkey_t;
225 * Signature result. Contains the key, status, and validity of a given
226 * signature.
228 typedef struct _alpm_sigresult_t {
229 alpm_pgpkey_t key;
230 alpm_sigstatus_t status;
231 alpm_sigvalidity_t validity;
232 } alpm_sigresult_t;
235 * Signature list. Contains the number of signatures found and a pointer to an
236 * array of results. The array is of size count.
238 typedef struct _alpm_siglist_t {
239 size_t count;
240 alpm_sigresult_t *results;
241 } alpm_siglist_t;
244 * Logging facilities
247 /** Logging Levels */
248 typedef enum _alpm_loglevel_t {
249 ALPM_LOG_ERROR = 1,
250 ALPM_LOG_WARNING = (1 << 1),
251 ALPM_LOG_DEBUG = (1 << 2),
252 ALPM_LOG_FUNCTION = (1 << 3)
253 } alpm_loglevel_t;
255 typedef void (*alpm_cb_log)(alpm_loglevel_t, const char *, va_list);
256 int alpm_logaction(alpm_handle_t *handle, const char *fmt, ...);
259 * Events.
260 * NULL parameters are passed to in all events unless specified otherwise.
262 typedef enum _alpm_event_t {
263 /** Dependencies will be computed for a package. */
264 ALPM_EVENT_CHECKDEPS_START = 1,
265 /** Dependencies were computed for a package. */
266 ALPM_EVENT_CHECKDEPS_DONE,
267 /** File conflicts will be computed for a package. */
268 ALPM_EVENT_FILECONFLICTS_START,
269 /** File conflicts were computed for a package. */
270 ALPM_EVENT_FILECONFLICTS_DONE,
271 /** Dependencies will be resolved for target package. */
272 ALPM_EVENT_RESOLVEDEPS_START,
273 /** Dependencies were resolved for target package. */
274 ALPM_EVENT_RESOLVEDEPS_DONE,
275 /** Inter-conflicts will be checked for target package. */
276 ALPM_EVENT_INTERCONFLICTS_START,
277 /** Inter-conflicts were checked for target package. */
278 ALPM_EVENT_INTERCONFLICTS_DONE,
279 /** Package will be installed.
280 * A pointer to the target package is passed to the callback.
282 ALPM_EVENT_ADD_START,
283 /** Package was installed.
284 * A pointer to the new package is passed to the callback.
286 ALPM_EVENT_ADD_DONE,
287 /** Package will be removed.
288 * A pointer to the target package is passed to the callback.
290 ALPM_EVENT_REMOVE_START,
291 /** Package was removed.
292 * A pointer to the removed package is passed to the callback.
294 ALPM_EVENT_REMOVE_DONE,
295 /** Package will be upgraded.
296 * A pointer to the upgraded package is passed to the callback.
298 ALPM_EVENT_UPGRADE_START,
299 /** Package was upgraded.
300 * A pointer to the new package, and a pointer to the old package is passed
301 * to the callback, respectively.
303 ALPM_EVENT_UPGRADE_DONE,
304 /** Target package's integrity will be checked. */
305 ALPM_EVENT_INTEGRITY_START,
306 /** Target package's integrity was checked. */
307 ALPM_EVENT_INTEGRITY_DONE,
308 /** Target package will be loaded. */
309 ALPM_EVENT_LOAD_START,
310 /** Target package is finished loading. */
311 ALPM_EVENT_LOAD_DONE,
312 /** Target deltas's integrity will be checked. */
313 ALPM_EVENT_DELTA_INTEGRITY_START,
314 /** Target delta's integrity was checked. */
315 ALPM_EVENT_DELTA_INTEGRITY_DONE,
316 /** Deltas will be applied to packages. */
317 ALPM_EVENT_DELTA_PATCHES_START,
318 /** Deltas were applied to packages. */
319 ALPM_EVENT_DELTA_PATCHES_DONE,
320 /** Delta patch will be applied to target package.
321 * The filename of the package and the filename of the patch is passed to the
322 * callback.
324 ALPM_EVENT_DELTA_PATCH_START,
325 /** Delta patch was applied to target package. */
326 ALPM_EVENT_DELTA_PATCH_DONE,
327 /** Delta patch failed to apply to target package. */
328 ALPM_EVENT_DELTA_PATCH_FAILED,
329 /** Scriptlet has printed information.
330 * A line of text is passed to the callback.
332 ALPM_EVENT_SCRIPTLET_INFO,
333 /** Files will be downloaded from a repository.
334 * The repository's tree name is passed to the callback.
336 ALPM_EVENT_RETRIEVE_START,
337 /** Disk space usage will be computed for a package */
338 ALPM_EVENT_DISKSPACE_START,
339 /** Disk space usage was computed for a package */
340 ALPM_EVENT_DISKSPACE_DONE
341 } alpm_event_t;
343 /** Event callback */
344 typedef void (*alpm_cb_event)(alpm_event_t, void *, void *);
347 * Questions.
348 * Unlike the events or progress enumerations, this enum has bitmask values
349 * so a frontend can use a bitmask map to supply preselected answers to the
350 * different types of questions.
352 typedef enum _alpm_question_t {
353 ALPM_QUESTION_INSTALL_IGNOREPKG = 1,
354 ALPM_QUESTION_REPLACE_PKG = (1 << 1),
355 ALPM_QUESTION_CONFLICT_PKG = (1 << 2),
356 ALPM_QUESTION_CORRUPTED_PKG = (1 << 3),
357 ALPM_QUESTION_LOCAL_NEWER = (1 << 4),
358 ALPM_QUESTION_REMOVE_PKGS = (1 << 5),
359 ALPM_QUESTION_SELECT_PROVIDER = (1 << 6),
360 ALPM_QUESTION_IMPORT_KEY = (1 << 7)
361 } alpm_question_t;
363 /** Question callback */
364 typedef void (*alpm_cb_question)(alpm_question_t, void *, void *, void *, int *);
366 /** Progress */
367 typedef enum _alpm_progress_t {
368 ALPM_PROGRESS_ADD_START,
369 ALPM_PROGRESS_UPGRADE_START,
370 ALPM_PROGRESS_REMOVE_START,
371 ALPM_PROGRESS_CONFLICTS_START,
372 ALPM_PROGRESS_DISKSPACE_START,
373 ALPM_PROGRESS_INTEGRITY_START,
374 ALPM_PROGRESS_LOAD_START
375 } alpm_progress_t;
377 /** Progress callback */
378 typedef void (*alpm_cb_progress)(alpm_progress_t, const char *, int, size_t, size_t);
381 * Downloading
384 /** Type of download progress callbacks.
385 * @param filename the name of the file being downloaded
386 * @param xfered the number of transferred bytes
387 * @param total the total number of bytes to transfer
389 typedef void (*alpm_cb_download)(const char *filename,
390 off_t xfered, off_t total);
392 typedef void (*alpm_cb_totaldl)(off_t total);
394 /** A callback for downloading files
395 * @param url the URL of the file to be downloaded
396 * @param localpath the directory to which the file should be downloaded
397 * @param force whether to force an update, even if the file is the same
398 * @return 0 on success, 1 if the file exists and is identical, -1 on
399 * error.
401 typedef int (*alpm_cb_fetch)(const char *url, const char *localpath,
402 int force);
404 /** Fetch a remote pkg.
405 * @param handle the context handle
406 * @param url URL of the package to download
407 * @return the downloaded filepath on success, NULL on error
409 char *alpm_fetch_pkgurl(alpm_handle_t *handle, const char *url);
411 /** @addtogroup alpm_api_options Options
412 * Libalpm option getters and setters
413 * @{
416 /** Returns the callback used for logging. */
417 alpm_cb_log alpm_option_get_logcb(alpm_handle_t *handle);
418 /** Sets the callback used for logging. */
419 int alpm_option_set_logcb(alpm_handle_t *handle, alpm_cb_log cb);
421 /** Returns the callback used to report download progress. */
422 alpm_cb_download alpm_option_get_dlcb(alpm_handle_t *handle);
423 /** Sets the callback used to report download progress. */
424 int alpm_option_set_dlcb(alpm_handle_t *handle, alpm_cb_download cb);
426 /** Returns the downloading callback. */
427 alpm_cb_fetch alpm_option_get_fetchcb(alpm_handle_t *handle);
428 /** Sets the downloading callback. */
429 int alpm_option_set_fetchcb(alpm_handle_t *handle, alpm_cb_fetch cb);
431 /** Returns the callback used to report total download size. */
432 alpm_cb_totaldl alpm_option_get_totaldlcb(alpm_handle_t *handle);
433 /** Sets the callback used to report total download size. */
434 int alpm_option_set_totaldlcb(alpm_handle_t *handle, alpm_cb_totaldl cb);
436 /** Returns the callback used for events. */
437 alpm_cb_event alpm_option_get_eventcb(alpm_handle_t *handle);
438 /** Sets the callback used for events. */
439 int alpm_option_set_eventcb(alpm_handle_t *handle, alpm_cb_event cb);
441 /** Returns the callback used for questions. */
442 alpm_cb_question alpm_option_get_questioncb(alpm_handle_t *handle);
443 /** Sets the callback used for questions. */
444 int alpm_option_set_questioncb(alpm_handle_t *handle, alpm_cb_question cb);
446 /** Returns the callback used for operation progress. */
447 alpm_cb_progress alpm_option_get_progresscb(alpm_handle_t *handle);
448 /** Sets the callback used for operation progress. */
449 int alpm_option_set_progresscb(alpm_handle_t *handle, alpm_cb_progress cb);
451 /** Returns the root of the destination filesystem. Read-only. */
452 const char *alpm_option_get_root(alpm_handle_t *handle);
454 /** Returns the path to the database directory. Read-only. */
455 const char *alpm_option_get_dbpath(alpm_handle_t *handle);
457 /** Get the name of the database lock file. Read-only. */
458 const char *alpm_option_get_lockfile(alpm_handle_t *handle);
460 /** @name Accessors to the list of package cache directories.
461 * @{
463 alpm_list_t *alpm_option_get_cachedirs(alpm_handle_t *handle);
464 int alpm_option_set_cachedirs(alpm_handle_t *handle, alpm_list_t *cachedirs);
465 int alpm_option_add_cachedir(alpm_handle_t *handle, const char *cachedir);
466 int alpm_option_remove_cachedir(alpm_handle_t *handle, const char *cachedir);
467 /** @} */
469 /** Returns the logfile name. */
470 const char *alpm_option_get_logfile(alpm_handle_t *handle);
471 /** Sets the logfile name. */
472 int alpm_option_set_logfile(alpm_handle_t *handle, const char *logfile);
474 /** Returns the path to libalpm's GnuPG home directory. */
475 const char *alpm_option_get_gpgdir(alpm_handle_t *handle);
476 /** Sets the path to libalpm's GnuPG home directory. */
477 int alpm_option_set_gpgdir(alpm_handle_t *handle, const char *gpgdir);
479 /** Returns whether to use syslog (0 is FALSE, TRUE otherwise). */
480 int alpm_option_get_usesyslog(alpm_handle_t *handle);
481 /** Sets whether to use syslog (0 is FALSE, TRUE otherwise). */
482 int alpm_option_set_usesyslog(alpm_handle_t *handle, int usesyslog);
484 /** @name Accessors to the list of no-upgrade files.
485 * These functions modify the list of files which should
486 * not be updated by package installation.
487 * @{
489 alpm_list_t *alpm_option_get_noupgrades(alpm_handle_t *handle);
490 int alpm_option_add_noupgrade(alpm_handle_t *handle, const char *pkg);
491 int alpm_option_set_noupgrades(alpm_handle_t *handle, alpm_list_t *noupgrade);
492 int alpm_option_remove_noupgrade(alpm_handle_t *handle, const char *pkg);
493 /** @} */
495 /** @name Accessors to the list of no-extract files.
496 * These functions modify the list of filenames which should
497 * be skipped packages which should
498 * not be upgraded by a sysupgrade operation.
499 * @{
501 alpm_list_t *alpm_option_get_noextracts(alpm_handle_t *handle);
502 int alpm_option_add_noextract(alpm_handle_t *handle, const char *pkg);
503 int alpm_option_set_noextracts(alpm_handle_t *handle, alpm_list_t *noextract);
504 int alpm_option_remove_noextract(alpm_handle_t *handle, const char *pkg);
505 /** @} */
507 /** @name Accessors to the list of ignored packages.
508 * These functions modify the list of packages that
509 * should be ignored by a sysupgrade.
510 * @{
512 alpm_list_t *alpm_option_get_ignorepkgs(alpm_handle_t *handle);
513 int alpm_option_add_ignorepkg(alpm_handle_t *handle, const char *pkg);
514 int alpm_option_set_ignorepkgs(alpm_handle_t *handle, alpm_list_t *ignorepkgs);
515 int alpm_option_remove_ignorepkg(alpm_handle_t *handle, const char *pkg);
516 /** @} */
518 /** @name Accessors to the list of ignored groups.
519 * These functions modify the list of groups whose packages
520 * should be ignored by a sysupgrade.
521 * @{
523 alpm_list_t *alpm_option_get_ignoregroups(alpm_handle_t *handle);
524 int alpm_option_add_ignoregroup(alpm_handle_t *handle, const char *grp);
525 int alpm_option_set_ignoregroups(alpm_handle_t *handle, alpm_list_t *ignoregrps);
526 int alpm_option_remove_ignoregroup(alpm_handle_t *handle, const char *grp);
527 /** @} */
529 /** Returns the targeted architecture. */
530 const char *alpm_option_get_arch(alpm_handle_t *handle);
531 /** Sets the targeted architecture. */
532 int alpm_option_set_arch(alpm_handle_t *handle, const char *arch);
534 double alpm_option_get_deltaratio(alpm_handle_t *handle);
535 int alpm_option_set_deltaratio(alpm_handle_t *handle, double ratio);
537 int alpm_option_get_checkspace(alpm_handle_t *handle);
538 int alpm_option_set_checkspace(alpm_handle_t *handle, int checkspace);
540 alpm_siglevel_t alpm_option_get_default_siglevel(alpm_handle_t *handle);
541 int alpm_option_set_default_siglevel(alpm_handle_t *handle, alpm_siglevel_t level);
543 /** @} */
545 /** @addtogroup alpm_api_databases Database Functions
546 * Functions to query and manipulate the database of libalpm.
547 * @{
550 /** Get the database of locally installed packages.
551 * The returned pointer points to an internal structure
552 * of libalpm which should only be manipulated through
553 * libalpm functions.
554 * @return a reference to the local database
556 alpm_db_t *alpm_get_localdb(alpm_handle_t *handle);
558 /** Get the list of sync databases.
559 * Returns a list of alpm_db_t structures, one for each registered
560 * sync database.
561 * @param handle the context handle
562 * @return a reference to an internal list of alpm_db_t structures
564 alpm_list_t *alpm_get_syncdbs(alpm_handle_t *handle);
566 /** Register a sync database of packages.
567 * @param handle the context handle
568 * @param treename the name of the sync repository
569 * @param level what level of signature checking to perform on the
570 * database; note that this must be a '.sig' file type verification
571 * @return an alpm_db_t* on success (the value), NULL on error
573 alpm_db_t *alpm_register_syncdb(alpm_handle_t *handle, const char *treename,
574 alpm_siglevel_t level);
576 /** Unregister all package databases.
577 * @param handle the context handle
578 * @return 0 on success, -1 on error (pm_errno is set accordingly)
580 int alpm_unregister_all_syncdbs(alpm_handle_t *handle);
582 /** Unregister a package database.
583 * @param db pointer to the package database to unregister
584 * @return 0 on success, -1 on error (pm_errno is set accordingly)
586 int alpm_db_unregister(alpm_db_t *db);
588 /** Get the name of a package database.
589 * @param db pointer to the package database
590 * @return the name of the package database, NULL on error
592 const char *alpm_db_get_name(const alpm_db_t *db);
594 /** Get the signature verification level for a database.
595 * Will return the default verification level if this database is set up
596 * with ALPM_SIG_USE_DEFAULT.
597 * @param db pointer to the package database
598 * @return the signature verification level
600 alpm_siglevel_t alpm_db_get_siglevel(alpm_db_t *db);
602 /** Check the validity of a database.
603 * This is most useful for sync databases and verifying signature status.
604 * If invalid, the handle error code will be set accordingly.
605 * @param db pointer to the package database
606 * @return 0 if valid, -1 if invalid (pm_errno is set accordingly)
608 int alpm_db_get_valid(alpm_db_t *db);
610 /** @name Accessors to the list of servers for a database.
611 * @{
613 alpm_list_t *alpm_db_get_servers(const alpm_db_t *db);
614 int alpm_db_set_servers(alpm_db_t *db, alpm_list_t *servers);
615 int alpm_db_add_server(alpm_db_t *db, const char *url);
616 int alpm_db_remove_server(alpm_db_t *db, const char *url);
617 /** @} */
619 int alpm_db_update(int level, alpm_db_t *db);
621 /** Get a package entry from a package database.
622 * @param db pointer to the package database to get the package from
623 * @param name of the package
624 * @return the package entry on success, NULL on error
626 alpm_pkg_t *alpm_db_get_pkg(alpm_db_t *db, const char *name);
628 /** Get the package cache of a package database.
629 * @param db pointer to the package database to get the package from
630 * @return the list of packages on success, NULL on error
632 alpm_list_t *alpm_db_get_pkgcache(alpm_db_t *db);
634 /** Get a group entry from a package database.
635 * @param db pointer to the package database to get the group from
636 * @param name of the group
637 * @return the groups entry on success, NULL on error
639 alpm_group_t *alpm_db_get_group(alpm_db_t *db, const char *name);
641 /** Get the group cache of a package database.
642 * @param db pointer to the package database to get the group from
643 * @return the list of groups on success, NULL on error
645 alpm_list_t *alpm_db_get_groupcache(alpm_db_t *db);
647 /** Searches a database with regular expressions.
648 * @param db pointer to the package database to search in
649 * @param needles a list of regular expressions to search for
650 * @return the list of packages matching all regular expressions on success, NULL on error
652 alpm_list_t *alpm_db_search(alpm_db_t *db, const alpm_list_t *needles);
654 /** @} */
656 /** @addtogroup alpm_api_packages Package Functions
657 * Functions to manipulate libalpm packages
658 * @{
661 /** Create a package from a file.
662 * If full is false, the archive is read only until all necessary
663 * metadata is found. If it is true, the entire archive is read, which
664 * serves as a verification of integrity and the filelist can be created.
665 * The allocated structure should be freed using alpm_pkg_free().
666 * @param handle the context handle
667 * @param filename location of the package tarball
668 * @param full whether to stop the load after metadata is read or continue
669 * through the full archive
670 * @param level what level of package signature checking to perform on the
671 * package; note that this must be a '.sig' file type verification
672 * @param pkg address of the package pointer
673 * @return 0 on success, -1 on error (pm_errno is set accordingly)
675 int alpm_pkg_load(alpm_handle_t *handle, const char *filename, int full,
676 alpm_siglevel_t level, alpm_pkg_t **pkg);
678 /** Free a package.
679 * @param pkg package pointer to free
680 * @return 0 on success, -1 on error (pm_errno is set accordingly)
682 int alpm_pkg_free(alpm_pkg_t *pkg);
684 /** Check the integrity (with md5) of a package from the sync cache.
685 * @param pkg package pointer
686 * @return 0 on success, -1 on error (pm_errno is set accordingly)
688 int alpm_pkg_checkmd5sum(alpm_pkg_t *pkg);
690 /** Compare two version strings and determine which one is 'newer'. */
691 int alpm_pkg_vercmp(const char *a, const char *b);
693 /** Computes the list of packages requiring a given package.
694 * The return value of this function is a newly allocated
695 * list of package names (char*), it should be freed by the caller.
696 * @param pkg a package
697 * @return the list of packages requiring pkg
699 alpm_list_t *alpm_pkg_compute_requiredby(alpm_pkg_t *pkg);
701 /** @name Package Property Accessors
702 * Any pointer returned by these functions points to internal structures
703 * allocated by libalpm. They should not be freed nor modified in any
704 * way.
705 * @{
708 /** Gets the name of the file from which the package was loaded.
709 * @param pkg a pointer to package
710 * @return a reference to an internal string
712 const char *alpm_pkg_get_filename(alpm_pkg_t *pkg);
714 /** Returns the package name.
715 * @param pkg a pointer to package
716 * @return a reference to an internal string
718 const char *alpm_pkg_get_name(alpm_pkg_t *pkg);
720 /** Returns the package version as a string.
721 * This includes all available epoch, version, and pkgrel components. Use
722 * alpm_pkg_vercmp() to compare version strings if necessary.
723 * @param pkg a pointer to package
724 * @return a reference to an internal string
726 const char *alpm_pkg_get_version(alpm_pkg_t *pkg);
728 /** Returns the origin of the package.
729 * @return an alpm_pkgfrom_t constant, -1 on error
731 alpm_pkgfrom_t alpm_pkg_get_origin(alpm_pkg_t *pkg);
733 /** Returns the package description.
734 * @param pkg a pointer to package
735 * @return a reference to an internal string
737 const char *alpm_pkg_get_desc(alpm_pkg_t *pkg);
739 /** Returns the package URL.
740 * @param pkg a pointer to package
741 * @return a reference to an internal string
743 const char *alpm_pkg_get_url(alpm_pkg_t *pkg);
745 /** Returns the build timestamp of the package.
746 * @param pkg a pointer to package
747 * @return the timestamp of the build time
749 alpm_time_t alpm_pkg_get_builddate(alpm_pkg_t *pkg);
751 /** Returns the install timestamp of the package.
752 * @param pkg a pointer to package
753 * @return the timestamp of the install time
755 alpm_time_t alpm_pkg_get_installdate(alpm_pkg_t *pkg);
757 /** Returns the packager's name.
758 * @param pkg a pointer to package
759 * @return a reference to an internal string
761 const char *alpm_pkg_get_packager(alpm_pkg_t *pkg);
763 /** Returns the package's MD5 checksum as a string.
764 * The returned string is a sequence of 32 lowercase hexadecimal digits.
765 * @param pkg a pointer to package
766 * @return a reference to an internal string
768 const char *alpm_pkg_get_md5sum(alpm_pkg_t *pkg);
770 /** Returns the package's SHA256 checksum as a string.
771 * The returned string is a sequence of 64 lowercase hexadecimal digits.
772 * @param pkg a pointer to package
773 * @return a reference to an internal string
775 const char *alpm_pkg_get_sha256sum(alpm_pkg_t *pkg);
777 /** Returns the architecture for which the package was built.
778 * @param pkg a pointer to package
779 * @return a reference to an internal string
781 const char *alpm_pkg_get_arch(alpm_pkg_t *pkg);
783 /** Returns the size of the package. This is only available for sync database
784 * packages and package files, not those loaded from the local database.
785 * @param pkg a pointer to package
786 * @return the size of the package in bytes.
788 off_t alpm_pkg_get_size(alpm_pkg_t *pkg);
790 /** Returns the installed size of the package.
791 * @param pkg a pointer to package
792 * @return the total size of files installed by the package.
794 off_t alpm_pkg_get_isize(alpm_pkg_t *pkg);
796 /** Returns the package installation reason.
797 * @param pkg a pointer to package
798 * @return an enum member giving the install reason.
800 alpm_pkgreason_t alpm_pkg_get_reason(alpm_pkg_t *pkg);
802 /** Returns the list of package licenses.
803 * @param pkg a pointer to package
804 * @return a pointer to an internal list of strings.
806 alpm_list_t *alpm_pkg_get_licenses(alpm_pkg_t *pkg);
808 /** Returns the list of package groups.
809 * @param pkg a pointer to package
810 * @return a pointer to an internal list of strings.
812 alpm_list_t *alpm_pkg_get_groups(alpm_pkg_t *pkg);
814 /** Returns the list of package dependencies as alpm_depend_t.
815 * @param pkg a pointer to package
816 * @return a reference to an internal list of alpm_depend_t structures.
818 alpm_list_t *alpm_pkg_get_depends(alpm_pkg_t *pkg);
820 /** Returns the list of package optional dependencies.
821 * @param pkg a pointer to package
822 * @return a reference to an internal list of strings.
824 alpm_list_t *alpm_pkg_get_optdepends(alpm_pkg_t *pkg);
826 /** Returns the list of packages conflicting with pkg.
827 * @param pkg a pointer to package
828 * @return a reference to an internal list of alpm_depend_t structures.
830 alpm_list_t *alpm_pkg_get_conflicts(alpm_pkg_t *pkg);
832 /** Returns the list of packages provided by pkg.
833 * @param pkg a pointer to package
834 * @return a reference to an internal list of alpm_depend_t structures.
836 alpm_list_t *alpm_pkg_get_provides(alpm_pkg_t *pkg);
838 /** Returns the list of available deltas for pkg.
839 * @param pkg a pointer to package
840 * @return a reference to an internal list of strings.
842 alpm_list_t *alpm_pkg_get_deltas(alpm_pkg_t *pkg);
844 /** Returns the list of packages to be replaced by pkg.
845 * @param pkg a pointer to package
846 * @return a reference to an internal list of alpm_depend_t structures.
848 alpm_list_t *alpm_pkg_get_replaces(alpm_pkg_t *pkg);
850 /** Returns the list of files installed by pkg.
851 * The filenames are relative to the install root,
852 * and do not include leading slashes.
853 * @param pkg a pointer to package
854 * @return a pointer to a filelist object containing a count and an array of
855 * package file objects
857 alpm_filelist_t *alpm_pkg_get_files(alpm_pkg_t *pkg);
859 /** Returns the list of files backed up when installing pkg.
860 * The elements of the returned list have the form
861 * "<filename>\t<md5sum>", where the given md5sum is that of
862 * the file as provided by the package.
863 * @param pkg a pointer to package
864 * @return a reference to an internal list of strings.
866 alpm_list_t *alpm_pkg_get_backup(alpm_pkg_t *pkg);
868 /** Returns the database containing pkg.
869 * Returns a pointer to the alpm_db_t structure the package is
870 * originating from, or NULL if the package was loaded from a file.
871 * @param pkg a pointer to package
872 * @return a pointer to the DB containing pkg, or NULL.
874 alpm_db_t *alpm_pkg_get_db(alpm_pkg_t *pkg);
876 /** Retuns the base64 encoded package signature.
877 * @param pkg a pointer to package
878 * @return a reference to an internal string
880 const char *alpm_pkg_get_base64_sig(alpm_pkg_t *pkg);
882 /* End of alpm_pkg_t accessors */
883 /* @} */
885 /** Open a package changelog for reading.
886 * Similar to fopen in functionality, except that the returned 'file
887 * stream' could really be from an archive as well as from the database.
888 * @param pkg the package to read the changelog of (either file or db)
889 * @return a 'file stream' to the package changelog
891 void *alpm_pkg_changelog_open(alpm_pkg_t *pkg);
893 /** Read data from an open changelog 'file stream'.
894 * Similar to fread in functionality, this function takes a buffer and
895 * amount of data to read. If an error occurs pm_errno will be set.
896 * @param ptr a buffer to fill with raw changelog data
897 * @param size the size of the buffer
898 * @param pkg the package that the changelog is being read from
899 * @param fp a 'file stream' to the package changelog
900 * @return the number of characters read, or 0 if there is no more data or an
901 * error occurred.
903 size_t alpm_pkg_changelog_read(void *ptr, size_t size,
904 const alpm_pkg_t *pkg, void *fp);
906 int alpm_pkg_changelog_close(const alpm_pkg_t *pkg, void *fp);
908 /** Returns whether the package has an install scriptlet.
909 * @return 0 if FALSE, TRUE otherwise
911 int alpm_pkg_has_scriptlet(alpm_pkg_t *pkg);
913 /** Returns the size of download.
914 * Returns the size of the files that will be downloaded to install a
915 * package.
916 * @param newpkg the new package to upgrade to
917 * @return the size of the download
919 off_t alpm_pkg_download_size(alpm_pkg_t *newpkg);
921 alpm_list_t *alpm_pkg_unused_deltas(alpm_pkg_t *pkg);
923 /** Set install reason for a package in the local database.
924 * The provided package object must be from the local database or this method
925 * will fail. The write to the local database is performed immediately.
926 * @param pkg the package to update
927 * @param reason the new install reason
928 * @return 0 on success, -1 on error (pm_errno is set accordingly)
930 int alpm_pkg_set_reason(alpm_pkg_t *pkg, alpm_pkgreason_t reason);
933 /* End of alpm_pkg */
934 /** @} */
937 * Signatures
940 int alpm_pkg_check_pgp_signature(alpm_pkg_t *pkg, alpm_siglist_t *siglist);
942 int alpm_db_check_pgp_signature(alpm_db_t *db, alpm_siglist_t *siglist);
944 int alpm_siglist_cleanup(alpm_siglist_t *siglist);
947 * Groups
950 alpm_list_t *alpm_find_group_pkgs(alpm_list_t *dbs, const char *name);
953 * Sync
956 alpm_pkg_t *alpm_sync_newversion(alpm_pkg_t *pkg, alpm_list_t *dbs_sync);
958 /** @addtogroup alpm_api_trans Transaction Functions
959 * Functions to manipulate libalpm transactions
960 * @{
963 /** Transaction flags */
964 typedef enum _alpm_transflag_t {
965 /** Ignore dependency checks. */
966 ALPM_TRANS_FLAG_NODEPS = 1,
967 /** Ignore file conflicts and overwrite files. */
968 ALPM_TRANS_FLAG_FORCE = (1 << 1),
969 /** Delete files even if they are tagged as backup. */
970 ALPM_TRANS_FLAG_NOSAVE = (1 << 2),
971 /** Ignore version numbers when checking dependencies. */
972 ALPM_TRANS_FLAG_NODEPVERSION = (1 << 3),
973 /** Remove also any packages depending on a package being removed. */
974 ALPM_TRANS_FLAG_CASCADE = (1 << 4),
975 /** Remove packages and their unneeded deps (not explicitly installed). */
976 ALPM_TRANS_FLAG_RECURSE = (1 << 5),
977 /** Modify database but do not commit changes to the filesystem. */
978 ALPM_TRANS_FLAG_DBONLY = (1 << 6),
979 /* (1 << 7) flag can go here */
980 /** Use ALPM_PKG_REASON_DEPEND when installing packages. */
981 ALPM_TRANS_FLAG_ALLDEPS = (1 << 8),
982 /** Only download packages and do not actually install. */
983 ALPM_TRANS_FLAG_DOWNLOADONLY = (1 << 9),
984 /** Do not execute install scriptlets after installing. */
985 ALPM_TRANS_FLAG_NOSCRIPTLET = (1 << 10),
986 /** Ignore dependency conflicts. */
987 ALPM_TRANS_FLAG_NOCONFLICTS = (1 << 11),
988 /* (1 << 12) flag can go here */
989 /** Do not install a package if it is already installed and up to date. */
990 ALPM_TRANS_FLAG_NEEDED = (1 << 13),
991 /** Use ALPM_PKG_REASON_EXPLICIT when installing packages. */
992 ALPM_TRANS_FLAG_ALLEXPLICIT = (1 << 14),
993 /** Do not remove a package if it is needed by another one. */
994 ALPM_TRANS_FLAG_UNNEEDED = (1 << 15),
995 /** Remove also explicitly installed unneeded deps (use with ALPM_TRANS_FLAG_RECURSE). */
996 ALPM_TRANS_FLAG_RECURSEALL = (1 << 16),
997 /** Do not lock the database during the operation. */
998 ALPM_TRANS_FLAG_NOLOCK = (1 << 17)
999 } alpm_transflag_t;
1001 /** Returns the bitfield of flags for the current transaction.
1002 * @param handle the context handle
1003 * @return the bitfield of transaction flags
1005 alpm_transflag_t alpm_trans_get_flags(alpm_handle_t *handle);
1007 /** Returns a list of packages added by the transaction.
1008 * @param handle the context handle
1009 * @return a list of alpm_pkg_t structures
1011 alpm_list_t *alpm_trans_get_add(alpm_handle_t *handle);
1013 /** Returns the list of packages removed by the transaction.
1014 * @param handle the context handle
1015 * @return a list of alpm_pkg_t structures
1017 alpm_list_t *alpm_trans_get_remove(alpm_handle_t *handle);
1019 /** Initialize the transaction.
1020 * @param handle the context handle
1021 * @param flags flags of the transaction (like nodeps, etc)
1022 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1024 int alpm_trans_init(alpm_handle_t *handle, alpm_transflag_t flags);
1026 /** Prepare a transaction.
1027 * @param handle the context handle
1028 * @param data the address of an alpm_list where a list
1029 * of alpm_depmissing_t objects is dumped (conflicting packages)
1030 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1032 int alpm_trans_prepare(alpm_handle_t *handle, alpm_list_t **data);
1034 /** Commit a transaction.
1035 * @param handle the context handle
1036 * @param data the address of an alpm_list where detailed description
1037 * of an error can be dumped (ie. list of conflicting files)
1038 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1040 int alpm_trans_commit(alpm_handle_t *handle, alpm_list_t **data);
1042 /** Interrupt a transaction.
1043 * @param handle the context handle
1044 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1046 int alpm_trans_interrupt(alpm_handle_t *handle);
1048 /** Release a transaction.
1049 * @param handle the context handle
1050 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1052 int alpm_trans_release(alpm_handle_t *handle);
1053 /** @} */
1055 /** @name Common Transactions */
1056 /** @{ */
1058 /** Search for packages to upgrade and add them to the transaction.
1059 * @param handle the context handle
1060 * @param enable_downgrade allow downgrading of packages if the remote version is lower
1061 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1063 int alpm_sync_sysupgrade(alpm_handle_t *handle, int enable_downgrade);
1065 /** Add a package to the transaction.
1066 * If the package was loaded by alpm_pkg_load(), it will be freed upon
1067 * alpm_trans_release() invocation.
1068 * @param handle the context handle
1069 * @param pkg the package to add
1070 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1072 int alpm_add_pkg(alpm_handle_t *handle, alpm_pkg_t *pkg);
1074 /** Add a package removal action to the transaction.
1075 * @param handle the context handle
1076 * @param pkg the package to uninstall
1077 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1079 int alpm_remove_pkg(alpm_handle_t *handle, alpm_pkg_t *pkg);
1081 /** @} */
1083 /** @addtogroup alpm_api_depends Dependency Functions
1084 * Functions dealing with libalpm representation of dependency
1085 * information.
1086 * @{
1089 alpm_list_t *alpm_checkdeps(alpm_handle_t *handle, alpm_list_t *pkglist,
1090 alpm_list_t *remove, alpm_list_t *upgrade, int reversedeps);
1091 alpm_pkg_t *alpm_find_satisfier(alpm_list_t *pkgs, const char *depstring);
1092 alpm_pkg_t *alpm_find_dbs_satisfier(alpm_handle_t *handle,
1093 alpm_list_t *dbs, const char *depstring);
1095 alpm_list_t *alpm_checkconflicts(alpm_handle_t *handle, alpm_list_t *pkglist);
1097 /** Returns a newly allocated string representing the dependency information.
1098 * @param dep a dependency info structure
1099 * @return a formatted string, e.g. "glibc>=2.12"
1101 char *alpm_dep_compute_string(const alpm_depend_t *dep);
1103 /** @} */
1105 /** @} */
1108 * Helpers
1111 /* checksums */
1112 char *alpm_compute_md5sum(const char *filename);
1113 char *alpm_compute_sha256sum(const char *filename);
1115 /** @addtogroup alpm_api_errors Error Codes
1116 * @{
1118 typedef enum _alpm_errno_t {
1119 ALPM_ERR_MEMORY = 1,
1120 ALPM_ERR_SYSTEM,
1121 ALPM_ERR_BADPERMS,
1122 ALPM_ERR_NOT_A_FILE,
1123 ALPM_ERR_NOT_A_DIR,
1124 ALPM_ERR_WRONG_ARGS,
1125 ALPM_ERR_DISK_SPACE,
1126 /* Interface */
1127 ALPM_ERR_HANDLE_NULL,
1128 ALPM_ERR_HANDLE_NOT_NULL,
1129 ALPM_ERR_HANDLE_LOCK,
1130 /* Databases */
1131 ALPM_ERR_DB_OPEN,
1132 ALPM_ERR_DB_CREATE,
1133 ALPM_ERR_DB_NULL,
1134 ALPM_ERR_DB_NOT_NULL,
1135 ALPM_ERR_DB_NOT_FOUND,
1136 ALPM_ERR_DB_INVALID,
1137 ALPM_ERR_DB_INVALID_SIG,
1138 ALPM_ERR_DB_VERSION,
1139 ALPM_ERR_DB_WRITE,
1140 ALPM_ERR_DB_REMOVE,
1141 /* Servers */
1142 ALPM_ERR_SERVER_BAD_URL,
1143 ALPM_ERR_SERVER_NONE,
1144 /* Transactions */
1145 ALPM_ERR_TRANS_NOT_NULL,
1146 ALPM_ERR_TRANS_NULL,
1147 ALPM_ERR_TRANS_DUP_TARGET,
1148 ALPM_ERR_TRANS_NOT_INITIALIZED,
1149 ALPM_ERR_TRANS_NOT_PREPARED,
1150 ALPM_ERR_TRANS_ABORT,
1151 ALPM_ERR_TRANS_TYPE,
1152 ALPM_ERR_TRANS_NOT_LOCKED,
1153 /* Packages */
1154 ALPM_ERR_PKG_NOT_FOUND,
1155 ALPM_ERR_PKG_IGNORED,
1156 ALPM_ERR_PKG_INVALID,
1157 ALPM_ERR_PKG_INVALID_CHECKSUM,
1158 ALPM_ERR_PKG_INVALID_SIG,
1159 ALPM_ERR_PKG_OPEN,
1160 ALPM_ERR_PKG_CANT_REMOVE,
1161 ALPM_ERR_PKG_INVALID_NAME,
1162 ALPM_ERR_PKG_INVALID_ARCH,
1163 ALPM_ERR_PKG_REPO_NOT_FOUND,
1164 /* Signatures */
1165 ALPM_ERR_SIG_MISSING,
1166 ALPM_ERR_SIG_INVALID,
1167 /* Deltas */
1168 ALPM_ERR_DLT_INVALID,
1169 ALPM_ERR_DLT_PATCHFAILED,
1170 /* Dependencies */
1171 ALPM_ERR_UNSATISFIED_DEPS,
1172 ALPM_ERR_CONFLICTING_DEPS,
1173 ALPM_ERR_FILE_CONFLICTS,
1174 /* Misc */
1175 ALPM_ERR_RETRIEVE,
1176 ALPM_ERR_INVALID_REGEX,
1177 /* External library errors */
1178 ALPM_ERR_LIBARCHIVE,
1179 ALPM_ERR_LIBCURL,
1180 ALPM_ERR_EXTERNAL_DOWNLOAD,
1181 ALPM_ERR_GPGME
1182 } alpm_errno_t;
1184 /** Returns the current error code from the handle. */
1185 alpm_errno_t alpm_errno(alpm_handle_t *handle);
1187 /** Returns the string corresponding to an error number. */
1188 const char *alpm_strerror(alpm_errno_t err);
1190 /* End of alpm_api_errors */
1191 /** @} */
1193 alpm_handle_t *alpm_initialize(const char *root, const char *dbpath,
1194 alpm_errno_t *err);
1195 int alpm_release(alpm_handle_t *handle);
1197 enum alpm_caps {
1198 ALPM_CAPABILITY_NLS = (1 << 0),
1199 ALPM_CAPABILITY_DOWNLOADER = (1 << 1),
1200 ALPM_CAPABILITY_SIGNATURES = (1 << 2)
1203 const char *alpm_version(void);
1204 enum alpm_caps alpm_capabilities(void);
1206 /* End of alpm_api */
1207 /** @} */
1209 #ifdef __cplusplus
1211 #endif
1212 #endif /* _ALPM_H */
1214 /* vim: set ts=2 sw=2 noet: */