2005-03-14 17:51:43 -08:00
|
|
|
/*
|
|
|
|
* alpm.c
|
|
|
|
*
|
2007-06-05 14:32:53 -07:00
|
|
|
* Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org>
|
2006-10-15 12:31:03 -07: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>
|
2005-03-14 17:51:43 -08: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
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
|
|
* USA.
|
|
|
|
*/
|
|
|
|
|
2007-03-05 14:13:33 -08:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
/* libalpm */
|
|
|
|
#include "alpm.h"
|
|
|
|
#include "alpm_list.h"
|
2005-03-14 17:51:43 -08:00
|
|
|
#include "error.h"
|
|
|
|
#include "handle.h"
|
2007-06-03 20:57:38 -07:00
|
|
|
#include "util.h"
|
2005-03-14 17:51:43 -08:00
|
|
|
|
2005-03-16 14:06:31 -08:00
|
|
|
/* Globals */
|
2005-03-14 17:51:43 -08:00
|
|
|
pmhandle_t *handle = NULL;
|
2007-01-29 23:47:19 -08:00
|
|
|
enum _pmerrno_t pm_errno SYMEXPORT;
|
2005-03-14 17:51:43 -08:00
|
|
|
|
2006-11-20 01:10:23 -08:00
|
|
|
/** \addtogroup alpm_interface Interface Functions
|
2007-01-11 09:32:49 -08:00
|
|
|
* @brief Functions to initialize and release libalpm
|
2005-10-09 00:42:06 -07:00
|
|
|
* @{
|
2005-03-14 17:51:43 -08:00
|
|
|
*/
|
|
|
|
|
2005-10-09 00:42:06 -07:00
|
|
|
/** Initializes the library. This must be called before any other
|
|
|
|
* functions are called.
|
|
|
|
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
|
|
|
*/
|
2007-07-06 09:11:55 -07:00
|
|
|
int SYMEXPORT alpm_initialize(void)
|
2005-03-14 17:51:43 -08:00
|
|
|
{
|
2005-03-16 14:10:05 -08:00
|
|
|
ASSERT(handle == NULL, RET_ERR(PM_ERR_HANDLE_NOT_NULL, -1));
|
2005-03-14 17:51:43 -08:00
|
|
|
|
2006-10-15 12:31:03 -07:00
|
|
|
handle = _alpm_handle_new();
|
2005-04-24 11:58:34 -07:00
|
|
|
if(handle == NULL) {
|
2005-04-24 13:11:10 -07:00
|
|
|
RET_ERR(PM_ERR_MEMORY, -1);
|
2005-04-24 11:58:34 -07:00
|
|
|
}
|
2005-03-14 17:51:43 -08:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2005-10-09 00:42:06 -07:00
|
|
|
/** Release the library. This should be the last alpm call you make.
|
|
|
|
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
|
|
|
*/
|
2007-07-06 09:11:55 -07:00
|
|
|
int SYMEXPORT alpm_release(void)
|
2005-03-14 17:51:43 -08:00
|
|
|
{
|
2006-11-07 22:52:50 -08:00
|
|
|
int dbs_left = 0;
|
2005-03-14 17:51:43 -08:00
|
|
|
|
2007-01-30 00:14:10 -08:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2005-03-16 14:10:05 -08:00
|
|
|
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
|
2005-03-14 17:51:43 -08:00
|
|
|
|
|
|
|
/* close local database */
|
|
|
|
if(handle->db_local) {
|
2006-03-02 11:06:52 -08:00
|
|
|
alpm_db_unregister(handle->db_local);
|
2005-03-14 17:51:43 -08:00
|
|
|
handle->db_local = NULL;
|
|
|
|
}
|
|
|
|
/* and also sync ones */
|
2006-11-07 22:52:50 -08:00
|
|
|
while((dbs_left = alpm_list_count(handle->dbs_sync)) > 0) {
|
|
|
|
pmdb_t *db = (pmdb_t *)handle->dbs_sync->data;
|
|
|
|
_alpm_log(PM_LOG_DEBUG, _("removing DB %s, %d remaining..."), db->treename, dbs_left);
|
|
|
|
alpm_db_unregister(db);
|
|
|
|
db = NULL;
|
2005-03-14 17:51:43 -08:00
|
|
|
}
|
|
|
|
|
2007-04-26 17:29:12 -07:00
|
|
|
_alpm_handle_free(handle);
|
2005-03-14 17:51:43 -08:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2007-01-11 09:32:49 -08:00
|
|
|
/** @} */
|
2005-03-14 17:51:43 -08:00
|
|
|
|
2007-06-03 20:57:38 -07:00
|
|
|
/** @defgroup alpm_misc Miscellaneous Functions
|
2006-02-01 09:58:02 -08:00
|
|
|
* @brief Various libalpm functions
|
2006-10-15 12:31:03 -07:00
|
|
|
*/
|
2007-02-04 00:26:52 -08:00
|
|
|
|
2005-03-14 17:51:43 -08:00
|
|
|
/* vim: set ts=2 sw=2 noet: */
|