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/>.
30 #include <inttypes.h> /* int64_t */
31 #include <sys/types.h> /* off_t */
32 #include <stdarg.h> /* va_list */
34 #include <alpm_list.h>
36 #define DEPRECATED __attribute__((deprecated))
39 * Arch Linux Package Management library
42 /** @addtogroup alpm_api Public API
43 * The libalpm Public API
47 typedef int64_t alpm_time_t
;
51 * These ones are used in multiple contexts, so are forward-declared.
56 * Why the package was installed.
58 typedef enum _alpm_pkgreason_t
{
59 /** Explicitly requested by the user. */
60 ALPM_PKG_REASON_EXPLICIT
= 0,
61 /** Installed as a dependency for another package. */
62 ALPM_PKG_REASON_DEPEND
= 1
65 typedef enum _alpm_pkgfrom_t
{
71 /** Types of version constraints in dependency specs. */
72 typedef enum _alpm_depmod_t
{
73 /** No version constraint */
75 /** Test version equality (package=x.y.z) */
77 /** Test for at least a version (package>=x.y.z) */
79 /** Test for at most a version (package<=x.y.z) */
81 /** Test for greater than some version (package>x.y.z) */
83 /** Test for less than some version (package<x.y.z) */
89 * Whether the conflict results from a file existing on the filesystem, or with
90 * another target in the transaction.
92 typedef enum _alpm_fileconflicttype_t
{
93 ALPM_FILECONFLICT_TARGET
= 1,
94 ALPM_FILECONFLICT_FILESYSTEM
95 } alpm_fileconflicttype_t
;
98 * PGP signature verification options
100 typedef enum _alpm_siglevel_t
{
101 ALPM_SIG_PACKAGE
= (1 << 0),
102 ALPM_SIG_PACKAGE_OPTIONAL
= (1 << 1),
103 ALPM_SIG_PACKAGE_MARGINAL_OK
= (1 << 2),
104 ALPM_SIG_PACKAGE_UNKNOWN_OK
= (1 << 3),
106 ALPM_SIG_DATABASE
= (1 << 10),
107 ALPM_SIG_DATABASE_OPTIONAL
= (1 << 11),
108 ALPM_SIG_DATABASE_MARGINAL_OK
= (1 << 12),
109 ALPM_SIG_DATABASE_UNKNOWN_OK
= (1 << 13),
111 ALPM_SIG_USE_DEFAULT
= (1 << 31)
115 * PGP signature verification status return codes
117 typedef enum _alpm_sigstatus_t
{
118 ALPM_SIGSTATUS_VALID
,
119 ALPM_SIGSTATUS_KEY_EXPIRED
,
120 ALPM_SIGSTATUS_SIG_EXPIRED
,
121 ALPM_SIGSTATUS_KEY_UNKNOWN
,
122 ALPM_SIGSTATUS_KEY_DISABLED
,
123 ALPM_SIGSTATUS_INVALID
127 * PGP signature verification status return codes
129 typedef enum _alpm_sigvalidity_t
{
130 ALPM_SIGVALIDITY_FULL
,
131 ALPM_SIGVALIDITY_MARGINAL
,
132 ALPM_SIGVALIDITY_NEVER
,
133 ALPM_SIGVALIDITY_UNKNOWN
134 } alpm_sigvalidity_t
;
140 typedef struct __alpm_handle_t alpm_handle_t
;
141 typedef struct __alpm_db_t alpm_db_t
;
142 typedef struct __alpm_pkg_t alpm_pkg_t
;
143 typedef struct __alpm_trans_t alpm_trans_t
;
146 typedef struct _alpm_depend_t
{
149 unsigned long name_hash
;
153 /** Missing dependency */
154 typedef struct _alpm_depmissing_t
{
156 alpm_depend_t
*depend
;
157 /* this is used in case of remove dependency error only */
162 typedef struct _alpm_conflict_t
{
163 unsigned long package1_hash
;
164 unsigned long package2_hash
;
167 alpm_depend_t
*reason
;
171 typedef struct _alpm_fileconflict_t
{
173 alpm_fileconflicttype_t type
;
176 } alpm_fileconflict_t
;
179 typedef struct _alpm_group_t
{
182 /** list of alpm_pkg_t packages */
183 alpm_list_t
*packages
;
186 /** Package upgrade delta */
187 typedef struct _alpm_delta_t
{
188 /** filename of the delta patch */
190 /** md5sum of the delta file */
192 /** filename of the 'before' file */
194 /** filename of the 'after' file */
196 /** filesize of the delta file */
198 /** download filesize of the delta file */
202 /** File in a package */
203 typedef struct _alpm_file_t
{
209 /** Package filelist container */
210 typedef struct _alpm_filelist_t
{
215 /** Local package or package file backup entry */
216 typedef struct _alpm_backup_t
{
221 typedef struct _alpm_pgpkey_t
{
230 unsigned int revoked
;
234 /** Signature result. Contains the key, status, and validity of a given
237 typedef struct _alpm_sigresult_t
{
239 alpm_sigstatus_t status
;
240 alpm_sigvalidity_t validity
;
243 /** Signature list. Contains the number of signatures found and a pointer to an
244 * array of results. The array is of size count.
246 typedef struct _alpm_siglist_t
{
248 alpm_sigresult_t
*results
;
258 typedef enum _alpm_loglevel_t
{
260 ALPM_LOG_WARNING
= (1 << 1),
261 ALPM_LOG_DEBUG
= (1 << 2),
262 ALPM_LOG_FUNCTION
= (1 << 3)
265 typedef void (*alpm_cb_log
)(alpm_loglevel_t
, const char *, va_list);
266 int alpm_logaction(alpm_handle_t
*handle
, const char *fmt
, ...);
269 * NULL parameters are passed to in all events unless specified otherwise.
271 typedef enum _alpm_event_t
{
272 /** Dependencies will be computed for a package. */
273 ALPM_EVENT_CHECKDEPS_START
= 1,
274 /** Dependencies were computed for a package. */
275 ALPM_EVENT_CHECKDEPS_DONE
,
276 /** File conflicts will be computed for a package. */
277 ALPM_EVENT_FILECONFLICTS_START
,
278 /** File conflicts were computed for a package. */
279 ALPM_EVENT_FILECONFLICTS_DONE
,
280 /** Dependencies will be resolved for target package. */
281 ALPM_EVENT_RESOLVEDEPS_START
,
282 /** Dependencies were resolved for target package. */
283 ALPM_EVENT_RESOLVEDEPS_DONE
,
284 /** Inter-conflicts will be checked for target package. */
285 ALPM_EVENT_INTERCONFLICTS_START
,
286 /** Inter-conflicts were checked for target package. */
287 ALPM_EVENT_INTERCONFLICTS_DONE
,
288 /** Package will be installed.
289 * A pointer to the target package is passed to the callback.
291 ALPM_EVENT_ADD_START
,
292 /** Package was installed.
293 * A pointer to the new package is passed to the callback.
296 /** Package will be removed.
297 * A pointer to the target package is passed to the callback.
299 ALPM_EVENT_REMOVE_START
,
300 /** Package was removed.
301 * A pointer to the removed package is passed to the callback.
303 ALPM_EVENT_REMOVE_DONE
,
304 /** Package will be upgraded.
305 * A pointer to the upgraded package is passed to the callback.
307 ALPM_EVENT_UPGRADE_START
,
308 /** Package was upgraded.
309 * A pointer to the new package, and a pointer to the old package is passed
310 * to the callback, respectively.
312 ALPM_EVENT_UPGRADE_DONE
,
313 /** Target package's integrity will be checked. */
314 ALPM_EVENT_INTEGRITY_START
,
315 /** Target package's integrity was checked. */
316 ALPM_EVENT_INTEGRITY_DONE
,
317 /** Target package will be loaded. */
318 ALPM_EVENT_LOAD_START
,
319 /** Target package is finished loading. */
320 ALPM_EVENT_LOAD_DONE
,
321 /** Target deltas's integrity will be checked. */
322 ALPM_EVENT_DELTA_INTEGRITY_START
,
323 /** Target delta's integrity was checked. */
324 ALPM_EVENT_DELTA_INTEGRITY_DONE
,
325 /** Deltas will be applied to packages. */
326 ALPM_EVENT_DELTA_PATCHES_START
,
327 /** Deltas were applied to packages. */
328 ALPM_EVENT_DELTA_PATCHES_DONE
,
329 /** Delta patch will be applied to target package.
330 * The filename of the package and the filename of the patch is passed to the
333 ALPM_EVENT_DELTA_PATCH_START
,
334 /** Delta patch was applied to target package. */
335 ALPM_EVENT_DELTA_PATCH_DONE
,
336 /** Delta patch failed to apply to target package. */
337 ALPM_EVENT_DELTA_PATCH_FAILED
,
338 /** Scriptlet has printed information.
339 * A line of text is passed to the callback.
341 ALPM_EVENT_SCRIPTLET_INFO
,
342 /** Files will be downloaded from a repository.
343 * The repository's tree name is passed to the callback.
345 ALPM_EVENT_RETRIEVE_START
,
346 /** Disk space usage will be computed for a package */
347 ALPM_EVENT_DISKSPACE_START
,
348 /** Disk space usage was computed for a package */
349 ALPM_EVENT_DISKSPACE_DONE
,
352 /** Event callback */
353 typedef void (*alpm_cb_event
)(alpm_event_t
, void *, void *);
356 typedef enum _alpm_question_t
{
357 ALPM_QUESTION_INSTALL_IGNOREPKG
= 1,
358 ALPM_QUESTION_REPLACE_PKG
= (1 << 1),
359 ALPM_QUESTION_CONFLICT_PKG
= (1 << 2),
360 ALPM_QUESTION_CORRUPTED_PKG
= (1 << 3),
361 ALPM_QUESTION_LOCAL_NEWER
= (1 << 4),
362 ALPM_QUESTION_REMOVE_PKGS
= (1 << 5),
363 ALPM_QUESTION_SELECT_PROVIDER
= (1 << 6),
364 ALPM_QUESTION_IMPORT_KEY
= (1 << 7)
367 /** Question callback */
368 typedef void (*alpm_cb_question
)(alpm_question_t
, void *, void *, void *, int *);
371 typedef enum _alpm_progress_t
{
372 ALPM_PROGRESS_ADD_START
,
373 ALPM_PROGRESS_UPGRADE_START
,
374 ALPM_PROGRESS_REMOVE_START
,
375 ALPM_PROGRESS_CONFLICTS_START
,
376 ALPM_PROGRESS_DISKSPACE_START
,
377 ALPM_PROGRESS_INTEGRITY_START
,
378 ALPM_PROGRESS_LOAD_START
,
381 /** Progress callback */
382 typedef void (*alpm_cb_progress
)(alpm_progress_t
, const char *, int, size_t, size_t);
388 /** Type of download progress callbacks.
389 * @param filename the name of the file being downloaded
390 * @param xfered the number of transferred bytes
391 * @param total the total number of bytes to transfer
393 typedef void (*alpm_cb_download
)(const char *filename
,
394 off_t xfered
, off_t total
);
396 typedef void (*alpm_cb_totaldl
)(off_t total
);
398 /** A callback for downloading files
399 * @param url the URL of the file to be downloaded
400 * @param localpath the directory to which the file should be downloaded
401 * @param force whether to force an update, even if the file is the same
402 * @return 0 on success, 1 if the file exists and is identical, -1 on
405 typedef int (*alpm_cb_fetch
)(const char *url
, const char *localpath
,
408 /** Fetch a remote pkg.
409 * @param handle the context handle
410 * @param url URL of the package to download
411 * @return the downloaded filepath on success, NULL on error
413 char *alpm_fetch_pkgurl(alpm_handle_t
*handle
, const char *url
);
415 /** @addtogroup alpm_api_options Options
416 * Libalpm option getters and setters
420 /** Returns the callback used for logging. */
421 alpm_cb_log
alpm_option_get_logcb(alpm_handle_t
*handle
);
422 /** Sets the callback used for logging. */
423 int alpm_option_set_logcb(alpm_handle_t
*handle
, alpm_cb_log cb
);
425 /** Returns the callback used to report download progress. */
426 alpm_cb_download
alpm_option_get_dlcb(alpm_handle_t
*handle
);
427 /** Sets the callback used to report download progress. */
428 int alpm_option_set_dlcb(alpm_handle_t
*handle
, alpm_cb_download cb
);
430 /** Returns the downloading callback. */
431 alpm_cb_fetch
alpm_option_get_fetchcb(alpm_handle_t
*handle
);
432 /** Sets the downloading callback. */
433 int alpm_option_set_fetchcb(alpm_handle_t
*handle
, alpm_cb_fetch cb
);
435 /** Returns the callback used to report total download size. */
436 alpm_cb_totaldl
alpm_option_get_totaldlcb(alpm_handle_t
*handle
);
437 /** Sets the callback used to report total download size. */
438 int alpm_option_set_totaldlcb(alpm_handle_t
*handle
, alpm_cb_totaldl cb
);
440 /** Returns the callback used for events. */
441 alpm_cb_event
alpm_option_get_eventcb(alpm_handle_t
*handle
);
442 /** Sets the callback used for events. */
443 int alpm_option_set_eventcb(alpm_handle_t
*handle
, alpm_cb_event cb
);
445 /** Returns the callback used for questions. */
446 alpm_cb_question
alpm_option_get_questioncb(alpm_handle_t
*handle
);
447 /** Sets the callback used for questions. */
448 int alpm_option_set_questioncb(alpm_handle_t
*handle
, alpm_cb_question cb
);
450 /** Returns the callback used for operation progress. */
451 alpm_cb_progress
alpm_option_get_progresscb(alpm_handle_t
*handle
);
452 /** Sets the callback used for operation progress. */
453 int alpm_option_set_progresscb(alpm_handle_t
*handle
, alpm_cb_progress cb
);
455 /** Returns the root of the destination filesystem. Read-only. */
456 const char *alpm_option_get_root(alpm_handle_t
*handle
);
458 /** Returns the path to the database directory. Read-only. */
459 const char *alpm_option_get_dbpath(alpm_handle_t
*handle
);
461 /** Get the name of the database lock file. Read-only. */
462 const char *alpm_option_get_lockfile(alpm_handle_t
*handle
);
464 /** @name Accessors to the list of package cache directories.
467 alpm_list_t
*alpm_option_get_cachedirs(alpm_handle_t
*handle
);
468 int alpm_option_set_cachedirs(alpm_handle_t
*handle
, alpm_list_t
*cachedirs
);
469 int alpm_option_add_cachedir(alpm_handle_t
*handle
, const char *cachedir
);
470 int alpm_option_remove_cachedir(alpm_handle_t
*handle
, const char *cachedir
);
473 /** Returns the logfile name. */
474 const char *alpm_option_get_logfile(alpm_handle_t
*handle
);
475 /** Sets the logfile name. */
476 int alpm_option_set_logfile(alpm_handle_t
*handle
, const char *logfile
);
478 /** Returns the path to libalpm's GnuPG home directory. */
479 const char *alpm_option_get_gpgdir(alpm_handle_t
*handle
);
480 /** Sets the path to libalpm's GnuPG home directory. */
481 int alpm_option_set_gpgdir(alpm_handle_t
*handle
, const char *gpgdir
);
483 /** Returns whether to use syslog (0 is FALSE, TRUE otherwise). */
484 int alpm_option_get_usesyslog(alpm_handle_t
*handle
);
485 /** Sets whether to use syslog (0 is FALSE, TRUE otherwise). */
486 int alpm_option_set_usesyslog(alpm_handle_t
*handle
, int usesyslog
);
488 /** @name Accessors to the list of no-upgrade files.
489 * These functions modify the list of files which should
490 * not be updated by package installation.
493 alpm_list_t
*alpm_option_get_noupgrades(alpm_handle_t
*handle
);
494 int alpm_option_add_noupgrade(alpm_handle_t
*handle
, const char *pkg
);
495 int alpm_option_set_noupgrades(alpm_handle_t
*handle
, alpm_list_t
*noupgrade
);
496 int alpm_option_remove_noupgrade(alpm_handle_t
*handle
, const char *pkg
);
499 /** @name Accessors to the list of no-extract files.
500 * These functions modify the list of filenames which should
501 * be skipped packages which should
502 * not be upgraded by a sysupgrade operation.
505 alpm_list_t
*alpm_option_get_noextracts(alpm_handle_t
*handle
);
506 int alpm_option_add_noextract(alpm_handle_t
*handle
, const char *pkg
);
507 int alpm_option_set_noextracts(alpm_handle_t
*handle
, alpm_list_t
*noextract
);
508 int alpm_option_remove_noextract(alpm_handle_t
*handle
, const char *pkg
);
511 /** @name Accessors to the list of ignored packages.
512 * These functions modify the list of packages that
513 * should be ignored by a sysupgrade.
516 alpm_list_t
*alpm_option_get_ignorepkgs(alpm_handle_t
*handle
);
517 int alpm_option_add_ignorepkg(alpm_handle_t
*handle
, const char *pkg
);
518 int alpm_option_set_ignorepkgs(alpm_handle_t
*handle
, alpm_list_t
*ignorepkgs
);
519 int alpm_option_remove_ignorepkg(alpm_handle_t
*handle
, const char *pkg
);
522 /** @name Accessors to the list of ignored groups.
523 * These functions modify the list of groups whose packages
524 * should be ignored by a sysupgrade.
527 alpm_list_t
*alpm_option_get_ignoregroups(alpm_handle_t
*handle
);
528 int alpm_option_add_ignoregroup(alpm_handle_t
*handle
, const char *grp
);
529 int alpm_option_set_ignoregroups(alpm_handle_t
*handle
, alpm_list_t
*ignoregrps
);
530 int alpm_option_remove_ignoregroup(alpm_handle_t
*handle
, const char *grp
);
533 /** Returns the targeted architecture. */
534 const char *alpm_option_get_arch(alpm_handle_t
*handle
);
535 /** Sets the targeted architecture. */
536 int alpm_option_set_arch(alpm_handle_t
*handle
, const char *arch
);
538 int alpm_option_get_usedelta(alpm_handle_t
*handle
);
539 int alpm_option_set_usedelta(alpm_handle_t
*handle
, int usedelta
);
541 int alpm_option_get_checkspace(alpm_handle_t
*handle
);
542 int alpm_option_set_checkspace(alpm_handle_t
*handle
, int checkspace
);
544 alpm_siglevel_t
alpm_option_get_default_siglevel(alpm_handle_t
*handle
);
545 int alpm_option_set_default_siglevel(alpm_handle_t
*handle
, alpm_siglevel_t level
);
549 /** @addtogroup alpm_api_databases Database Functions
550 * Functions to query and manipulate the database of libalpm.
554 /** Get the database of locally installed packages.
555 * The returned pointer points to an internal structure
556 * of libalpm which should only be manipulated through
558 * @return a reference to the local database
560 alpm_db_t
*alpm_option_get_localdb(alpm_handle_t
*handle
);
562 /** Get the list of sync databases.
563 * Returns a list of alpm_db_t structures, one for each registered
565 * @param handle the context handle
566 * @return a reference to an internal list of alpm_db_t structures
568 alpm_list_t
*alpm_option_get_syncdbs(alpm_handle_t
*handle
);
570 /** Register a sync database of packages.
571 * @param handle the context handle
572 * @param treename the name of the sync repository
573 * @param level what level of signature checking to perform on the
574 * database; note that this must be a '.sig' file type verification
575 * @return an alpm_db_t* on success (the value), NULL on error
577 alpm_db_t
*alpm_db_register_sync(alpm_handle_t
*handle
, const char *treename
,
578 alpm_siglevel_t level
);
580 /** Unregister a package database.
581 * @param db pointer to the package database to unregister
582 * @return 0 on success, -1 on error (pm_errno is set accordingly)
584 int alpm_db_unregister(alpm_db_t
*db
);
586 /** Unregister all package databases.
587 * @param handle the context handle
588 * @return 0 on success, -1 on error (pm_errno is set accordingly)
590 int alpm_db_unregister_all(alpm_handle_t
*handle
);
592 /** Get the name of a package database.
593 * @param db pointer to the package database
594 * @return the name of the package database, NULL on error
596 const char *alpm_db_get_name(const alpm_db_t
*db
);
598 /** Get the signature verification level for a database.
599 * Will return the default verification level if this database is set up
600 * with ALPM_SIG_USE_DEFAULT.
601 * @param db pointer to the package database
602 * @return the signature verification level
604 alpm_siglevel_t
alpm_db_get_siglevel(alpm_db_t
*db
);
606 /** Check the validity of a database.
607 * This is most useful for sync databases and verifying signature status.
608 * If invalid, the handle error code will be set accordingly.
609 * @param db pointer to the package database
610 * @return 0 if valid, -1 if invalid (pm_errno is set accordingly)
612 int alpm_db_get_valid(alpm_db_t
*db
);
614 /** @name Accessors to the list of servers for a database.
617 alpm_list_t
*alpm_db_get_servers(const alpm_db_t
*db
);
618 int alpm_db_set_servers(alpm_db_t
*db
, alpm_list_t
*servers
);
619 int alpm_db_add_server(alpm_db_t
*db
, const char *url
);
620 int alpm_db_remove_server(alpm_db_t
*db
, const char *url
);
623 int alpm_db_update(int level
, alpm_db_t
*db
);
625 /** Get a package entry from a package database.
626 * @param db pointer to the package database to get the package from
627 * @param name of the package
628 * @return the package entry on success, NULL on error
630 alpm_pkg_t
*alpm_db_get_pkg(alpm_db_t
*db
, const char *name
);
632 /** Get the package cache of a package database.
633 * @param db pointer to the package database to get the package from
634 * @return the list of packages on success, NULL on error
636 alpm_list_t
*alpm_db_get_pkgcache(alpm_db_t
*db
);
638 /** Get a group entry from a package database.
639 * @param db pointer to the package database to get the group from
640 * @param name of the group
641 * @return the groups entry on success, NULL on error
643 alpm_group_t
*alpm_db_readgroup(alpm_db_t
*db
, const char *name
);
645 /** Get the group cache of a package database.
646 * @param db pointer to the package database to get the group from
647 * @return the list of groups on success, NULL on error
649 alpm_list_t
*alpm_db_get_groupcache(alpm_db_t
*db
);
651 /** Searches a database with regular expressions.
652 * @param db pointer to the package database to search in
653 * @param needles a list of regular expressions to search for
654 * @return the list of packages matching all regular expressions on success, NULL on error
656 alpm_list_t
*alpm_db_search(alpm_db_t
*db
, const alpm_list_t
* needles
);
658 /** Set install reason for a package in db.
659 * @param handle the context handle
660 * @param pkg the package to update
661 * @param reason the new install reason
662 * @return 0 on success, -1 on error (pm_errno is set accordingly)
664 int alpm_db_set_pkgreason(alpm_handle_t
*handle
, alpm_pkg_t
*pkg
,
665 alpm_pkgreason_t reason
);
669 /** @addtogroup alpm_api_packages Package Functions
670 * Functions to manipulate libalpm packages
674 /** Create a package from a file.
675 * If full is false, the archive is read only until all necessary
676 * metadata is found. If it is true, the entire archive is read, which
677 * serves as a verification of integrity and the filelist can be created.
678 * The allocated structure should be freed using alpm_pkg_free().
679 * @param handle the context handle
680 * @param filename location of the package tarball
681 * @param full whether to stop the load after metadata is read or continue
682 * through the full archive
683 * @param level what level of package signature checking to perform on the
684 * package; note that this must be a '.sig' file type verification
685 * @param pkg address of the package pointer
686 * @return 0 on success, -1 on error (pm_errno is set accordingly)
688 int alpm_pkg_load(alpm_handle_t
*handle
, const char *filename
, int full
,
689 alpm_siglevel_t level
, alpm_pkg_t
**pkg
);
692 * @param pkg package pointer to free
693 * @return 0 on success, -1 on error (pm_errno is set accordingly)
695 int alpm_pkg_free(alpm_pkg_t
*pkg
);
697 /** Check the integrity (with md5) of a package from the sync cache.
698 * @param pkg package pointer
699 * @return 0 on success, -1 on error (pm_errno is set accordingly)
701 int alpm_pkg_checkmd5sum(alpm_pkg_t
*pkg
);
703 /** Compare two version strings and determine which one is 'newer'. */
704 int alpm_pkg_vercmp(const char *a
, const char *b
);
706 /** Computes the list of packages requiring a given package.
707 * The return value of this function is a newly allocated
708 * list of package names (char*), it should be freed by the caller.
709 * @param pkg a package
710 * @return the list of packages requiring pkg
712 alpm_list_t
*alpm_pkg_compute_requiredby(alpm_pkg_t
*pkg
);
714 /** @name Package Property Accessors
715 * Any pointer returned by these functions points to internal structures
716 * allocated by libalpm. They should not be freed nor modified in any
721 /** Gets the name of the file from which the package was loaded.
722 * @param pkg a pointer to package
723 * @return a reference to an internal string
725 const char *alpm_pkg_get_filename(alpm_pkg_t
*pkg
);
727 /** Returns the package name.
728 * @param pkg a pointer to package
729 * @return a reference to an internal string
731 const char *alpm_pkg_get_name(alpm_pkg_t
*pkg
);
733 /** Returns the package version as a string.
734 * This includes all available epoch, version, and pkgrel components. Use
735 * alpm_pkg_vercmp() to compare version strings if necessary.
736 * @param pkg a pointer to package
737 * @return a reference to an internal string
739 const char *alpm_pkg_get_version(alpm_pkg_t
*pkg
);
741 /** Returns the origin of the package.
742 * @return an alpm_pkgfrom_t constant, -1 on error
744 alpm_pkgfrom_t
alpm_pkg_get_origin(alpm_pkg_t
*pkg
);
746 /** Returns the package description.
747 * @param pkg a pointer to package
748 * @return a reference to an internal string
750 const char *alpm_pkg_get_desc(alpm_pkg_t
*pkg
);
752 /** Returns the package URL.
753 * @param pkg a pointer to package
754 * @return a reference to an internal string
756 const char *alpm_pkg_get_url(alpm_pkg_t
*pkg
);
758 /** Returns the build timestamp of the package.
759 * @param pkg a pointer to package
760 * @return the timestamp of the build time
762 alpm_time_t
alpm_pkg_get_builddate(alpm_pkg_t
*pkg
);
764 /** Returns the install timestamp of the package.
765 * @param pkg a pointer to package
766 * @return the timestamp of the install time
768 alpm_time_t
alpm_pkg_get_installdate(alpm_pkg_t
*pkg
);
770 /** Returns the packager's name.
771 * @param pkg a pointer to package
772 * @return a reference to an internal string
774 const char *alpm_pkg_get_packager(alpm_pkg_t
*pkg
);
776 /** Returns the package's MD5 checksum as a string.
777 * The returned string is a sequence of 32 lowercase hexadecimal digits.
778 * @param pkg a pointer to package
779 * @return a reference to an internal string
781 const char *alpm_pkg_get_md5sum(alpm_pkg_t
*pkg
);
783 /** Returns the package's SHA256 checksum as a string.
784 * The returned string is a sequence of 64 lowercase hexadecimal digits.
785 * @param pkg a pointer to package
786 * @return a reference to an internal string
788 const char *alpm_pkg_get_sha256sum(alpm_pkg_t
*pkg
);
790 /** Returns the architecture for which the package was built.
791 * @param pkg a pointer to package
792 * @return a reference to an internal string
794 const char *alpm_pkg_get_arch(alpm_pkg_t
*pkg
);
796 /** Returns the size of the package. This is only available for sync database
797 * packages and package files, not those loaded from the local database.
798 * @param pkg a pointer to package
799 * @return the size of the package in bytes.
801 off_t
alpm_pkg_get_size(alpm_pkg_t
*pkg
);
803 /** Returns the installed size of the package.
804 * @param pkg a pointer to package
805 * @return the total size of files installed by the package.
807 off_t
alpm_pkg_get_isize(alpm_pkg_t
*pkg
);
809 /** Returns the package installation reason.
810 * @param pkg a pointer to package
811 * @return an enum member giving the install reason.
813 alpm_pkgreason_t
alpm_pkg_get_reason(alpm_pkg_t
*pkg
);
815 /** Returns the list of package licenses.
816 * @param pkg a pointer to package
817 * @return a pointer to an internal list of strings.
819 alpm_list_t
*alpm_pkg_get_licenses(alpm_pkg_t
*pkg
);
821 /** Returns the list of package groups.
822 * @param pkg a pointer to package
823 * @return a pointer to an internal list of strings.
825 alpm_list_t
*alpm_pkg_get_groups(alpm_pkg_t
*pkg
);
827 /** Returns the list of package dependencies as alpm_depend_t.
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_depends(alpm_pkg_t
*pkg
);
833 /** Returns the list of package optional dependencies.
834 * @param pkg a pointer to package
835 * @return a reference to an internal list of strings.
837 alpm_list_t
*alpm_pkg_get_optdepends(alpm_pkg_t
*pkg
);
839 /** Returns the list of packages conflicting with pkg.
840 * @param pkg a pointer to package
841 * @return a reference to an internal list of alpm_depend_t structures.
843 alpm_list_t
*alpm_pkg_get_conflicts(alpm_pkg_t
*pkg
);
845 /** Returns the list of packages provided 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_provides(alpm_pkg_t
*pkg
);
851 /** Returns the list of available deltas for pkg.
852 * @param pkg a pointer to package
853 * @return a reference to an internal list of strings.
855 alpm_list_t
*alpm_pkg_get_deltas(alpm_pkg_t
*pkg
);
857 /** Returns the list of packages to be replaced by pkg.
858 * @param pkg a pointer to package
859 * @return a reference to an internal list of alpm_depend_t structures.
861 alpm_list_t
*alpm_pkg_get_replaces(alpm_pkg_t
*pkg
);
863 /** Returns the list of files installed by pkg.
864 * The filenames are relative to the install root,
865 * and do not include leading slashes.
866 * @param pkg a pointer to package
867 * @return a pointer to a filelist object containing a count and an array of
868 * package file objects
870 alpm_filelist_t
*alpm_pkg_get_files(alpm_pkg_t
*pkg
);
872 /** Returns the list of files backed up when installing pkg.
873 * The elements of the returned list have the form
874 * "<filename>\t<md5sum>", where the given md5sum is that of
875 * the file as provided by the package.
876 * @param pkg a pointer to package
877 * @return a reference to an internal list of strings.
879 alpm_list_t
*alpm_pkg_get_backup(alpm_pkg_t
*pkg
);
881 /** Returns the database containing pkg.
882 * Returns a pointer to the alpm_db_t structure the package is
883 * originating from, or NULL if the package was loaded from a file.
884 * @param pkg a pointer to package
885 * @return a pointer to the DB containing pkg, or NULL.
887 alpm_db_t
*alpm_pkg_get_db(alpm_pkg_t
*pkg
);
889 /** Retuns the base64 encoded package signature.
890 * @param pkg a pointer to package
891 * @return a reference to an internal string
893 const char *alpm_pkg_get_base64_sig(alpm_pkg_t
*pkg
);
895 /* End of alpm_pkg_t accessors */
898 /** Open a package changelog for reading.
899 * Similar to fopen in functionality, except that the returned 'file
900 * stream' could really be from an archive as well as from the database.
901 * @param pkg the package to read the changelog of (either file or db)
902 * @return a 'file stream' to the package changelog
904 void *alpm_pkg_changelog_open(alpm_pkg_t
*pkg
);
906 /** Read data from an open changelog 'file stream'.
907 * Similar to fread in functionality, this function takes a buffer and
908 * amount of data to read. If an error occurs pm_errno will be set.
909 * @param ptr a buffer to fill with raw changelog data
910 * @param size the size of the buffer
911 * @param pkg the package that the changelog is being read from
912 * @param fp a 'file stream' to the package changelog
913 * @return the number of characters read, or 0 if there is no more data or an
916 size_t alpm_pkg_changelog_read(void *ptr
, size_t size
,
917 const alpm_pkg_t
*pkg
, void *fp
);
919 int alpm_pkg_changelog_close(const alpm_pkg_t
*pkg
, void *fp
);
921 /** Returns whether the package has an install scriptlet.
922 * @return 0 if FALSE, TRUE otherwise
924 int alpm_pkg_has_scriptlet(alpm_pkg_t
*pkg
);
926 /** Returns the size of download.
927 * Returns the size of the files that will be downloaded to install a
929 * @param newpkg the new package to upgrade to
930 * @return the size of the download
932 off_t
alpm_pkg_download_size(alpm_pkg_t
*newpkg
);
934 alpm_list_t
*alpm_pkg_unused_deltas(alpm_pkg_t
*pkg
);
936 /* End of alpm_pkg */
943 int alpm_pkg_check_pgp_signature(alpm_pkg_t
*pkg
, alpm_siglist_t
*siglist
);
945 int alpm_db_check_pgp_signature(alpm_db_t
*db
, alpm_siglist_t
*siglist
);
947 int alpm_siglist_cleanup(alpm_siglist_t
*siglist
);
953 alpm_list_t
*alpm_find_group_pkgs(alpm_list_t
*dbs
, const char *name
);
959 alpm_pkg_t
*alpm_sync_newversion(alpm_pkg_t
*pkg
, alpm_list_t
*dbs_sync
);
961 /** @addtogroup alpm_api_trans Transaction Functions
962 * Functions to manipulate libalpm transactions
966 /** Transaction flags */
967 typedef enum _alpm_transflag_t
{
968 /** Ignore dependency checks. */
969 ALPM_TRANS_FLAG_NODEPS
= 1,
970 /** Ignore file conflicts and overwrite files. */
971 ALPM_TRANS_FLAG_FORCE
= (1 << 1),
972 /** Delete files even if they are tagged as backup. */
973 ALPM_TRANS_FLAG_NOSAVE
= (1 << 2),
974 /** Ignore version numbers when checking dependencies. */
975 ALPM_TRANS_FLAG_NODEPVERSION
= (1 << 3),
976 /** Remove also any packages depending on a package being removed. */
977 ALPM_TRANS_FLAG_CASCADE
= (1 << 4),
978 /** Remove packages and their unneeded deps (not explicitly installed). */
979 ALPM_TRANS_FLAG_RECURSE
= (1 << 5),
980 /** Modify database but do not commit changes to the filesystem. */
981 ALPM_TRANS_FLAG_DBONLY
= (1 << 6),
982 /* (1 << 7) flag can go here */
983 /** Use ALPM_PKG_REASON_DEPEND when installing packages. */
984 ALPM_TRANS_FLAG_ALLDEPS
= (1 << 8),
985 /** Only download packages and do not actually install. */
986 ALPM_TRANS_FLAG_DOWNLOADONLY
= (1 << 9),
987 /** Do not execute install scriptlets after installing. */
988 ALPM_TRANS_FLAG_NOSCRIPTLET
= (1 << 10),
989 /** Ignore dependency conflicts. */
990 ALPM_TRANS_FLAG_NOCONFLICTS
= (1 << 11),
991 /* (1 << 12) flag can go here */
992 /** Do not install a package if it is already installed and up to date. */
993 ALPM_TRANS_FLAG_NEEDED
= (1 << 13),
994 /** Use ALPM_PKG_REASON_EXPLICIT when installing packages. */
995 ALPM_TRANS_FLAG_ALLEXPLICIT
= (1 << 14),
996 /** Do not remove a package if it is needed by another one. */
997 ALPM_TRANS_FLAG_UNNEEDED
= (1 << 15),
998 /** Remove also explicitly installed unneeded deps (use with ALPM_TRANS_FLAG_RECURSE). */
999 ALPM_TRANS_FLAG_RECURSEALL
= (1 << 16),
1000 /** Do not lock the database during the operation. */
1001 ALPM_TRANS_FLAG_NOLOCK
= (1 << 17)
1004 /** Returns the bitfield of flags for the current transaction.
1005 * @param handle the context handle
1006 * @return the bitfield of transaction flags
1008 alpm_transflag_t
alpm_trans_get_flags(alpm_handle_t
*handle
);
1010 /** Returns a list of packages added by the transaction.
1011 * @param handle the context handle
1012 * @return a list of alpm_pkg_t structures
1014 alpm_list_t
*alpm_trans_get_add(alpm_handle_t
*handle
);
1016 /** Returns the list of packages removed by the transaction.
1017 * @param handle the context handle
1018 * @return a list of alpm_pkg_t structures
1020 alpm_list_t
*alpm_trans_get_remove(alpm_handle_t
*handle
);
1022 /** Initialize the transaction.
1023 * @param handle the context handle
1024 * @param flags flags of the transaction (like nodeps, etc)
1025 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1027 int alpm_trans_init(alpm_handle_t
*handle
, alpm_transflag_t flags
);
1029 /** Prepare a transaction.
1030 * @param handle the context handle
1031 * @param data the address of an alpm_list where a list
1032 * of alpm_depmissing_t objects is dumped (conflicting packages)
1033 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1035 int alpm_trans_prepare(alpm_handle_t
*handle
, alpm_list_t
**data
);
1037 /** Commit a transaction.
1038 * @param handle the context handle
1039 * @param data the address of an alpm_list where detailed description
1040 * of an error can be dumped (ie. list of conflicting files)
1041 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1043 int alpm_trans_commit(alpm_handle_t
*handle
, alpm_list_t
**data
);
1045 /** Interrupt a transaction.
1046 * @param handle the context handle
1047 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1049 int alpm_trans_interrupt(alpm_handle_t
*handle
);
1051 /** Release a transaction.
1052 * @param handle the context handle
1053 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1055 int alpm_trans_release(alpm_handle_t
*handle
);
1058 /** @name Common Transactions */
1061 /** Search for packages to upgrade and add them to the transaction.
1062 * @param handle the context handle
1063 * @param enable_downgrade allow downgrading of packages if the remote version is lower
1064 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1066 int alpm_sync_sysupgrade(alpm_handle_t
*handle
, int enable_downgrade
);
1068 /** Add a package to the transaction.
1069 * If the package was loaded by alpm_pkg_load(), it will be freed upon
1070 * alpm_trans_release() invocation.
1071 * @param handle the context handle
1072 * @param pkg the package to add
1073 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1075 int alpm_add_pkg(alpm_handle_t
*handle
, alpm_pkg_t
*pkg
);
1077 /** Add a package removal action to the transaction.
1078 * @param handle the context handle
1079 * @param pkg the package to uninstall
1080 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1082 int alpm_remove_pkg(alpm_handle_t
*handle
, alpm_pkg_t
*pkg
);
1086 /** @addtogroup alpm_api_depends Dependency Functions
1087 * Functions dealing with libalpm representation of dependency
1092 alpm_list_t
*alpm_checkdeps(alpm_handle_t
*handle
, alpm_list_t
*pkglist
,
1093 alpm_list_t
*remove
, alpm_list_t
*upgrade
, int reversedeps
);
1094 alpm_pkg_t
*alpm_find_satisfier(alpm_list_t
*pkgs
, const char *depstring
);
1095 alpm_pkg_t
*alpm_find_dbs_satisfier(alpm_handle_t
*handle
,
1096 alpm_list_t
*dbs
, const char *depstring
);
1098 alpm_list_t
*alpm_checkconflicts(alpm_handle_t
*handle
, alpm_list_t
*pkglist
);
1100 /** Returns a newly allocated string representing the dependency information.
1101 * @param dep a dependency info structure
1102 * @return a formatted string, e.g. "glibc>=2.12"
1104 char *alpm_dep_compute_string(const alpm_depend_t
*dep
);
1115 char *alpm_compute_md5sum(const char *name
);
1116 char *alpm_compute_sha256sum(const char *filename
);
1118 /** @addtogroup alpm_api_errors Error Codes
1121 typedef enum _alpm_errno_t
{
1122 ALPM_ERR_MEMORY
= 1,
1125 ALPM_ERR_NOT_A_FILE
,
1127 ALPM_ERR_WRONG_ARGS
,
1128 ALPM_ERR_DISK_SPACE
,
1130 ALPM_ERR_HANDLE_NULL
,
1131 ALPM_ERR_HANDLE_NOT_NULL
,
1132 ALPM_ERR_HANDLE_LOCK
,
1137 ALPM_ERR_DB_NOT_NULL
,
1138 ALPM_ERR_DB_NOT_FOUND
,
1139 ALPM_ERR_DB_INVALID
,
1140 ALPM_ERR_DB_INVALID_SIG
,
1141 ALPM_ERR_DB_VERSION
,
1145 ALPM_ERR_SERVER_BAD_URL
,
1146 ALPM_ERR_SERVER_NONE
,
1148 ALPM_ERR_TRANS_NOT_NULL
,
1149 ALPM_ERR_TRANS_NULL
,
1150 ALPM_ERR_TRANS_DUP_TARGET
,
1151 ALPM_ERR_TRANS_NOT_INITIALIZED
,
1152 ALPM_ERR_TRANS_NOT_PREPARED
,
1153 ALPM_ERR_TRANS_ABORT
,
1154 ALPM_ERR_TRANS_TYPE
,
1155 ALPM_ERR_TRANS_NOT_LOCKED
,
1157 ALPM_ERR_PKG_NOT_FOUND
,
1158 ALPM_ERR_PKG_IGNORED
,
1159 ALPM_ERR_PKG_INVALID
,
1160 ALPM_ERR_PKG_INVALID_CHECKSUM
,
1161 ALPM_ERR_PKG_INVALID_SIG
,
1163 ALPM_ERR_PKG_CANT_REMOVE
,
1164 ALPM_ERR_PKG_INVALID_NAME
,
1165 ALPM_ERR_PKG_INVALID_ARCH
,
1166 ALPM_ERR_PKG_REPO_NOT_FOUND
,
1168 ALPM_ERR_SIG_MISSING
,
1169 ALPM_ERR_SIG_INVALID
,
1171 ALPM_ERR_DLT_INVALID
,
1172 ALPM_ERR_DLT_PATCHFAILED
,
1174 ALPM_ERR_UNSATISFIED_DEPS
,
1175 ALPM_ERR_CONFLICTING_DEPS
,
1176 ALPM_ERR_FILE_CONFLICTS
,
1179 ALPM_ERR_INVALID_REGEX
,
1180 /* External library errors */
1181 ALPM_ERR_LIBARCHIVE
,
1183 ALPM_ERR_EXTERNAL_DOWNLOAD
,
1187 /** Returns the current error code from the handle. */
1188 alpm_errno_t
alpm_errno(alpm_handle_t
*handle
);
1190 /** Returns the string corresponding to an error number. */
1191 const char *alpm_strerror(alpm_errno_t err
);
1193 /* End of alpm_api_errors */
1196 alpm_handle_t
*alpm_initialize(const char *root
, const char *dbpath
,
1198 int alpm_release(alpm_handle_t
*handle
);
1201 ALPM_CAPABILITY_NLS
= (1 << 0),
1202 ALPM_CAPABILITY_DOWNLOADER
= (1 << 1),
1203 ALPM_CAPABILITY_SIGNATURES
= (1 << 2)
1206 const char *alpm_version(void);
1207 enum alpm_caps
alpm_capabilities(void);
1209 /* End of alpm_api */
1215 #endif /* _ALPM_H */
1217 /* vim: set ts=2 sw=2 noet: */