2005-03-15 01:51:43 +00:00
|
|
|
/*
|
|
|
|
* alpm.c
|
2007-11-16 20:18:45 -06:00
|
|
|
*
|
2024-02-24 18:40:44 +10:00
|
|
|
* Copyright (c) 2006-2024 Pacman Development Team <pacman-dev@lists.archlinux.org>
|
2009-07-01 02:08:33 -05:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2006-10-15 19:31:03 +00:00
|
|
|
* Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
|
|
|
|
* Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
|
|
|
|
* Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.org>
|
2007-11-16 20:18:45 -06:00
|
|
|
*
|
2005-03-15 01:51:43 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-12-10 22:55:22 -06:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-03-15 01:51:43 +00:00
|
|
|
*/
|
|
|
|
|
2010-12-15 19:57:31 -05:00
|
|
|
#ifdef HAVE_LIBCURL
|
|
|
|
#include <curl/curl.h>
|
|
|
|
#endif
|
|
|
|
|
2007-03-05 22:13:33 +00:00
|
|
|
/* libalpm */
|
|
|
|
#include "alpm.h"
|
|
|
|
#include "alpm_list.h"
|
2005-03-15 01:51:43 +00:00
|
|
|
#include "handle.h"
|
2011-06-03 16:42:41 -05:00
|
|
|
#include "log.h"
|
2007-06-03 23:57:38 -04:00
|
|
|
#include "util.h"
|
2005-03-15 01:51:43 +00:00
|
|
|
|
2011-06-28 14:04:00 +10:00
|
|
|
alpm_handle_t SYMEXPORT *alpm_initialize(const char *root, const char *dbpath,
|
2011-10-29 15:03:24 +13:00
|
|
|
alpm_errno_t *err)
|
2005-03-15 01:51:43 +00:00
|
|
|
{
|
2011-10-29 15:03:24 +13:00
|
|
|
alpm_errno_t myerr;
|
2011-06-03 15:24:01 -05:00
|
|
|
const char *lf = "db.lck";
|
2015-10-16 20:28:23 -04:00
|
|
|
char *hookdir;
|
2011-06-03 15:24:01 -05:00
|
|
|
size_t lockfilelen;
|
2011-06-28 14:04:00 +10:00
|
|
|
alpm_handle_t *myhandle = _alpm_handle_new();
|
2011-06-03 15:24:01 -05:00
|
|
|
|
|
|
|
if(myhandle == NULL) {
|
2016-06-05 19:23:31 +02:00
|
|
|
goto nomem;
|
2005-04-24 18:58:34 +00:00
|
|
|
}
|
2011-06-03 15:24:01 -05:00
|
|
|
if((myerr = _alpm_set_directory_option(root, &(myhandle->root), 1))) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if((myerr = _alpm_set_directory_option(dbpath, &(myhandle->dbpath), 1))) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-06-06 21:29:09 +02:00
|
|
|
/* to concatenate myhandle->root (ends with a slash) with SYSHOOKDIR (starts
|
2015-11-29 14:55:15 +01:00
|
|
|
* with a slash) correctly, we skip SYSHOOKDIR[0]; the regular +1 therefore
|
|
|
|
* disappears from the allocation */
|
2016-06-05 19:23:31 +02:00
|
|
|
MALLOC(hookdir, strlen(myhandle->root) + strlen(SYSHOOKDIR), goto nomem);
|
2019-04-05 00:02:51 +02:00
|
|
|
sprintf(hookdir, "%s%s", myhandle->root, &SYSHOOKDIR[1]);
|
2015-10-16 20:28:23 -04:00
|
|
|
myhandle->hookdirs = alpm_list_add(NULL, hookdir);
|
|
|
|
|
2015-07-14 21:45:59 +10:00
|
|
|
/* set default database extension */
|
2016-06-05 19:23:31 +02:00
|
|
|
STRDUP(myhandle->dbext, ".db", goto nomem);
|
2015-07-14 21:45:59 +10:00
|
|
|
|
2011-06-03 15:24:01 -05:00
|
|
|
lockfilelen = strlen(myhandle->dbpath) + strlen(lf) + 1;
|
2016-06-05 19:23:31 +02:00
|
|
|
MALLOC(myhandle->lockfile, lockfilelen, goto nomem);
|
2011-06-03 15:24:01 -05:00
|
|
|
snprintf(myhandle->lockfile, lockfilelen, "%s%s", myhandle->dbpath, lf);
|
|
|
|
|
|
|
|
if(_alpm_db_register_local(myhandle) == NULL) {
|
2011-04-20 19:54:01 -05:00
|
|
|
myerr = myhandle->pm_errno;
|
2011-06-03 15:24:01 -05:00
|
|
|
goto cleanup;
|
2011-01-28 17:41:15 -06:00
|
|
|
}
|
2007-10-22 23:52:55 -05:00
|
|
|
|
2020-03-09 15:23:12 -07:00
|
|
|
#ifdef HAVE_LIBCURL
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
|
|
|
myhandle->curlm = curl_multi_init();
|
|
|
|
#endif
|
|
|
|
|
2020-11-24 12:39:04 +00:00
|
|
|
myhandle->parallel_downloads = 1;
|
|
|
|
|
2007-10-22 23:52:55 -05:00
|
|
|
#ifdef ENABLE_NLS
|
2007-07-06 17:59:08 -04:00
|
|
|
bindtextdomain("libalpm", LOCALEDIR);
|
2007-10-22 23:52:55 -05:00
|
|
|
#endif
|
2005-03-15 01:51:43 +00:00
|
|
|
|
2011-06-03 15:24:01 -05:00
|
|
|
return myhandle;
|
|
|
|
|
2016-06-05 19:23:31 +02:00
|
|
|
nomem:
|
|
|
|
myerr = ALPM_ERR_MEMORY;
|
2011-06-03 15:24:01 -05:00
|
|
|
cleanup:
|
|
|
|
_alpm_handle_free(myhandle);
|
2016-06-05 19:23:31 +02:00
|
|
|
if(err) {
|
2011-06-03 15:24:01 -05:00
|
|
|
*err = myerr;
|
|
|
|
}
|
|
|
|
return NULL;
|
2005-03-15 01:51:43 +00:00
|
|
|
}
|
|
|
|
|
2023-11-18 16:27:58 -08:00
|
|
|
/* check current state and free all resources including storage locks */
|
2011-06-28 14:04:00 +10:00
|
|
|
int SYMEXPORT alpm_release(alpm_handle_t *myhandle)
|
2005-03-15 01:51:43 +00:00
|
|
|
{
|
2011-06-14 10:01:08 -05:00
|
|
|
CHECK_HANDLE(myhandle, return -1);
|
2023-11-18 16:27:58 -08:00
|
|
|
ASSERT(myhandle->trans == NULL, RET_ERR(myhandle, ALPM_ERR_TRANS_NOT_NULL, -1));
|
2010-12-15 19:57:31 -05:00
|
|
|
|
2020-03-09 15:23:12 -07:00
|
|
|
_alpm_handle_unlock(myhandle);
|
|
|
|
_alpm_handle_free(myhandle);
|
|
|
|
|
2023-11-18 16:27:58 -08:00
|
|
|
return 0;
|
2005-03-15 01:51:43 +00:00
|
|
|
}
|
|
|
|
|
2011-09-21 10:31:30 -05:00
|
|
|
const char SYMEXPORT *alpm_version(void)
|
|
|
|
{
|
2011-03-20 19:45:57 -05:00
|
|
|
return LIB_VERSION;
|
2008-02-29 21:52:57 +01:00
|
|
|
}
|
|
|
|
|
2016-10-12 15:13:32 -05:00
|
|
|
int SYMEXPORT alpm_capabilities(void)
|
2011-09-21 10:31:30 -05:00
|
|
|
{
|
|
|
|
return 0
|
|
|
|
#ifdef ENABLE_NLS
|
|
|
|
| ALPM_CAPABILITY_NLS
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBCURL
|
|
|
|
| ALPM_CAPABILITY_DOWNLOADER
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBGPGME
|
|
|
|
| ALPM_CAPABILITY_SIGNATURES
|
|
|
|
#endif
|
|
|
|
| 0;
|
|
|
|
}
|