#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
#include <syslog.h>
#include <limits.h>
#include <stdarg.h>
#include "log.h"
#include "error.h"
#include "rpmvercmp.h"
#include "md5.h"
#include "list.h"
#include "package.h"
#include "group.h"
#include "util.h"
#include "db.h"
#include "cache.h"
#include "deps.h"
#include "backup.h"
#include "add.h"
#include "remove.h"
#include "sync.h"
#include "handle.h"
#include "alpm.h"
pmhandle_t *handle = NULL;
enum __pmerrno_t pm_errno;
int alpm_initialize(char *root)
{
char str[PATH_MAX];
ASSERT(handle == NULL, RET_ERR(PM_ERR_HANDLE_NOT_NULL, -1));
handle = handle_new();
if(handle->access == PM_ACCESS_RW) {
if(_alpm_lckmk(PM_LOCK) == -1) {
FREE(handle);
RET_ERR(PM_ERR_HANDLE_LOCK, -1);
}
}
STRNCPY(str, (root) ? root : PM_ROOT, PATH_MAX);
if(str[strlen(str)-1] != '/') {
strcat(str, "/");
}
handle->root = strdup(str);
return(0);
}
int alpm_release()
{
PMList *i;
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
if(handle->access == PM_ACCESS_RW) {
if(_alpm_lckrm(PM_LOCK)) {
_alpm_log(PM_LOG_WARNING, "could not remove lock file %s", PM_LOCK);
alpm_logaction("warning: could not remove lock file %s", PM_LOCK);
}
}
if(handle->db_local) {
db_close(handle->db_local);
handle->db_local = NULL;
}
for(i = handle->dbs_sync; i; i = i->next) {
if(i->data) {
db_close(i->data);
i->data = NULL;
}
}
FREEHANDLE(handle);
return(0);
}
int alpm_set_option(unsigned char parm, unsigned long data)
{
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
return(handle_set_option(handle, parm, data));
}
int alpm_get_option(unsigned char parm, long *data)
{
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
ASSERT(data != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
return(handle_get_option(handle, parm, data));
}
int alpm_db_register(char *treename, PM_DB **db)
{
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
ASSERT(treename != NULL && strlen(treename) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
ASSERT(db != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
*db = db_open(handle->root, handle->dbpath, treename);
if(*db == NULL) {
if(db_create(handle->root, handle->dbpath, treename) == -1) {
RET_ERR(PM_ERR_DB_CREATE, -1);
}
*db = db_open(handle->root, handle->dbpath, treename);
if(*db == NULL) {
<
|