pacman: list all unknown targets on removal operation
[pacman-ng.git] / lib / libalpm / alpm.c
blobe957f1aa3cd3fededd30b3d474a797d8d6617bb6
1 /*
2 * alpm.c
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/>.
24 #include "config.h"
26 #ifdef HAVE_LIBCURL
27 #include <curl/curl.h>
28 #endif
30 /* libalpm */
31 #include "alpm.h"
32 #include "alpm_list.h"
33 #include "handle.h"
34 #include "log.h"
35 #include "util.h"
37 /** \addtogroup alpm_interface Interface Functions
38 * @brief Functions to initialize and release libalpm
39 * @{
42 /** Initializes the library. This must be called before any other
43 * functions are called.
44 * @param root the root path for all filesystem operations
45 * @param dbpath the absolute path to the libalpm database
46 * @param err an optional variable to hold any error return codes
47 * @return a context handle on success, NULL on error, err will be set if provided
49 alpm_handle_t SYMEXPORT *alpm_initialize(const char *root, const char *dbpath,
50 alpm_errno_t *err)
52 alpm_errno_t myerr;
53 const char *lf = "db.lck";
54 size_t lockfilelen;
55 alpm_handle_t *myhandle = _alpm_handle_new();
57 if(myhandle == NULL) {
58 myerr = ALPM_ERR_MEMORY;
59 goto cleanup;
61 if((myerr = _alpm_set_directory_option(root, &(myhandle->root), 1))) {
62 goto cleanup;
64 if((myerr = _alpm_set_directory_option(dbpath, &(myhandle->dbpath), 1))) {
65 goto cleanup;
68 lockfilelen = strlen(myhandle->dbpath) + strlen(lf) + 1;
69 myhandle->lockfile = calloc(lockfilelen, sizeof(char));
70 snprintf(myhandle->lockfile, lockfilelen, "%s%s", myhandle->dbpath, lf);
72 if(_alpm_db_register_local(myhandle) == NULL) {
73 myerr = myhandle->pm_errno;
74 goto cleanup;
77 #ifdef ENABLE_NLS
78 bindtextdomain("libalpm", LOCALEDIR);
79 #endif
81 return myhandle;
83 cleanup:
84 _alpm_handle_free(myhandle);
85 if(err && myerr) {
86 *err = myerr;
88 return NULL;
91 /** Release the library. This should be the last alpm call you make.
92 * After this returns, handle should be considered invalid and cannot be reused
93 * in any way.
94 * @param myhandle the context handle
95 * @return 0 on success, -1 on error
97 int SYMEXPORT alpm_release(alpm_handle_t *myhandle)
99 int ret = 0;
100 alpm_db_t *db;
102 CHECK_HANDLE(myhandle, return -1);
104 /* close local database */
105 db = myhandle->db_local;
106 if(db) {
107 db->ops->unregister(db);
108 myhandle->db_local = NULL;
111 if(alpm_db_unregister_all(myhandle) == -1) {
112 ret = -1;
115 _alpm_handle_unlock(myhandle);
116 _alpm_handle_free(myhandle);
118 #ifdef HAVE_LIBCURL
119 curl_global_cleanup();
120 #endif
122 return ret;
125 /** @} */
127 /** @defgroup alpm_misc Miscellaneous Functions
128 * @brief Various libalpm functions
131 /** Get the version of library.
132 * @return the library version, e.g. "6.0.4"
133 * */
134 const char SYMEXPORT *alpm_version(void)
136 return LIB_VERSION;
139 /** Get the capabilities of the library.
140 * @return a bitmask of the capabilities
141 * */
142 enum alpm_caps SYMEXPORT alpm_capabilities(void)
144 return 0
145 #ifdef ENABLE_NLS
146 | ALPM_CAPABILITY_NLS
147 #endif
148 #ifdef HAVE_LIBCURL
149 | ALPM_CAPABILITY_DOWNLOADER
150 #endif
151 #ifdef HAVE_LIBGPGME
152 | ALPM_CAPABILITY_SIGNATURES
153 #endif
154 | 0;
157 /* vim: set ts=2 sw=2 noet: */