4 * Copyright (c) 2006-2012 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/>.
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
45 typedef int64_t alpm_time_t
;
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
60 /** Location a package object was loaded from. */
61 typedef enum _alpm_pkgfrom_t
{
67 /** Types of version constraints in dependency specs. */
68 typedef enum _alpm_depmod_t
{
69 /** No version constraint */
71 /** Test version equality (package=x.y.z) */
73 /** Test for at least a version (package>=x.y.z) */
75 /** Test for at most a version (package<=x.y.z) */
77 /** Test for greater than some version (package>x.y.z) */
79 /** Test for less than some version (package<x.y.z) */
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)
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
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
;
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
;
136 typedef struct _alpm_depend_t
{
140 unsigned long name_hash
;
144 /** Missing dependency */
145 typedef struct _alpm_depmissing_t
{
147 alpm_depend_t
*depend
;
148 /* this is used only in the case of a remove dependency error */
153 typedef struct _alpm_conflict_t
{
154 unsigned long package1_hash
;
155 unsigned long package2_hash
;
158 alpm_depend_t
*reason
;
162 typedef struct _alpm_fileconflict_t
{
164 alpm_fileconflicttype_t type
;
167 } alpm_fileconflict_t
;
170 typedef struct _alpm_group_t
{
173 /** list of alpm_pkg_t packages */
174 alpm_list_t
*packages
;
177 /** Package upgrade delta */
178 typedef struct _alpm_delta_t
{
179 /** filename of the delta patch */
181 /** md5sum of the delta file */
183 /** filename of the 'before' file */
185 /** filename of the 'after' file */
187 /** filesize of the delta file */
189 /** download filesize of the delta file */
193 /** File in a package */
194 typedef struct _alpm_file_t
{
200 /** Package filelist container */
201 typedef struct _alpm_filelist_t
{
206 /** Local package or package file backup entry */
207 typedef struct _alpm_backup_t
{
212 typedef struct _alpm_pgpkey_t
{
221 unsigned int revoked
;
226 * Signature result. Contains the key, status, and validity of a given
229 typedef struct _alpm_sigresult_t
{
231 alpm_sigstatus_t status
;
232 alpm_sigvalidity_t validity
;
236 * Signature list. Contains the number of signatures found and a pointer to an
237 * array of results. The array is of size count.
239 typedef struct _alpm_siglist_t
{
241 alpm_sigresult_t
*results
;
248 /** Logging Levels */
249 typedef enum _alpm_loglevel_t
{
251 ALPM_LOG_WARNING
= (1 << 1),
252 ALPM_LOG_DEBUG
= (1 << 2),
253 ALPM_LOG_FUNCTION
= (1 << 3)
256 typedef void (*alpm_cb_log
)(alpm_loglevel_t
, const char *, va_list);
257 int alpm_logaction(alpm_handle_t
*handle
, const char *fmt
, ...);
261 * NULL parameters are passed to in all events unless specified otherwise.
263 typedef enum _alpm_event_t
{
264 /** Dependencies will be computed for a package. */
265 ALPM_EVENT_CHECKDEPS_START
= 1,
266 /** Dependencies were computed for a package. */
267 ALPM_EVENT_CHECKDEPS_DONE
,
268 /** File conflicts will be computed for a package. */
269 ALPM_EVENT_FILECONFLICTS_START
,
270 /** File conflicts were computed for a package. */
271 ALPM_EVENT_FILECONFLICTS_DONE
,
272 /** Dependencies will be resolved for target package. */
273 ALPM_EVENT_RESOLVEDEPS_START
,
274 /** Dependencies were resolved for target package. */
275 ALPM_EVENT_RESOLVEDEPS_DONE
,
276 /** Inter-conflicts will be checked for target package. */
277 ALPM_EVENT_INTERCONFLICTS_START
,
278 /** Inter-conflicts were checked for target package. */
279 ALPM_EVENT_INTERCONFLICTS_DONE
,
280 /** Package will be installed.
281 * A pointer to the target package is passed to the callback.
283 ALPM_EVENT_ADD_START
,
284 /** Package was installed.
285 * A pointer to the new package is passed to the callback.
288 /** Package will be removed.
289 * A pointer to the target package is passed to the callback.
291 ALPM_EVENT_REMOVE_START
,
292 /** Package was removed.
293 * A pointer to the removed package is passed to the callback.
295 ALPM_EVENT_REMOVE_DONE
,
296 /** Package will be upgraded.
297 * A pointer to the upgraded package is passed to the callback.
299 ALPM_EVENT_UPGRADE_START
,
300 /** Package was upgraded.
301 * A pointer to the new package, and a pointer to the old package is passed
302 * to the callback, respectively.
304 ALPM_EVENT_UPGRADE_DONE
,
305 /** Target package's integrity will be checked. */
306 ALPM_EVENT_INTEGRITY_START
,
307 /** Target package's integrity was checked. */
308 ALPM_EVENT_INTEGRITY_DONE
,
309 /** Target package will be loaded. */
310 ALPM_EVENT_LOAD_START
,
311 /** Target package is finished loading. */
312 ALPM_EVENT_LOAD_DONE
,
313 /** Target delta's integrity will be checked. */
314 ALPM_EVENT_DELTA_INTEGRITY_START
,
315 /** Target delta's integrity was checked. */
316 ALPM_EVENT_DELTA_INTEGRITY_DONE
,
317 /** Deltas will be applied to packages. */
318 ALPM_EVENT_DELTA_PATCHES_START
,
319 /** Deltas were applied to packages. */
320 ALPM_EVENT_DELTA_PATCHES_DONE
,
321 /** Delta patch will be applied to target package.
322 * The filename of the package and the filename of the patch is passed to the
325 ALPM_EVENT_DELTA_PATCH_START
,
326 /** Delta patch was applied to target package. */
327 ALPM_EVENT_DELTA_PATCH_DONE
,
328 /** Delta patch failed to apply to target package. */
329 ALPM_EVENT_DELTA_PATCH_FAILED
,
330 /** Scriptlet has printed information.
331 * A line of text is passed to the callback.
333 ALPM_EVENT_SCRIPTLET_INFO
,
334 /** Files will be downloaded from a repository.
335 * The repository's tree name is passed to the callback.
337 ALPM_EVENT_RETRIEVE_START
,
338 /** Disk space usage will be computed for a package */
339 ALPM_EVENT_DISKSPACE_START
,
340 /** Disk space usage was computed for a package */
341 ALPM_EVENT_DISKSPACE_DONE
344 /** Event callback */
345 typedef void (*alpm_cb_event
)(alpm_event_t
, void *, void *);
349 * Unlike the events or progress enumerations, this enum has bitmask values
350 * so a frontend can use a bitmask map to supply preselected answers to the
351 * different types of questions.
353 typedef enum _alpm_question_t
{
354 ALPM_QUESTION_INSTALL_IGNOREPKG
= 1,
355 ALPM_QUESTION_REPLACE_PKG
= (1 << 1),
356 ALPM_QUESTION_CONFLICT_PKG
= (1 << 2),
357 ALPM_QUESTION_CORRUPTED_PKG
= (1 << 3),
358 ALPM_QUESTION_LOCAL_NEWER
= (1 << 4),
359 ALPM_QUESTION_REMOVE_PKGS
= (1 << 5),
360 ALPM_QUESTION_SELECT_PROVIDER
= (1 << 6),
361 ALPM_QUESTION_IMPORT_KEY
= (1 << 7)
364 /** Question callback */
365 typedef void (*alpm_cb_question
)(alpm_question_t
, void *, void *, void *, int *);
368 typedef enum _alpm_progress_t
{
369 ALPM_PROGRESS_ADD_START
,
370 ALPM_PROGRESS_UPGRADE_START
,
371 ALPM_PROGRESS_REMOVE_START
,
372 ALPM_PROGRESS_CONFLICTS_START
,
373 ALPM_PROGRESS_DISKSPACE_START
,
374 ALPM_PROGRESS_INTEGRITY_START
,
375 ALPM_PROGRESS_LOAD_START
378 /** Progress callback */
379 typedef void (*alpm_cb_progress
)(alpm_progress_t
, const char *, int, size_t, size_t);
385 /** Type of download progress callbacks.
386 * @param filename the name of the file being downloaded
387 * @param xfered the number of transferred bytes
388 * @param total the total number of bytes to transfer
390 typedef void (*alpm_cb_download
)(const char *filename
,
391 off_t xfered
, off_t total
);
393 typedef void (*alpm_cb_totaldl
)(off_t total
);
395 /** A callback for downloading files
396 * @param url the URL of the file to be downloaded
397 * @param localpath the directory to which the file should be downloaded
398 * @param force whether to force an update, even if the file is the same
399 * @return 0 on success, 1 if the file exists and is identical, -1 on
402 typedef int (*alpm_cb_fetch
)(const char *url
, const char *localpath
,
405 /** Fetch a remote pkg.
406 * @param handle the context handle
407 * @param url URL of the package to download
408 * @return the downloaded filepath on success, NULL on error
410 char *alpm_fetch_pkgurl(alpm_handle_t
*handle
, const char *url
);
412 /** @addtogroup alpm_api_options Options
413 * Libalpm option getters and setters
417 /** Returns the callback used for logging. */
418 alpm_cb_log
alpm_option_get_logcb(alpm_handle_t
*handle
);
419 /** Sets the callback used for logging. */
420 int alpm_option_set_logcb(alpm_handle_t
*handle
, alpm_cb_log cb
);
422 /** Returns the callback used to report download progress. */
423 alpm_cb_download
alpm_option_get_dlcb(alpm_handle_t
*handle
);
424 /** Sets the callback used to report download progress. */
425 int alpm_option_set_dlcb(alpm_handle_t
*handle
, alpm_cb_download cb
);
427 /** Returns the downloading callback. */
428 alpm_cb_fetch
alpm_option_get_fetchcb(alpm_handle_t
*handle
);
429 /** Sets the downloading callback. */
430 int alpm_option_set_fetchcb(alpm_handle_t
*handle
, alpm_cb_fetch cb
);
432 /** Returns the callback used to report total download size. */
433 alpm_cb_totaldl
alpm_option_get_totaldlcb(alpm_handle_t
*handle
);
434 /** Sets the callback used to report total download size. */
435 int alpm_option_set_totaldlcb(alpm_handle_t
*handle
, alpm_cb_totaldl cb
);
437 /** Returns the callback used for events. */
438 alpm_cb_event
alpm_option_get_eventcb(alpm_handle_t
*handle
);
439 /** Sets the callback used for events. */
440 int alpm_option_set_eventcb(alpm_handle_t
*handle
, alpm_cb_event cb
);
442 /** Returns the callback used for questions. */
443 alpm_cb_question
alpm_option_get_questioncb(alpm_handle_t
*handle
);
444 /** Sets the callback used for questions. */
445 int alpm_option_set_questioncb(alpm_handle_t
*handle
, alpm_cb_question cb
);
447 /** Returns the callback used for operation progress. */
448 alpm_cb_progress
alpm_option_get_progresscb(alpm_handle_t
*handle
);
449 /** Sets the callback used for operation progress. */
450 int alpm_option_set_progresscb(alpm_handle_t
*handle
, alpm_cb_progress cb
);
452 /** Returns the root of the destination filesystem. Read-only. */
453 const char *alpm_option_get_root(alpm_handle_t
*handle
);
455 /** Returns the path to the database directory. Read-only. */
456 const char *alpm_option_get_dbpath(alpm_handle_t
*handle
);
458 /** Get the name of the database lock file. Read-only. */
459 const char *alpm_option_get_lockfile(alpm_handle_t
*handle
);
461 /** @name Accessors to the list of package cache directories.
464 alpm_list_t
*alpm_option_get_cachedirs(alpm_handle_t
*handle
);
465 int alpm_option_set_cachedirs(alpm_handle_t
*handle
, alpm_list_t
*cachedirs
);
466 int alpm_option_add_cachedir(alpm_handle_t
*handle
, const char *cachedir
);
467 int alpm_option_remove_cachedir(alpm_handle_t
*handle
, const char *cachedir
);
470 /** Returns the logfile name. */
471 const char *alpm_option_get_logfile(alpm_handle_t
*handle
);
472 /** Sets the logfile name. */
473 int alpm_option_set_logfile(alpm_handle_t
*handle
, const char *logfile
);
475 /** Returns the path to libalpm's GnuPG home directory. */
476 const char *alpm_option_get_gpgdir(alpm_handle_t
*handle
);
477 /** Sets the path to libalpm's GnuPG home directory. */
478 int alpm_option_set_gpgdir(alpm_handle_t
*handle
, const char *gpgdir
);
480 /** Returns whether to use syslog (0 is FALSE, TRUE otherwise). */
481 int alpm_option_get_usesyslog(alpm_handle_t
*handle
);
482 /** Sets whether to use syslog (0 is FALSE, TRUE otherwise). */
483 int alpm_option_set_usesyslog(alpm_handle_t
*handle
, int usesyslog
);
485 /** @name Accessors to the list of no-upgrade files.
486 * These functions modify the list of files which should
487 * not be updated by package installation.
490 alpm_list_t
*alpm_option_get_noupgrades(alpm_handle_t
*handle
);
491 int alpm_option_add_noupgrade(alpm_handle_t
*handle
, const char *pkg
);
492 int alpm_option_set_noupgrades(alpm_handle_t
*handle
, alpm_list_t
*noupgrade
);
493 int alpm_option_remove_noupgrade(alpm_handle_t
*handle
, const char *pkg
);
496 /** @name Accessors to the list of no-extract files.
497 * These functions modify the list of filenames which should
498 * be skipped packages which should
499 * not be upgraded by a sysupgrade operation.
502 alpm_list_t
*alpm_option_get_noextracts(alpm_handle_t
*handle
);
503 int alpm_option_add_noextract(alpm_handle_t
*handle
, const char *pkg
);
504 int alpm_option_set_noextracts(alpm_handle_t
*handle
, alpm_list_t
*noextract
);
505 int alpm_option_remove_noextract(alpm_handle_t
*handle
, const char *pkg
);
508 /** @name Accessors to the list of ignored packages.
509 * These functions modify the list of packages that
510 * should be ignored by a sysupgrade.
513 alpm_list_t
*alpm_option_get_ignorepkgs(alpm_handle_t
*handle
);
514 int alpm_option_add_ignorepkg(alpm_handle_t
*handle
, const char *pkg
);
515 int alpm_option_set_ignorepkgs(alpm_handle_t
*handle
, alpm_list_t
*ignorepkgs
);
516 int alpm_option_remove_ignorepkg(alpm_handle_t
*handle
, const char *pkg
);
519 /** @name Accessors to the list of ignored groups.
520 * These functions modify the list of groups whose packages
521 * should be ignored by a sysupgrade.
524 alpm_list_t
*alpm_option_get_ignoregroups(alpm_handle_t
*handle
);
525 int alpm_option_add_ignoregroup(alpm_handle_t
*handle
, const char *grp
);
526 int alpm_option_set_ignoregroups(alpm_handle_t
*handle
, alpm_list_t
*ignoregrps
);
527 int alpm_option_remove_ignoregroup(alpm_handle_t
*handle
, const char *grp
);
530 /** Returns the targeted architecture. */
531 const char *alpm_option_get_arch(alpm_handle_t
*handle
);
532 /** Sets the targeted architecture. */
533 int alpm_option_set_arch(alpm_handle_t
*handle
, const char *arch
);
535 double alpm_option_get_deltaratio(alpm_handle_t
*handle
);
536 int alpm_option_set_deltaratio(alpm_handle_t
*handle
, double ratio
);
538 int alpm_option_get_checkspace(alpm_handle_t
*handle
);
539 int alpm_option_set_checkspace(alpm_handle_t
*handle
, int checkspace
);
541 alpm_siglevel_t
alpm_option_get_default_siglevel(alpm_handle_t
*handle
);
542 int alpm_option_set_default_siglevel(alpm_handle_t
*handle
, alpm_siglevel_t level
);
546 /** @addtogroup alpm_api_databases Database Functions
547 * Functions to query and manipulate the database of libalpm.
551 /** Get the database of locally installed packages.
552 * The returned pointer points to an internal structure
553 * of libalpm which should only be manipulated through
555 * @return a reference to the local database
557 alpm_db_t
*alpm_get_localdb(alpm_handle_t
*handle
);
559 /** Get the list of sync databases.
560 * Returns a list of alpm_db_t structures, one for each registered
562 * @param handle the context handle
563 * @return a reference to an internal list of alpm_db_t structures
565 alpm_list_t
*alpm_get_syncdbs(alpm_handle_t
*handle
);
567 /** Register a sync database of packages.
568 * @param handle the context handle
569 * @param treename the name of the sync repository
570 * @param level what level of signature checking to perform on the
571 * database; note that this must be a '.sig' file type verification
572 * @return an alpm_db_t* on success (the value), NULL on error
574 alpm_db_t
*alpm_register_syncdb(alpm_handle_t
*handle
, const char *treename
,
575 alpm_siglevel_t level
);
577 /** Unregister all package databases.
578 * @param handle the context handle
579 * @return 0 on success, -1 on error (pm_errno is set accordingly)
581 int alpm_unregister_all_syncdbs(alpm_handle_t
*handle
);
583 /** Unregister a package database.
584 * @param db pointer to the package database to unregister
585 * @return 0 on success, -1 on error (pm_errno is set accordingly)
587 int alpm_db_unregister(alpm_db_t
*db
);
589 /** Get the name of a package database.
590 * @param db pointer to the package database
591 * @return the name of the package database, NULL on error
593 const char *alpm_db_get_name(const alpm_db_t
*db
);
595 /** Get the signature verification level for a database.
596 * Will return the default verification level if this database is set up
597 * with ALPM_SIG_USE_DEFAULT.
598 * @param db pointer to the package database
599 * @return the signature verification level
601 alpm_siglevel_t
alpm_db_get_siglevel(alpm_db_t
*db
);
603 /** Check the validity of a database.
604 * This is most useful for sync databases and verifying signature status.
605 * If invalid, the handle error code will be set accordingly.
606 * @param db pointer to the package database
607 * @return 0 if valid, -1 if invalid (pm_errno is set accordingly)
609 int alpm_db_get_valid(alpm_db_t
*db
);
611 /** @name Accessors to the list of servers for a database.
614 alpm_list_t
*alpm_db_get_servers(const alpm_db_t
*db
);
615 int alpm_db_set_servers(alpm_db_t
*db
, alpm_list_t
*servers
);
616 int alpm_db_add_server(alpm_db_t
*db
, const char *url
);
617 int alpm_db_remove_server(alpm_db_t
*db
, const char *url
);
620 int alpm_db_update(int level
, alpm_db_t
*db
);
622 /** Get a package entry from a package database.
623 * @param db pointer to the package database to get the package from
624 * @param name of the package
625 * @return the package entry on success, NULL on error
627 alpm_pkg_t
*alpm_db_get_pkg(alpm_db_t
*db
, const char *name
);
629 /** Get the package cache of a package database.
630 * @param db pointer to the package database to get the package from
631 * @return the list of packages on success, NULL on error
633 alpm_list_t
*alpm_db_get_pkgcache(alpm_db_t
*db
);
635 /** Get a group entry from a package database.
636 * @param db pointer to the package database to get the group from
637 * @param name of the group
638 * @return the groups entry on success, NULL on error
640 alpm_group_t
*alpm_db_get_group(alpm_db_t
*db
, const char *name
);
642 /** Get the group cache of a package database.
643 * @param db pointer to the package database to get the group from
644 * @return the list of groups on success, NULL on error
646 alpm_list_t
*alpm_db_get_groupcache(alpm_db_t
*db
);
648 /** Searches a database with regular expressions.
649 * @param db pointer to the package database to search in
650 * @param needles a list of regular expressions to search for
651 * @return the list of packages matching all regular expressions on success, NULL on error
653 alpm_list_t
*alpm_db_search(alpm_db_t
*db
, const alpm_list_t
*needles
);
657 /** @addtogroup alpm_api_packages Package Functions
658 * Functions to manipulate libalpm packages
662 /** Create a package from a file.
663 * If full is false, the archive is read only until all necessary
664 * metadata is found. If it is true, the entire archive is read, which
665 * serves as a verification of integrity and the filelist can be created.
666 * The allocated structure should be freed using alpm_pkg_free().
667 * @param handle the context handle
668 * @param filename location of the package tarball
669 * @param full whether to stop the load after metadata is read or continue
670 * through the full archive
671 * @param level what level of package signature checking to perform on the
672 * package; note that this must be a '.sig' file type verification
673 * @param pkg address of the package pointer
674 * @return 0 on success, -1 on error (pm_errno is set accordingly)
676 int alpm_pkg_load(alpm_handle_t
*handle
, const char *filename
, int full
,
677 alpm_siglevel_t level
, alpm_pkg_t
**pkg
);
680 * @param pkg package pointer to free
681 * @return 0 on success, -1 on error (pm_errno is set accordingly)
683 int alpm_pkg_free(alpm_pkg_t
*pkg
);
685 /** Check the integrity (with md5) of a package from the sync cache.
686 * @param pkg package pointer
687 * @return 0 on success, -1 on error (pm_errno is set accordingly)
689 int alpm_pkg_checkmd5sum(alpm_pkg_t
*pkg
);
691 /** Compare two version strings and determine which one is 'newer'. */
692 int alpm_pkg_vercmp(const char *a
, const char *b
);
694 /** Computes the list of packages requiring a given package.
695 * The return value of this function is a newly allocated
696 * list of package names (char*), it should be freed by the caller.
697 * @param pkg a package
698 * @return the list of packages requiring pkg
700 alpm_list_t
*alpm_pkg_compute_requiredby(alpm_pkg_t
*pkg
);
702 /** @name Package Property Accessors
703 * Any pointer returned by these functions points to internal structures
704 * allocated by libalpm. They should not be freed nor modified in any
709 /** Gets the name of the file from which the package was loaded.
710 * @param pkg a pointer to package
711 * @return a reference to an internal string
713 const char *alpm_pkg_get_filename(alpm_pkg_t
*pkg
);
715 /** Returns the package name.
716 * @param pkg a pointer to package
717 * @return a reference to an internal string
719 const char *alpm_pkg_get_name(alpm_pkg_t
*pkg
);
721 /** Returns the package version as a string.
722 * This includes all available epoch, version, and pkgrel components. Use
723 * alpm_pkg_vercmp() to compare version strings if necessary.
724 * @param pkg a pointer to package
725 * @return a reference to an internal string
727 const char *alpm_pkg_get_version(alpm_pkg_t
*pkg
);
729 /** Returns the origin of the package.
730 * @return an alpm_pkgfrom_t constant, -1 on error
732 alpm_pkgfrom_t
alpm_pkg_get_origin(alpm_pkg_t
*pkg
);
734 /** Returns the package description.
735 * @param pkg a pointer to package
736 * @return a reference to an internal string
738 const char *alpm_pkg_get_desc(alpm_pkg_t
*pkg
);
740 /** Returns the package URL.
741 * @param pkg a pointer to package
742 * @return a reference to an internal string
744 const char *alpm_pkg_get_url(alpm_pkg_t
*pkg
);
746 /** Returns the build timestamp of the package.
747 * @param pkg a pointer to package
748 * @return the timestamp of the build time
750 alpm_time_t
alpm_pkg_get_builddate(alpm_pkg_t
*pkg
);
752 /** Returns the install timestamp of the package.
753 * @param pkg a pointer to package
754 * @return the timestamp of the install time
756 alpm_time_t
alpm_pkg_get_installdate(alpm_pkg_t
*pkg
);
758 /** Returns the packager's name.
759 * @param pkg a pointer to package
760 * @return a reference to an internal string
762 const char *alpm_pkg_get_packager(alpm_pkg_t
*pkg
);
764 /** Returns the package's MD5 checksum as a string.
765 * The returned string is a sequence of 32 lowercase hexadecimal digits.
766 * @param pkg a pointer to package
767 * @return a reference to an internal string
769 const char *alpm_pkg_get_md5sum(alpm_pkg_t
*pkg
);
771 /** Returns the package's SHA256 checksum as a string.
772 * The returned string is a sequence of 64 lowercase hexadecimal digits.
773 * @param pkg a pointer to package
774 * @return a reference to an internal string
776 const char *alpm_pkg_get_sha256sum(alpm_pkg_t
*pkg
);
778 /** Returns the architecture for which the package was built.
779 * @param pkg a pointer to package
780 * @return a reference to an internal string
782 const char *alpm_pkg_get_arch(alpm_pkg_t
*pkg
);
784 /** Returns the size of the package. This is only available for sync database
785 * packages and package files, not those loaded from the local database.
786 * @param pkg a pointer to package
787 * @return the size of the package in bytes.
789 off_t
alpm_pkg_get_size(alpm_pkg_t
*pkg
);
791 /** Returns the installed size of the package.
792 * @param pkg a pointer to package
793 * @return the total size of files installed by the package.
795 off_t
alpm_pkg_get_isize(alpm_pkg_t
*pkg
);
797 /** Returns the package installation reason.
798 * @param pkg a pointer to package
799 * @return an enum member giving the install reason.
801 alpm_pkgreason_t
alpm_pkg_get_reason(alpm_pkg_t
*pkg
);
803 /** Returns the list of package licenses.
804 * @param pkg a pointer to package
805 * @return a pointer to an internal list of strings.
807 alpm_list_t
*alpm_pkg_get_licenses(alpm_pkg_t
*pkg
);
809 /** Returns the list of package groups.
810 * @param pkg a pointer to package
811 * @return a pointer to an internal list of strings.
813 alpm_list_t
*alpm_pkg_get_groups(alpm_pkg_t
*pkg
);
815 /** Returns the list of package dependencies as alpm_depend_t.
816 * @param pkg a pointer to package
817 * @return a reference to an internal list of alpm_depend_t structures.
819 alpm_list_t
*alpm_pkg_get_depends(alpm_pkg_t
*pkg
);
821 /** Returns the list of package optional dependencies.
822 * @param pkg a pointer to package
823 * @return a reference to an internal list of alpm_depend_t structures.
825 alpm_list_t
*alpm_pkg_get_optdepends(alpm_pkg_t
*pkg
);
827 /** Returns the list of packages conflicting with pkg.
828 * @param pkg a pointer to package
829 * @return a reference to an internal list of alpm_depend_t structures.
831 alpm_list_t
*alpm_pkg_get_conflicts(alpm_pkg_t
*pkg
);
833 /** Returns the list of packages provided by pkg.
834 * @param pkg a pointer to package
835 * @return a reference to an internal list of alpm_depend_t structures.
837 alpm_list_t
*alpm_pkg_get_provides(alpm_pkg_t
*pkg
);
839 /** Returns the list of available deltas for pkg.
840 * @param pkg a pointer to package
841 * @return a reference to an internal list of strings.
843 alpm_list_t
*alpm_pkg_get_deltas(alpm_pkg_t
*pkg
);
845 /** Returns the list of packages to be replaced by pkg.
846 * @param pkg a pointer to package
847 * @return a reference to an internal list of alpm_depend_t structures.
849 alpm_list_t
*alpm_pkg_get_replaces(alpm_pkg_t
*pkg
);
851 /** Returns the list of files installed by pkg.
852 * The filenames are relative to the install root,
853 * and do not include leading slashes.
854 * @param pkg a pointer to package
855 * @return a pointer to a filelist object containing a count and an array of
856 * package file objects
858 alpm_filelist_t
*alpm_pkg_get_files(alpm_pkg_t
*pkg
);
860 /** Returns the list of files backed up when installing pkg.
861 * The elements of the returned list have the form
862 * "<filename>\t<md5sum>", where the given md5sum is that of
863 * the file as provided by the package.
864 * @param pkg a pointer to package
865 * @return a reference to an internal list of strings.
867 alpm_list_t
*alpm_pkg_get_backup(alpm_pkg_t
*pkg
);
869 /** Returns the database containing pkg.
870 * Returns a pointer to the alpm_db_t structure the package is
871 * originating from, or NULL if the package was loaded from a file.
872 * @param pkg a pointer to package
873 * @return a pointer to the DB containing pkg, or NULL.
875 alpm_db_t
*alpm_pkg_get_db(alpm_pkg_t
*pkg
);
877 /** Returns the base64 encoded package signature.
878 * @param pkg a pointer to package
879 * @return a reference to an internal string
881 const char *alpm_pkg_get_base64_sig(alpm_pkg_t
*pkg
);
883 /* End of alpm_pkg_t accessors */
886 /** Open a package changelog for reading.
887 * Similar to fopen in functionality, except that the returned 'file
888 * stream' could really be from an archive as well as from the database.
889 * @param pkg the package to read the changelog of (either file or db)
890 * @return a 'file stream' to the package changelog
892 void *alpm_pkg_changelog_open(alpm_pkg_t
*pkg
);
894 /** Read data from an open changelog 'file stream'.
895 * Similar to fread in functionality, this function takes a buffer and
896 * amount of data to read. If an error occurs pm_errno will be set.
897 * @param ptr a buffer to fill with raw changelog data
898 * @param size the size of the buffer
899 * @param pkg the package that the changelog is being read from
900 * @param fp a 'file stream' to the package changelog
901 * @return the number of characters read, or 0 if there is no more data or an
904 size_t alpm_pkg_changelog_read(void *ptr
, size_t size
,
905 const alpm_pkg_t
*pkg
, void *fp
);
907 int alpm_pkg_changelog_close(const alpm_pkg_t
*pkg
, void *fp
);
909 /** Returns whether the package has an install scriptlet.
910 * @return 0 if FALSE, TRUE otherwise
912 int alpm_pkg_has_scriptlet(alpm_pkg_t
*pkg
);
914 /** Returns the size of download.
915 * Returns the size of the files that will be downloaded to install a
917 * @param newpkg the new package to upgrade to
918 * @return the size of the download
920 off_t
alpm_pkg_download_size(alpm_pkg_t
*newpkg
);
922 alpm_list_t
*alpm_pkg_unused_deltas(alpm_pkg_t
*pkg
);
924 /** Set install reason for a package in the local database.
925 * The provided package object must be from the local database or this method
926 * will fail. The write to the local database is performed immediately.
927 * @param pkg the package to update
928 * @param reason the new install reason
929 * @return 0 on success, -1 on error (pm_errno is set accordingly)
931 int alpm_pkg_set_reason(alpm_pkg_t
*pkg
, alpm_pkgreason_t reason
);
934 /* End of alpm_pkg */
941 int alpm_pkg_check_pgp_signature(alpm_pkg_t
*pkg
, alpm_siglist_t
*siglist
);
943 int alpm_db_check_pgp_signature(alpm_db_t
*db
, alpm_siglist_t
*siglist
);
945 int alpm_siglist_cleanup(alpm_siglist_t
*siglist
);
951 alpm_list_t
*alpm_find_group_pkgs(alpm_list_t
*dbs
, const char *name
);
957 alpm_pkg_t
*alpm_sync_newversion(alpm_pkg_t
*pkg
, alpm_list_t
*dbs_sync
);
959 /** @addtogroup alpm_api_trans Transaction Functions
960 * Functions to manipulate libalpm transactions
964 /** Transaction flags */
965 typedef enum _alpm_transflag_t
{
966 /** Ignore dependency checks. */
967 ALPM_TRANS_FLAG_NODEPS
= 1,
968 /** Ignore file conflicts and overwrite files. */
969 ALPM_TRANS_FLAG_FORCE
= (1 << 1),
970 /** Delete files even if they are tagged as backup. */
971 ALPM_TRANS_FLAG_NOSAVE
= (1 << 2),
972 /** Ignore version numbers when checking dependencies. */
973 ALPM_TRANS_FLAG_NODEPVERSION
= (1 << 3),
974 /** Remove also any packages depending on a package being removed. */
975 ALPM_TRANS_FLAG_CASCADE
= (1 << 4),
976 /** Remove packages and their unneeded deps (not explicitly installed). */
977 ALPM_TRANS_FLAG_RECURSE
= (1 << 5),
978 /** Modify database but do not commit changes to the filesystem. */
979 ALPM_TRANS_FLAG_DBONLY
= (1 << 6),
980 /* (1 << 7) flag can go here */
981 /** Use ALPM_PKG_REASON_DEPEND when installing packages. */
982 ALPM_TRANS_FLAG_ALLDEPS
= (1 << 8),
983 /** Only download packages and do not actually install. */
984 ALPM_TRANS_FLAG_DOWNLOADONLY
= (1 << 9),
985 /** Do not execute install scriptlets after installing. */
986 ALPM_TRANS_FLAG_NOSCRIPTLET
= (1 << 10),
987 /** Ignore dependency conflicts. */
988 ALPM_TRANS_FLAG_NOCONFLICTS
= (1 << 11),
989 /* (1 << 12) flag can go here */
990 /** Do not install a package if it is already installed and up to date. */
991 ALPM_TRANS_FLAG_NEEDED
= (1 << 13),
992 /** Use ALPM_PKG_REASON_EXPLICIT when installing packages. */
993 ALPM_TRANS_FLAG_ALLEXPLICIT
= (1 << 14),
994 /** Do not remove a package if it is needed by another one. */
995 ALPM_TRANS_FLAG_UNNEEDED
= (1 << 15),
996 /** Remove also explicitly installed unneeded deps (use with ALPM_TRANS_FLAG_RECURSE). */
997 ALPM_TRANS_FLAG_RECURSEALL
= (1 << 16),
998 /** Do not lock the database during the operation. */
999 ALPM_TRANS_FLAG_NOLOCK
= (1 << 17)
1002 /** Returns the bitfield of flags for the current transaction.
1003 * @param handle the context handle
1004 * @return the bitfield of transaction flags
1006 alpm_transflag_t
alpm_trans_get_flags(alpm_handle_t
*handle
);
1008 /** Returns a list of packages added by the transaction.
1009 * @param handle the context handle
1010 * @return a list of alpm_pkg_t structures
1012 alpm_list_t
*alpm_trans_get_add(alpm_handle_t
*handle
);
1014 /** Returns the list of packages removed by the transaction.
1015 * @param handle the context handle
1016 * @return a list of alpm_pkg_t structures
1018 alpm_list_t
*alpm_trans_get_remove(alpm_handle_t
*handle
);
1020 /** Initialize the transaction.
1021 * @param handle the context handle
1022 * @param flags flags of the transaction (like nodeps, etc)
1023 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1025 int alpm_trans_init(alpm_handle_t
*handle
, alpm_transflag_t flags
);
1027 /** Prepare a transaction.
1028 * @param handle the context handle
1029 * @param data the address of an alpm_list where a list
1030 * of alpm_depmissing_t objects is dumped (conflicting packages)
1031 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1033 int alpm_trans_prepare(alpm_handle_t
*handle
, alpm_list_t
**data
);
1035 /** Commit a transaction.
1036 * @param handle the context handle
1037 * @param data the address of an alpm_list where detailed description
1038 * of an error can be dumped (i.e. list of conflicting files)
1039 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1041 int alpm_trans_commit(alpm_handle_t
*handle
, alpm_list_t
**data
);
1043 /** Interrupt a transaction.
1044 * @param handle the context handle
1045 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1047 int alpm_trans_interrupt(alpm_handle_t
*handle
);
1049 /** Release a transaction.
1050 * @param handle the context handle
1051 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1053 int alpm_trans_release(alpm_handle_t
*handle
);
1056 /** @name Common Transactions */
1059 /** Search for packages to upgrade and add them to the transaction.
1060 * @param handle the context handle
1061 * @param enable_downgrade allow downgrading of packages if the remote version is lower
1062 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1064 int alpm_sync_sysupgrade(alpm_handle_t
*handle
, int enable_downgrade
);
1066 /** Add a package to the transaction.
1067 * If the package was loaded by alpm_pkg_load(), it will be freed upon
1068 * alpm_trans_release() invocation.
1069 * @param handle the context handle
1070 * @param pkg the package to add
1071 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1073 int alpm_add_pkg(alpm_handle_t
*handle
, alpm_pkg_t
*pkg
);
1075 /** Add a package removal action to the transaction.
1076 * @param handle the context handle
1077 * @param pkg the package to uninstall
1078 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1080 int alpm_remove_pkg(alpm_handle_t
*handle
, alpm_pkg_t
*pkg
);
1084 /** @addtogroup alpm_api_depends Dependency Functions
1085 * Functions dealing with libalpm representation of dependency
1090 alpm_list_t
*alpm_checkdeps(alpm_handle_t
*handle
, alpm_list_t
*pkglist
,
1091 alpm_list_t
*remove
, alpm_list_t
*upgrade
, int reversedeps
);
1092 alpm_pkg_t
*alpm_find_satisfier(alpm_list_t
*pkgs
, const char *depstring
);
1093 alpm_pkg_t
*alpm_find_dbs_satisfier(alpm_handle_t
*handle
,
1094 alpm_list_t
*dbs
, const char *depstring
);
1096 alpm_list_t
*alpm_checkconflicts(alpm_handle_t
*handle
, alpm_list_t
*pkglist
);
1098 /** Returns a newly allocated string representing the dependency information.
1099 * @param dep a dependency info structure
1100 * @return a formatted string, e.g. "glibc>=2.12"
1102 char *alpm_dep_compute_string(const alpm_depend_t
*dep
);
1113 char *alpm_compute_md5sum(const char *filename
);
1114 char *alpm_compute_sha256sum(const char *filename
);
1116 /** @addtogroup alpm_api_errors Error Codes
1119 typedef enum _alpm_errno_t
{
1120 ALPM_ERR_MEMORY
= 1,
1123 ALPM_ERR_NOT_A_FILE
,
1125 ALPM_ERR_WRONG_ARGS
,
1126 ALPM_ERR_DISK_SPACE
,
1128 ALPM_ERR_HANDLE_NULL
,
1129 ALPM_ERR_HANDLE_NOT_NULL
,
1130 ALPM_ERR_HANDLE_LOCK
,
1135 ALPM_ERR_DB_NOT_NULL
,
1136 ALPM_ERR_DB_NOT_FOUND
,
1137 ALPM_ERR_DB_INVALID
,
1138 ALPM_ERR_DB_INVALID_SIG
,
1139 ALPM_ERR_DB_VERSION
,
1143 ALPM_ERR_SERVER_BAD_URL
,
1144 ALPM_ERR_SERVER_NONE
,
1146 ALPM_ERR_TRANS_NOT_NULL
,
1147 ALPM_ERR_TRANS_NULL
,
1148 ALPM_ERR_TRANS_DUP_TARGET
,
1149 ALPM_ERR_TRANS_NOT_INITIALIZED
,
1150 ALPM_ERR_TRANS_NOT_PREPARED
,
1151 ALPM_ERR_TRANS_ABORT
,
1152 ALPM_ERR_TRANS_TYPE
,
1153 ALPM_ERR_TRANS_NOT_LOCKED
,
1155 ALPM_ERR_PKG_NOT_FOUND
,
1156 ALPM_ERR_PKG_IGNORED
,
1157 ALPM_ERR_PKG_INVALID
,
1158 ALPM_ERR_PKG_INVALID_CHECKSUM
,
1159 ALPM_ERR_PKG_INVALID_SIG
,
1161 ALPM_ERR_PKG_CANT_REMOVE
,
1162 ALPM_ERR_PKG_INVALID_NAME
,
1163 ALPM_ERR_PKG_INVALID_ARCH
,
1164 ALPM_ERR_PKG_REPO_NOT_FOUND
,
1166 ALPM_ERR_SIG_MISSING
,
1167 ALPM_ERR_SIG_INVALID
,
1169 ALPM_ERR_DLT_INVALID
,
1170 ALPM_ERR_DLT_PATCHFAILED
,
1172 ALPM_ERR_UNSATISFIED_DEPS
,
1173 ALPM_ERR_CONFLICTING_DEPS
,
1174 ALPM_ERR_FILE_CONFLICTS
,
1177 ALPM_ERR_INVALID_REGEX
,
1178 /* External library errors */
1179 ALPM_ERR_LIBARCHIVE
,
1181 ALPM_ERR_EXTERNAL_DOWNLOAD
,
1185 /** Returns the current error code from the handle. */
1186 alpm_errno_t
alpm_errno(alpm_handle_t
*handle
);
1188 /** Returns the string corresponding to an error number. */
1189 const char *alpm_strerror(alpm_errno_t err
);
1191 /* End of alpm_api_errors */
1194 alpm_handle_t
*alpm_initialize(const char *root
, const char *dbpath
,
1196 int alpm_release(alpm_handle_t
*handle
);
1199 ALPM_CAPABILITY_NLS
= (1 << 0),
1200 ALPM_CAPABILITY_DOWNLOADER
= (1 << 1),
1201 ALPM_CAPABILITY_SIGNATURES
= (1 << 2)
1204 const char *alpm_version(void);
1205 enum alpm_caps
alpm_capabilities(void);
1207 /* End of alpm_api */
1213 #endif /* _ALPM_H */
1215 /* vim: set ts=2 sw=2 noet: */