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
{
62 ALPM_PKG_FROM_FILE
= 1,
63 ALPM_PKG_FROM_LOCALDB
,
67 /** Location a package object was loaded from. */
68 typedef enum _alpm_pkgvalidation_t
{
69 ALPM_PKG_VALIDATION_UNKNOWN
= 0,
70 ALPM_PKG_VALIDATION_NONE
= (1 << 0),
71 ALPM_PKG_VALIDATION_MD5SUM
= (1 << 1),
72 ALPM_PKG_VALIDATION_SHA256SUM
= (1 << 2),
73 ALPM_PKG_VALIDATION_SIGNATURE
= (1 << 3)
74 } alpm_pkgvalidation_t
;
76 /** Types of version constraints in dependency specs. */
77 typedef enum _alpm_depmod_t
{
78 /** No version constraint */
80 /** Test version equality (package=x.y.z) */
82 /** Test for at least a version (package>=x.y.z) */
84 /** Test for at most a version (package<=x.y.z) */
86 /** Test for greater than some version (package>x.y.z) */
88 /** Test for less than some version (package<x.y.z) */
94 * Whether the conflict results from a file existing on the filesystem, or with
95 * another target in the transaction.
97 typedef enum _alpm_fileconflicttype_t
{
98 ALPM_FILECONFLICT_TARGET
= 1,
99 ALPM_FILECONFLICT_FILESYSTEM
100 } alpm_fileconflicttype_t
;
102 /** PGP signature verification options */
103 typedef enum _alpm_siglevel_t
{
104 ALPM_SIG_PACKAGE
= (1 << 0),
105 ALPM_SIG_PACKAGE_OPTIONAL
= (1 << 1),
106 ALPM_SIG_PACKAGE_MARGINAL_OK
= (1 << 2),
107 ALPM_SIG_PACKAGE_UNKNOWN_OK
= (1 << 3),
109 ALPM_SIG_DATABASE
= (1 << 10),
110 ALPM_SIG_DATABASE_OPTIONAL
= (1 << 11),
111 ALPM_SIG_DATABASE_MARGINAL_OK
= (1 << 12),
112 ALPM_SIG_DATABASE_UNKNOWN_OK
= (1 << 13),
114 ALPM_SIG_USE_DEFAULT
= (1 << 31)
117 /** PGP signature verification status return codes */
118 typedef enum _alpm_sigstatus_t
{
119 ALPM_SIGSTATUS_VALID
,
120 ALPM_SIGSTATUS_KEY_EXPIRED
,
121 ALPM_SIGSTATUS_SIG_EXPIRED
,
122 ALPM_SIGSTATUS_KEY_UNKNOWN
,
123 ALPM_SIGSTATUS_KEY_DISABLED
,
124 ALPM_SIGSTATUS_INVALID
127 /** PGP signature verification status return codes */
128 typedef enum _alpm_sigvalidity_t
{
129 ALPM_SIGVALIDITY_FULL
,
130 ALPM_SIGVALIDITY_MARGINAL
,
131 ALPM_SIGVALIDITY_NEVER
,
132 ALPM_SIGVALIDITY_UNKNOWN
133 } alpm_sigvalidity_t
;
139 typedef struct __alpm_handle_t alpm_handle_t
;
140 typedef struct __alpm_db_t alpm_db_t
;
141 typedef struct __alpm_pkg_t alpm_pkg_t
;
142 typedef struct __alpm_trans_t alpm_trans_t
;
145 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 only in the case of a remove dependency error */
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
;
235 * Signature result. Contains the key, status, and validity of a given
238 typedef struct _alpm_sigresult_t
{
240 alpm_sigstatus_t status
;
241 alpm_sigvalidity_t validity
;
245 * Signature list. Contains the number of signatures found and a pointer to an
246 * array of results. The array is of size count.
248 typedef struct _alpm_siglist_t
{
250 alpm_sigresult_t
*results
;
257 /** Logging Levels */
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
, ...);
270 * NULL parameters are passed to in all events unless specified otherwise.
272 typedef enum _alpm_event_t
{
273 /** Dependencies will be computed for a package. */
274 ALPM_EVENT_CHECKDEPS_START
= 1,
275 /** Dependencies were computed for a package. */
276 ALPM_EVENT_CHECKDEPS_DONE
,
277 /** File conflicts will be computed for a package. */
278 ALPM_EVENT_FILECONFLICTS_START
,
279 /** File conflicts were computed for a package. */
280 ALPM_EVENT_FILECONFLICTS_DONE
,
281 /** Dependencies will be resolved for target package. */
282 ALPM_EVENT_RESOLVEDEPS_START
,
283 /** Dependencies were resolved for target package. */
284 ALPM_EVENT_RESOLVEDEPS_DONE
,
285 /** Inter-conflicts will be checked for target package. */
286 ALPM_EVENT_INTERCONFLICTS_START
,
287 /** Inter-conflicts were checked for target package. */
288 ALPM_EVENT_INTERCONFLICTS_DONE
,
289 /** Package will be installed.
290 * A pointer to the target package is passed to the callback.
292 ALPM_EVENT_ADD_START
,
293 /** Package was installed.
294 * A pointer to the new package is passed to the callback.
297 /** Package will be removed.
298 * A pointer to the target package is passed to the callback.
300 ALPM_EVENT_REMOVE_START
,
301 /** Package was removed.
302 * A pointer to the removed package is passed to the callback.
304 ALPM_EVENT_REMOVE_DONE
,
305 /** Package will be upgraded.
306 * A pointer to the upgraded package is passed to the callback.
308 ALPM_EVENT_UPGRADE_START
,
309 /** Package was upgraded.
310 * A pointer to the new package, and a pointer to the old package is passed
311 * to the callback, respectively.
313 ALPM_EVENT_UPGRADE_DONE
,
314 /** Target package's integrity will be checked. */
315 ALPM_EVENT_INTEGRITY_START
,
316 /** Target package's integrity was checked. */
317 ALPM_EVENT_INTEGRITY_DONE
,
318 /** Target package will be loaded. */
319 ALPM_EVENT_LOAD_START
,
320 /** Target package is finished loading. */
321 ALPM_EVENT_LOAD_DONE
,
322 /** Target delta's integrity will be checked. */
323 ALPM_EVENT_DELTA_INTEGRITY_START
,
324 /** Target delta's integrity was checked. */
325 ALPM_EVENT_DELTA_INTEGRITY_DONE
,
326 /** Deltas will be applied to packages. */
327 ALPM_EVENT_DELTA_PATCHES_START
,
328 /** Deltas were applied to packages. */
329 ALPM_EVENT_DELTA_PATCHES_DONE
,
330 /** Delta patch will be applied to target package.
331 * The filename of the package and the filename of the patch is passed to the
334 ALPM_EVENT_DELTA_PATCH_START
,
335 /** Delta patch was applied to target package. */
336 ALPM_EVENT_DELTA_PATCH_DONE
,
337 /** Delta patch failed to apply to target package. */
338 ALPM_EVENT_DELTA_PATCH_FAILED
,
339 /** Scriptlet has printed information.
340 * A line of text is passed to the callback.
342 ALPM_EVENT_SCRIPTLET_INFO
,
343 /** Files will be downloaded from a repository.
344 * The repository's tree name is passed to the callback.
346 ALPM_EVENT_RETRIEVE_START
,
347 /** Disk space usage will be computed for a package */
348 ALPM_EVENT_DISKSPACE_START
,
349 /** Disk space usage was computed for a package */
350 ALPM_EVENT_DISKSPACE_DONE
353 /** Event callback */
354 typedef void (*alpm_cb_event
)(alpm_event_t
, void *, void *);
358 * Unlike the events or progress enumerations, this enum has bitmask values
359 * so a frontend can use a bitmask map to supply preselected answers to the
360 * different types of questions.
362 typedef enum _alpm_question_t
{
363 ALPM_QUESTION_INSTALL_IGNOREPKG
= 1,
364 ALPM_QUESTION_REPLACE_PKG
= (1 << 1),
365 ALPM_QUESTION_CONFLICT_PKG
= (1 << 2),
366 ALPM_QUESTION_CORRUPTED_PKG
= (1 << 3),
367 ALPM_QUESTION_LOCAL_NEWER
= (1 << 4),
368 ALPM_QUESTION_REMOVE_PKGS
= (1 << 5),
369 ALPM_QUESTION_SELECT_PROVIDER
= (1 << 6),
370 ALPM_QUESTION_IMPORT_KEY
= (1 << 7)
373 /** Question callback */
374 typedef void (*alpm_cb_question
)(alpm_question_t
, void *, void *, void *, int *);
377 typedef enum _alpm_progress_t
{
378 ALPM_PROGRESS_ADD_START
,
379 ALPM_PROGRESS_UPGRADE_START
,
380 ALPM_PROGRESS_REMOVE_START
,
381 ALPM_PROGRESS_CONFLICTS_START
,
382 ALPM_PROGRESS_DISKSPACE_START
,
383 ALPM_PROGRESS_INTEGRITY_START
,
384 ALPM_PROGRESS_LOAD_START
387 /** Progress callback */
388 typedef void (*alpm_cb_progress
)(alpm_progress_t
, const char *, int, size_t, size_t);
394 /** Type of download progress callbacks.
395 * @param filename the name of the file being downloaded
396 * @param xfered the number of transferred bytes
397 * @param total the total number of bytes to transfer
399 typedef void (*alpm_cb_download
)(const char *filename
,
400 off_t xfered
, off_t total
);
402 typedef void (*alpm_cb_totaldl
)(off_t total
);
404 /** A callback for downloading files
405 * @param url the URL of the file to be downloaded
406 * @param localpath the directory to which the file should be downloaded
407 * @param force whether to force an update, even if the file is the same
408 * @return 0 on success, 1 if the file exists and is identical, -1 on
411 typedef int (*alpm_cb_fetch
)(const char *url
, const char *localpath
,
414 /** Fetch a remote pkg.
415 * @param handle the context handle
416 * @param url URL of the package to download
417 * @return the downloaded filepath on success, NULL on error
419 char *alpm_fetch_pkgurl(alpm_handle_t
*handle
, const char *url
);
421 /** @addtogroup alpm_api_options Options
422 * Libalpm option getters and setters
426 /** Returns the callback used for logging. */
427 alpm_cb_log
alpm_option_get_logcb(alpm_handle_t
*handle
);
428 /** Sets the callback used for logging. */
429 int alpm_option_set_logcb(alpm_handle_t
*handle
, alpm_cb_log cb
);
431 /** Returns the callback used to report download progress. */
432 alpm_cb_download
alpm_option_get_dlcb(alpm_handle_t
*handle
);
433 /** Sets the callback used to report download progress. */
434 int alpm_option_set_dlcb(alpm_handle_t
*handle
, alpm_cb_download cb
);
436 /** Returns the downloading callback. */
437 alpm_cb_fetch
alpm_option_get_fetchcb(alpm_handle_t
*handle
);
438 /** Sets the downloading callback. */
439 int alpm_option_set_fetchcb(alpm_handle_t
*handle
, alpm_cb_fetch cb
);
441 /** Returns the callback used to report total download size. */
442 alpm_cb_totaldl
alpm_option_get_totaldlcb(alpm_handle_t
*handle
);
443 /** Sets the callback used to report total download size. */
444 int alpm_option_set_totaldlcb(alpm_handle_t
*handle
, alpm_cb_totaldl cb
);
446 /** Returns the callback used for events. */
447 alpm_cb_event
alpm_option_get_eventcb(alpm_handle_t
*handle
);
448 /** Sets the callback used for events. */
449 int alpm_option_set_eventcb(alpm_handle_t
*handle
, alpm_cb_event cb
);
451 /** Returns the callback used for questions. */
452 alpm_cb_question
alpm_option_get_questioncb(alpm_handle_t
*handle
);
453 /** Sets the callback used for questions. */
454 int alpm_option_set_questioncb(alpm_handle_t
*handle
, alpm_cb_question cb
);
456 /** Returns the callback used for operation progress. */
457 alpm_cb_progress
alpm_option_get_progresscb(alpm_handle_t
*handle
);
458 /** Sets the callback used for operation progress. */
459 int alpm_option_set_progresscb(alpm_handle_t
*handle
, alpm_cb_progress cb
);
461 /** Returns the root of the destination filesystem. Read-only. */
462 const char *alpm_option_get_root(alpm_handle_t
*handle
);
464 /** Returns the path to the database directory. Read-only. */
465 const char *alpm_option_get_dbpath(alpm_handle_t
*handle
);
467 /** Get the name of the database lock file. Read-only. */
468 const char *alpm_option_get_lockfile(alpm_handle_t
*handle
);
470 /** @name Accessors to the list of package cache directories.
473 alpm_list_t
*alpm_option_get_cachedirs(alpm_handle_t
*handle
);
474 int alpm_option_set_cachedirs(alpm_handle_t
*handle
, alpm_list_t
*cachedirs
);
475 int alpm_option_add_cachedir(alpm_handle_t
*handle
, const char *cachedir
);
476 int alpm_option_remove_cachedir(alpm_handle_t
*handle
, const char *cachedir
);
479 /** Returns the logfile name. */
480 const char *alpm_option_get_logfile(alpm_handle_t
*handle
);
481 /** Sets the logfile name. */
482 int alpm_option_set_logfile(alpm_handle_t
*handle
, const char *logfile
);
484 /** Returns the path to libalpm's GnuPG home directory. */
485 const char *alpm_option_get_gpgdir(alpm_handle_t
*handle
);
486 /** Sets the path to libalpm's GnuPG home directory. */
487 int alpm_option_set_gpgdir(alpm_handle_t
*handle
, const char *gpgdir
);
489 /** Returns whether to use syslog (0 is FALSE, TRUE otherwise). */
490 int alpm_option_get_usesyslog(alpm_handle_t
*handle
);
491 /** Sets whether to use syslog (0 is FALSE, TRUE otherwise). */
492 int alpm_option_set_usesyslog(alpm_handle_t
*handle
, int usesyslog
);
494 /** @name Accessors to the list of no-upgrade files.
495 * These functions modify the list of files which should
496 * not be updated by package installation.
499 alpm_list_t
*alpm_option_get_noupgrades(alpm_handle_t
*handle
);
500 int alpm_option_add_noupgrade(alpm_handle_t
*handle
, const char *pkg
);
501 int alpm_option_set_noupgrades(alpm_handle_t
*handle
, alpm_list_t
*noupgrade
);
502 int alpm_option_remove_noupgrade(alpm_handle_t
*handle
, const char *pkg
);
505 /** @name Accessors to the list of no-extract files.
506 * These functions modify the list of filenames which should
507 * be skipped packages which should
508 * not be upgraded by a sysupgrade operation.
511 alpm_list_t
*alpm_option_get_noextracts(alpm_handle_t
*handle
);
512 int alpm_option_add_noextract(alpm_handle_t
*handle
, const char *pkg
);
513 int alpm_option_set_noextracts(alpm_handle_t
*handle
, alpm_list_t
*noextract
);
514 int alpm_option_remove_noextract(alpm_handle_t
*handle
, const char *pkg
);
517 /** @name Accessors to the list of ignored packages.
518 * These functions modify the list of packages that
519 * should be ignored by a sysupgrade.
522 alpm_list_t
*alpm_option_get_ignorepkgs(alpm_handle_t
*handle
);
523 int alpm_option_add_ignorepkg(alpm_handle_t
*handle
, const char *pkg
);
524 int alpm_option_set_ignorepkgs(alpm_handle_t
*handle
, alpm_list_t
*ignorepkgs
);
525 int alpm_option_remove_ignorepkg(alpm_handle_t
*handle
, const char *pkg
);
528 /** @name Accessors to the list of ignored groups.
529 * These functions modify the list of groups whose packages
530 * should be ignored by a sysupgrade.
533 alpm_list_t
*alpm_option_get_ignoregroups(alpm_handle_t
*handle
);
534 int alpm_option_add_ignoregroup(alpm_handle_t
*handle
, const char *grp
);
535 int alpm_option_set_ignoregroups(alpm_handle_t
*handle
, alpm_list_t
*ignoregrps
);
536 int alpm_option_remove_ignoregroup(alpm_handle_t
*handle
, const char *grp
);
539 /** Returns the targeted architecture. */
540 const char *alpm_option_get_arch(alpm_handle_t
*handle
);
541 /** Sets the targeted architecture. */
542 int alpm_option_set_arch(alpm_handle_t
*handle
, const char *arch
);
544 double alpm_option_get_deltaratio(alpm_handle_t
*handle
);
545 int alpm_option_set_deltaratio(alpm_handle_t
*handle
, double ratio
);
547 int alpm_option_get_checkspace(alpm_handle_t
*handle
);
548 int alpm_option_set_checkspace(alpm_handle_t
*handle
, int checkspace
);
550 alpm_siglevel_t
alpm_option_get_default_siglevel(alpm_handle_t
*handle
);
551 int alpm_option_set_default_siglevel(alpm_handle_t
*handle
, alpm_siglevel_t level
);
555 /** @addtogroup alpm_api_databases Database Functions
556 * Functions to query and manipulate the database of libalpm.
560 /** Get the database of locally installed packages.
561 * The returned pointer points to an internal structure
562 * of libalpm which should only be manipulated through
564 * @return a reference to the local database
566 alpm_db_t
*alpm_get_localdb(alpm_handle_t
*handle
);
568 /** Get the list of sync databases.
569 * Returns a list of alpm_db_t structures, one for each registered
571 * @param handle the context handle
572 * @return a reference to an internal list of alpm_db_t structures
574 alpm_list_t
*alpm_get_syncdbs(alpm_handle_t
*handle
);
576 /** Register a sync database of packages.
577 * @param handle the context handle
578 * @param treename the name of the sync repository
579 * @param level what level of signature checking to perform on the
580 * database; note that this must be a '.sig' file type verification
581 * @return an alpm_db_t* on success (the value), NULL on error
583 alpm_db_t
*alpm_register_syncdb(alpm_handle_t
*handle
, const char *treename
,
584 alpm_siglevel_t level
);
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_unregister_all_syncdbs(alpm_handle_t
*handle
);
592 /** Unregister a package database.
593 * @param db pointer to the package database to unregister
594 * @return 0 on success, -1 on error (pm_errno is set accordingly)
596 int alpm_db_unregister(alpm_db_t
*db
);
598 /** Get the name of a package database.
599 * @param db pointer to the package database
600 * @return the name of the package database, NULL on error
602 const char *alpm_db_get_name(const alpm_db_t
*db
);
604 /** Get the signature verification level for a database.
605 * Will return the default verification level if this database is set up
606 * with ALPM_SIG_USE_DEFAULT.
607 * @param db pointer to the package database
608 * @return the signature verification level
610 alpm_siglevel_t
alpm_db_get_siglevel(alpm_db_t
*db
);
612 /** Check the validity of a database.
613 * This is most useful for sync databases and verifying signature status.
614 * If invalid, the handle error code will be set accordingly.
615 * @param db pointer to the package database
616 * @return 0 if valid, -1 if invalid (pm_errno is set accordingly)
618 int alpm_db_get_valid(alpm_db_t
*db
);
620 /** @name Accessors to the list of servers for a database.
623 alpm_list_t
*alpm_db_get_servers(const alpm_db_t
*db
);
624 int alpm_db_set_servers(alpm_db_t
*db
, alpm_list_t
*servers
);
625 int alpm_db_add_server(alpm_db_t
*db
, const char *url
);
626 int alpm_db_remove_server(alpm_db_t
*db
, const char *url
);
629 int alpm_db_update(int force
, alpm_db_t
*db
);
631 /** Get a package entry from a package database.
632 * @param db pointer to the package database to get the package from
633 * @param name of the package
634 * @return the package entry on success, NULL on error
636 alpm_pkg_t
*alpm_db_get_pkg(alpm_db_t
*db
, const char *name
);
638 /** Get the package cache of a package database.
639 * @param db pointer to the package database to get the package from
640 * @return the list of packages on success, NULL on error
642 alpm_list_t
*alpm_db_get_pkgcache(alpm_db_t
*db
);
644 /** Get a group entry from a package database.
645 * @param db pointer to the package database to get the group from
646 * @param name of the group
647 * @return the groups entry on success, NULL on error
649 alpm_group_t
*alpm_db_get_group(alpm_db_t
*db
, const char *name
);
651 /** Get the group cache of a package database.
652 * @param db pointer to the package database to get the group from
653 * @return the list of groups on success, NULL on error
655 alpm_list_t
*alpm_db_get_groupcache(alpm_db_t
*db
);
657 /** Searches a database with regular expressions.
658 * @param db pointer to the package database to search in
659 * @param needles a list of regular expressions to search for
660 * @return the list of packages matching all regular expressions on success, NULL on error
662 alpm_list_t
*alpm_db_search(alpm_db_t
*db
, const alpm_list_t
*needles
);
666 /** @addtogroup alpm_api_packages Package Functions
667 * Functions to manipulate libalpm packages
671 /** Create a package from a file.
672 * If full is false, the archive is read only until all necessary
673 * metadata is found. If it is true, the entire archive is read, which
674 * serves as a verification of integrity and the filelist can be created.
675 * The allocated structure should be freed using alpm_pkg_free().
676 * @param handle the context handle
677 * @param filename location of the package tarball
678 * @param full whether to stop the load after metadata is read or continue
679 * through the full archive
680 * @param level what level of package signature checking to perform on the
681 * package; note that this must be a '.sig' file type verification
682 * @param pkg address of the package pointer
683 * @return 0 on success, -1 on error (pm_errno is set accordingly)
685 int alpm_pkg_load(alpm_handle_t
*handle
, const char *filename
, int full
,
686 alpm_siglevel_t level
, alpm_pkg_t
**pkg
);
689 * @param pkg package pointer to free
690 * @return 0 on success, -1 on error (pm_errno is set accordingly)
692 int alpm_pkg_free(alpm_pkg_t
*pkg
);
694 /** Check the integrity (with md5) of a package from the sync cache.
695 * @param pkg package pointer
696 * @return 0 on success, -1 on error (pm_errno is set accordingly)
698 int alpm_pkg_checkmd5sum(alpm_pkg_t
*pkg
);
700 /** Compare two version strings and determine which one is 'newer'. */
701 int alpm_pkg_vercmp(const char *a
, const char *b
);
703 /** Computes the list of packages requiring a given package.
704 * The return value of this function is a newly allocated
705 * list of package names (char*), it should be freed by the caller.
706 * @param pkg a package
707 * @return the list of packages requiring pkg
709 alpm_list_t
*alpm_pkg_compute_requiredby(alpm_pkg_t
*pkg
);
711 /** @name Package Property Accessors
712 * Any pointer returned by these functions points to internal structures
713 * allocated by libalpm. They should not be freed nor modified in any
718 /** Gets the name of the file from which the package was loaded.
719 * @param pkg a pointer to package
720 * @return a reference to an internal string
722 const char *alpm_pkg_get_filename(alpm_pkg_t
*pkg
);
724 /** Returns the package name.
725 * @param pkg a pointer to package
726 * @return a reference to an internal string
728 const char *alpm_pkg_get_name(alpm_pkg_t
*pkg
);
730 /** Returns the package version as a string.
731 * This includes all available epoch, version, and pkgrel components. Use
732 * alpm_pkg_vercmp() to compare version strings if necessary.
733 * @param pkg a pointer to package
734 * @return a reference to an internal string
736 const char *alpm_pkg_get_version(alpm_pkg_t
*pkg
);
738 /** Returns the origin of the package.
739 * @return an alpm_pkgfrom_t constant, -1 on error
741 alpm_pkgfrom_t
alpm_pkg_get_origin(alpm_pkg_t
*pkg
);
743 /** Returns the package description.
744 * @param pkg a pointer to package
745 * @return a reference to an internal string
747 const char *alpm_pkg_get_desc(alpm_pkg_t
*pkg
);
749 /** Returns the package URL.
750 * @param pkg a pointer to package
751 * @return a reference to an internal string
753 const char *alpm_pkg_get_url(alpm_pkg_t
*pkg
);
755 /** Returns the build timestamp of the package.
756 * @param pkg a pointer to package
757 * @return the timestamp of the build time
759 alpm_time_t
alpm_pkg_get_builddate(alpm_pkg_t
*pkg
);
761 /** Returns the install timestamp of the package.
762 * @param pkg a pointer to package
763 * @return the timestamp of the install time
765 alpm_time_t
alpm_pkg_get_installdate(alpm_pkg_t
*pkg
);
767 /** Returns the packager's name.
768 * @param pkg a pointer to package
769 * @return a reference to an internal string
771 const char *alpm_pkg_get_packager(alpm_pkg_t
*pkg
);
773 /** Returns the package's MD5 checksum as a string.
774 * The returned string is a sequence of 32 lowercase hexadecimal digits.
775 * @param pkg a pointer to package
776 * @return a reference to an internal string
778 const char *alpm_pkg_get_md5sum(alpm_pkg_t
*pkg
);
780 /** Returns the package's SHA256 checksum as a string.
781 * The returned string is a sequence of 64 lowercase hexadecimal digits.
782 * @param pkg a pointer to package
783 * @return a reference to an internal string
785 const char *alpm_pkg_get_sha256sum(alpm_pkg_t
*pkg
);
787 /** Returns the architecture for which the package was built.
788 * @param pkg a pointer to package
789 * @return a reference to an internal string
791 const char *alpm_pkg_get_arch(alpm_pkg_t
*pkg
);
793 /** Returns the size of the package. This is only available for sync database
794 * packages and package files, not those loaded from the local database.
795 * @param pkg a pointer to package
796 * @return the size of the package in bytes.
798 off_t
alpm_pkg_get_size(alpm_pkg_t
*pkg
);
800 /** Returns the installed size of the package.
801 * @param pkg a pointer to package
802 * @return the total size of files installed by the package.
804 off_t
alpm_pkg_get_isize(alpm_pkg_t
*pkg
);
806 /** Returns the package installation reason.
807 * @param pkg a pointer to package
808 * @return an enum member giving the install reason.
810 alpm_pkgreason_t
alpm_pkg_get_reason(alpm_pkg_t
*pkg
);
812 /** Returns the list of package licenses.
813 * @param pkg a pointer to package
814 * @return a pointer to an internal list of strings.
816 alpm_list_t
*alpm_pkg_get_licenses(alpm_pkg_t
*pkg
);
818 /** Returns the list of package groups.
819 * @param pkg a pointer to package
820 * @return a pointer to an internal list of strings.
822 alpm_list_t
*alpm_pkg_get_groups(alpm_pkg_t
*pkg
);
824 /** Returns the list of package dependencies as alpm_depend_t.
825 * @param pkg a pointer to package
826 * @return a reference to an internal list of alpm_depend_t structures.
828 alpm_list_t
*alpm_pkg_get_depends(alpm_pkg_t
*pkg
);
830 /** Returns the list of package optional dependencies.
831 * @param pkg a pointer to package
832 * @return a reference to an internal list of alpm_depend_t structures.
834 alpm_list_t
*alpm_pkg_get_optdepends(alpm_pkg_t
*pkg
);
836 /** Returns the list of packages conflicting with pkg.
837 * @param pkg a pointer to package
838 * @return a reference to an internal list of alpm_depend_t structures.
840 alpm_list_t
*alpm_pkg_get_conflicts(alpm_pkg_t
*pkg
);
842 /** Returns the list of packages provided by pkg.
843 * @param pkg a pointer to package
844 * @return a reference to an internal list of alpm_depend_t structures.
846 alpm_list_t
*alpm_pkg_get_provides(alpm_pkg_t
*pkg
);
848 /** Returns the list of available deltas for pkg.
849 * @param pkg a pointer to package
850 * @return a reference to an internal list of strings.
852 alpm_list_t
*alpm_pkg_get_deltas(alpm_pkg_t
*pkg
);
854 /** Returns the list of packages to be replaced by pkg.
855 * @param pkg a pointer to package
856 * @return a reference to an internal list of alpm_depend_t structures.
858 alpm_list_t
*alpm_pkg_get_replaces(alpm_pkg_t
*pkg
);
860 /** Returns the list of files installed by pkg.
861 * The filenames are relative to the install root,
862 * and do not include leading slashes.
863 * @param pkg a pointer to package
864 * @return a pointer to a filelist object containing a count and an array of
865 * package file objects
867 alpm_filelist_t
*alpm_pkg_get_files(alpm_pkg_t
*pkg
);
869 /** Returns the list of files backed up when installing pkg.
870 * The elements of the returned list have the form
871 * "<filename>\t<md5sum>", where the given md5sum is that of
872 * the file as provided by the package.
873 * @param pkg a pointer to package
874 * @return a reference to a list of alpm_backup_t objects
876 alpm_list_t
*alpm_pkg_get_backup(alpm_pkg_t
*pkg
);
878 /** Returns the database containing pkg.
879 * Returns a pointer to the alpm_db_t structure the package is
880 * originating from, or NULL if the package was loaded from a file.
881 * @param pkg a pointer to package
882 * @return a pointer to the DB containing pkg, or NULL.
884 alpm_db_t
*alpm_pkg_get_db(alpm_pkg_t
*pkg
);
886 /** Returns the base64 encoded package signature.
887 * @param pkg a pointer to package
888 * @return a reference to an internal string
890 const char *alpm_pkg_get_base64_sig(alpm_pkg_t
*pkg
);
892 /** Returns the method used to validate a package during install.
893 * @param pkg a pointer to package
894 * @return an enum member giving the validation method
896 alpm_pkgvalidation_t
alpm_pkg_get_validation(alpm_pkg_t
*pkg
);
898 /* End of alpm_pkg_t accessors */
901 /** Open a package changelog for reading.
902 * Similar to fopen in functionality, except that the returned 'file
903 * stream' could really be from an archive as well as from the database.
904 * @param pkg the package to read the changelog of (either file or db)
905 * @return a 'file stream' to the package changelog
907 void *alpm_pkg_changelog_open(alpm_pkg_t
*pkg
);
909 /** Read data from an open changelog 'file stream'.
910 * Similar to fread in functionality, this function takes a buffer and
911 * amount of data to read. If an error occurs pm_errno will be set.
912 * @param ptr a buffer to fill with raw changelog data
913 * @param size the size of the buffer
914 * @param pkg the package that the changelog is being read from
915 * @param fp a 'file stream' to the package changelog
916 * @return the number of characters read, or 0 if there is no more data or an
919 size_t alpm_pkg_changelog_read(void *ptr
, size_t size
,
920 const alpm_pkg_t
*pkg
, void *fp
);
922 int alpm_pkg_changelog_close(const alpm_pkg_t
*pkg
, void *fp
);
924 /** Returns whether the package has an install scriptlet.
925 * @return 0 if FALSE, TRUE otherwise
927 int alpm_pkg_has_scriptlet(alpm_pkg_t
*pkg
);
929 /** Returns the size of download.
930 * Returns the size of the files that will be downloaded to install a
932 * @param newpkg the new package to upgrade to
933 * @return the size of the download
935 off_t
alpm_pkg_download_size(alpm_pkg_t
*newpkg
);
937 alpm_list_t
*alpm_pkg_unused_deltas(alpm_pkg_t
*pkg
);
939 /** Set install reason for a package in the local database.
940 * The provided package object must be from the local database or this method
941 * will fail. The write to the local database is performed immediately.
942 * @param pkg the package to update
943 * @param reason the new install reason
944 * @return 0 on success, -1 on error (pm_errno is set accordingly)
946 int alpm_pkg_set_reason(alpm_pkg_t
*pkg
, alpm_pkgreason_t reason
);
949 /* End of alpm_pkg */
956 /** Determines whether a package filelist contains a given path.
957 * The provided path should be relative to the install root with no leading
958 * slashes, e.g. "etc/localtime". When searching for directories, the path must
959 * have a trailing slash.
960 * @param filelist a pointer to a package filelist
961 * @param path the path to search for in the package
962 * @return a pointer to the matching file or NULL if not found
964 alpm_file_t
*alpm_filelist_contains(alpm_filelist_t
*filelist
, const char *path
);
970 int alpm_pkg_check_pgp_signature(alpm_pkg_t
*pkg
, alpm_siglist_t
*siglist
);
972 int alpm_db_check_pgp_signature(alpm_db_t
*db
, alpm_siglist_t
*siglist
);
974 int alpm_siglist_cleanup(alpm_siglist_t
*siglist
);
980 alpm_list_t
*alpm_find_group_pkgs(alpm_list_t
*dbs
, const char *name
);
986 alpm_pkg_t
*alpm_sync_newversion(alpm_pkg_t
*pkg
, alpm_list_t
*dbs_sync
);
988 /** @addtogroup alpm_api_trans Transaction Functions
989 * Functions to manipulate libalpm transactions
993 /** Transaction flags */
994 typedef enum _alpm_transflag_t
{
995 /** Ignore dependency checks. */
996 ALPM_TRANS_FLAG_NODEPS
= 1,
997 /** Ignore file conflicts and overwrite files. */
998 ALPM_TRANS_FLAG_FORCE
= (1 << 1),
999 /** Delete files even if they are tagged as backup. */
1000 ALPM_TRANS_FLAG_NOSAVE
= (1 << 2),
1001 /** Ignore version numbers when checking dependencies. */
1002 ALPM_TRANS_FLAG_NODEPVERSION
= (1 << 3),
1003 /** Remove also any packages depending on a package being removed. */
1004 ALPM_TRANS_FLAG_CASCADE
= (1 << 4),
1005 /** Remove packages and their unneeded deps (not explicitly installed). */
1006 ALPM_TRANS_FLAG_RECURSE
= (1 << 5),
1007 /** Modify database but do not commit changes to the filesystem. */
1008 ALPM_TRANS_FLAG_DBONLY
= (1 << 6),
1009 /* (1 << 7) flag can go here */
1010 /** Use ALPM_PKG_REASON_DEPEND when installing packages. */
1011 ALPM_TRANS_FLAG_ALLDEPS
= (1 << 8),
1012 /** Only download packages and do not actually install. */
1013 ALPM_TRANS_FLAG_DOWNLOADONLY
= (1 << 9),
1014 /** Do not execute install scriptlets after installing. */
1015 ALPM_TRANS_FLAG_NOSCRIPTLET
= (1 << 10),
1016 /** Ignore dependency conflicts. */
1017 ALPM_TRANS_FLAG_NOCONFLICTS
= (1 << 11),
1018 /* (1 << 12) flag can go here */
1019 /** Do not install a package if it is already installed and up to date. */
1020 ALPM_TRANS_FLAG_NEEDED
= (1 << 13),
1021 /** Use ALPM_PKG_REASON_EXPLICIT when installing packages. */
1022 ALPM_TRANS_FLAG_ALLEXPLICIT
= (1 << 14),
1023 /** Do not remove a package if it is needed by another one. */
1024 ALPM_TRANS_FLAG_UNNEEDED
= (1 << 15),
1025 /** Remove also explicitly installed unneeded deps (use with ALPM_TRANS_FLAG_RECURSE). */
1026 ALPM_TRANS_FLAG_RECURSEALL
= (1 << 16),
1027 /** Do not lock the database during the operation. */
1028 ALPM_TRANS_FLAG_NOLOCK
= (1 << 17)
1031 /** Returns the bitfield of flags for the current transaction.
1032 * @param handle the context handle
1033 * @return the bitfield of transaction flags
1035 alpm_transflag_t
alpm_trans_get_flags(alpm_handle_t
*handle
);
1037 /** Returns a list of packages added by the transaction.
1038 * @param handle the context handle
1039 * @return a list of alpm_pkg_t structures
1041 alpm_list_t
*alpm_trans_get_add(alpm_handle_t
*handle
);
1043 /** Returns the list of packages removed by the transaction.
1044 * @param handle the context handle
1045 * @return a list of alpm_pkg_t structures
1047 alpm_list_t
*alpm_trans_get_remove(alpm_handle_t
*handle
);
1049 /** Initialize the transaction.
1050 * @param handle the context handle
1051 * @param flags flags of the transaction (like nodeps, etc)
1052 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1054 int alpm_trans_init(alpm_handle_t
*handle
, alpm_transflag_t flags
);
1056 /** Prepare a transaction.
1057 * @param handle the context handle
1058 * @param data the address of an alpm_list where a list
1059 * of alpm_depmissing_t objects is dumped (conflicting packages)
1060 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1062 int alpm_trans_prepare(alpm_handle_t
*handle
, alpm_list_t
**data
);
1064 /** Commit a transaction.
1065 * @param handle the context handle
1066 * @param data the address of an alpm_list where detailed description
1067 * of an error can be dumped (i.e. list of conflicting files)
1068 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1070 int alpm_trans_commit(alpm_handle_t
*handle
, alpm_list_t
**data
);
1072 /** Interrupt a transaction.
1073 * @param handle the context handle
1074 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1076 int alpm_trans_interrupt(alpm_handle_t
*handle
);
1078 /** Release a transaction.
1079 * @param handle the context handle
1080 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1082 int alpm_trans_release(alpm_handle_t
*handle
);
1085 /** @name Common Transactions */
1088 /** Search for packages to upgrade and add them to the transaction.
1089 * @param handle the context handle
1090 * @param enable_downgrade allow downgrading of packages if the remote version is lower
1091 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1093 int alpm_sync_sysupgrade(alpm_handle_t
*handle
, int enable_downgrade
);
1095 /** Add a package to the transaction.
1096 * If the package was loaded by alpm_pkg_load(), it will be freed upon
1097 * alpm_trans_release() invocation.
1098 * @param handle the context handle
1099 * @param pkg the package to add
1100 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1102 int alpm_add_pkg(alpm_handle_t
*handle
, alpm_pkg_t
*pkg
);
1104 /** Add a package removal action to the transaction.
1105 * @param handle the context handle
1106 * @param pkg the package to uninstall
1107 * @return 0 on success, -1 on error (pm_errno is set accordingly)
1109 int alpm_remove_pkg(alpm_handle_t
*handle
, alpm_pkg_t
*pkg
);
1113 /** @addtogroup alpm_api_depends Dependency Functions
1114 * Functions dealing with libalpm representation of dependency
1119 alpm_list_t
*alpm_checkdeps(alpm_handle_t
*handle
, alpm_list_t
*pkglist
,
1120 alpm_list_t
*remove
, alpm_list_t
*upgrade
, int reversedeps
);
1121 alpm_pkg_t
*alpm_find_satisfier(alpm_list_t
*pkgs
, const char *depstring
);
1122 alpm_pkg_t
*alpm_find_dbs_satisfier(alpm_handle_t
*handle
,
1123 alpm_list_t
*dbs
, const char *depstring
);
1125 alpm_list_t
*alpm_checkconflicts(alpm_handle_t
*handle
, alpm_list_t
*pkglist
);
1127 /** Returns a newly allocated string representing the dependency information.
1128 * @param dep a dependency info structure
1129 * @return a formatted string, e.g. "glibc>=2.12"
1131 char *alpm_dep_compute_string(const alpm_depend_t
*dep
);
1142 char *alpm_compute_md5sum(const char *filename
);
1143 char *alpm_compute_sha256sum(const char *filename
);
1145 /** @addtogroup alpm_api_errors Error Codes
1148 typedef enum _alpm_errno_t
{
1149 ALPM_ERR_MEMORY
= 1,
1152 ALPM_ERR_NOT_A_FILE
,
1154 ALPM_ERR_WRONG_ARGS
,
1155 ALPM_ERR_DISK_SPACE
,
1157 ALPM_ERR_HANDLE_NULL
,
1158 ALPM_ERR_HANDLE_NOT_NULL
,
1159 ALPM_ERR_HANDLE_LOCK
,
1164 ALPM_ERR_DB_NOT_NULL
,
1165 ALPM_ERR_DB_NOT_FOUND
,
1166 ALPM_ERR_DB_INVALID
,
1167 ALPM_ERR_DB_INVALID_SIG
,
1168 ALPM_ERR_DB_VERSION
,
1172 ALPM_ERR_SERVER_BAD_URL
,
1173 ALPM_ERR_SERVER_NONE
,
1175 ALPM_ERR_TRANS_NOT_NULL
,
1176 ALPM_ERR_TRANS_NULL
,
1177 ALPM_ERR_TRANS_DUP_TARGET
,
1178 ALPM_ERR_TRANS_NOT_INITIALIZED
,
1179 ALPM_ERR_TRANS_NOT_PREPARED
,
1180 ALPM_ERR_TRANS_ABORT
,
1181 ALPM_ERR_TRANS_TYPE
,
1182 ALPM_ERR_TRANS_NOT_LOCKED
,
1184 ALPM_ERR_PKG_NOT_FOUND
,
1185 ALPM_ERR_PKG_IGNORED
,
1186 ALPM_ERR_PKG_INVALID
,
1187 ALPM_ERR_PKG_INVALID_CHECKSUM
,
1188 ALPM_ERR_PKG_INVALID_SIG
,
1190 ALPM_ERR_PKG_CANT_REMOVE
,
1191 ALPM_ERR_PKG_INVALID_NAME
,
1192 ALPM_ERR_PKG_INVALID_ARCH
,
1193 ALPM_ERR_PKG_REPO_NOT_FOUND
,
1195 ALPM_ERR_SIG_MISSING
,
1196 ALPM_ERR_SIG_INVALID
,
1198 ALPM_ERR_DLT_INVALID
,
1199 ALPM_ERR_DLT_PATCHFAILED
,
1201 ALPM_ERR_UNSATISFIED_DEPS
,
1202 ALPM_ERR_CONFLICTING_DEPS
,
1203 ALPM_ERR_FILE_CONFLICTS
,
1206 ALPM_ERR_INVALID_REGEX
,
1207 /* External library errors */
1208 ALPM_ERR_LIBARCHIVE
,
1210 ALPM_ERR_EXTERNAL_DOWNLOAD
,
1214 /** Returns the current error code from the handle. */
1215 alpm_errno_t
alpm_errno(alpm_handle_t
*handle
);
1217 /** Returns the string corresponding to an error number. */
1218 const char *alpm_strerror(alpm_errno_t err
);
1220 /* End of alpm_api_errors */
1223 alpm_handle_t
*alpm_initialize(const char *root
, const char *dbpath
,
1225 int alpm_release(alpm_handle_t
*handle
);
1228 ALPM_CAPABILITY_NLS
= (1 << 0),
1229 ALPM_CAPABILITY_DOWNLOADER
= (1 << 1),
1230 ALPM_CAPABILITY_SIGNATURES
= (1 << 2)
1233 const char *alpm_version(void);
1234 enum alpm_caps
alpm_capabilities(void);
1236 /* End of alpm_api */
1242 #endif /* _ALPM_H */
1244 /* vim: set ts=2 sw=2 noet: */