Clean up the alpm handle
Add some comments in handle.h, and remove the pmaccess_t part that we don't even use. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
4906e15d0d
commit
1480ac29e4
4 changed files with 36 additions and 66 deletions
|
@ -53,31 +53,10 @@ pmhandle_t *_alpm_handle_new()
|
||||||
|
|
||||||
memset(handle, 0, sizeof(pmhandle_t));
|
memset(handle, 0, sizeof(pmhandle_t));
|
||||||
handle->lckfd = -1;
|
handle->lckfd = -1;
|
||||||
|
handle->logstream = NULL;
|
||||||
|
|
||||||
#ifndef CYGWIN
|
|
||||||
/* see if we're root or not */
|
/* see if we're root or not */
|
||||||
handle->uid = geteuid();
|
handle->uid = geteuid();
|
||||||
//#ifndef FAKEROOT
|
|
||||||
// if(!handle->uid && getenv("FAKEROOTKEY")) {
|
|
||||||
// /* fakeroot doesn't count, we're non-root */
|
|
||||||
// handle->uid = 99;
|
|
||||||
// }
|
|
||||||
//#endif
|
|
||||||
//
|
|
||||||
// /* see if we're root or not (fakeroot does not count) */
|
|
||||||
//#ifndef FAKEROOT
|
|
||||||
// if(handle->uid == 0 && !getenv("FAKEROOTKEY")) {
|
|
||||||
// /* } make vim indent work - stupid ifdef's */
|
|
||||||
//#else
|
|
||||||
// if(handle->uid == 0) {
|
|
||||||
//#endif
|
|
||||||
// handle->access = PM_ACCESS_RW;
|
|
||||||
// } else {
|
|
||||||
// handle->access = PM_ACCESS_RO;
|
|
||||||
// }
|
|
||||||
//#else
|
|
||||||
handle->access = PM_ACCESS_RW;
|
|
||||||
#endif
|
|
||||||
handle->root = NULL;
|
handle->root = NULL;
|
||||||
handle->dbpath = NULL;
|
handle->dbpath = NULL;
|
||||||
handle->cachedirs = NULL;
|
handle->cachedirs = NULL;
|
||||||
|
@ -95,10 +74,10 @@ void _alpm_handle_free(pmhandle_t *handle)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* close logfiles */
|
/* close logfile */
|
||||||
if(handle->logfd) {
|
if(handle->logstream) {
|
||||||
fclose(handle->logfd);
|
fclose(handle->logstream);
|
||||||
handle->logfd = NULL;
|
handle->logstream= NULL;
|
||||||
}
|
}
|
||||||
if(handle->usesyslog) {
|
if(handle->usesyslog) {
|
||||||
handle->usesyslog = 0;
|
handle->usesyslog = 0;
|
||||||
|
@ -231,14 +210,14 @@ void SYMEXPORT alpm_option_set_logfile(const char *logfile)
|
||||||
|
|
||||||
if(handle->logfile) {
|
if(handle->logfile) {
|
||||||
FREE(handle->logfile);
|
FREE(handle->logfile);
|
||||||
if(handle->logfd) {
|
if(handle->logstream) {
|
||||||
fclose(handle->logfd);
|
fclose(handle->logstream);
|
||||||
handle->logfd = NULL;
|
handle->logstream = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(logfile) {
|
if(logfile) {
|
||||||
handle->logfile = strdup(logfile);
|
handle->logfile = strdup(logfile);
|
||||||
handle->logfd = fopen(logfile, "a");
|
handle->logstream = fopen(logfile, "a");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,40 +30,37 @@
|
||||||
#include "alpm.h"
|
#include "alpm.h"
|
||||||
#include "trans.h"
|
#include "trans.h"
|
||||||
|
|
||||||
typedef enum _pmaccess_t {
|
|
||||||
PM_ACCESS_RO,
|
|
||||||
PM_ACCESS_RW
|
|
||||||
} pmaccess_t;
|
|
||||||
|
|
||||||
typedef struct _pmhandle_t {
|
typedef struct _pmhandle_t {
|
||||||
/* Internal */
|
/* internal usage */
|
||||||
pmaccess_t access;
|
uid_t uid; /* current UID */ /* TODO is this used? */
|
||||||
uid_t uid;
|
pmdb_t *db_local; /* local db pointer */
|
||||||
pmdb_t *db_local;
|
|
||||||
alpm_list_t *dbs_sync; /* List of (pmdb_t *) */
|
alpm_list_t *dbs_sync; /* List of (pmdb_t *) */
|
||||||
FILE *logfd;
|
FILE *logstream; /* log file stream pointer */
|
||||||
int lckfd;
|
int lckfd; /* lock file descriptor if one exists */
|
||||||
pmtrans_t *trans;
|
pmtrans_t *trans;
|
||||||
|
|
||||||
/* options */
|
/* callback functions */
|
||||||
alpm_cb_log logcb; /* Log callback function */
|
alpm_cb_log logcb; /* Log callback function */
|
||||||
alpm_cb_download dlcb; /* Download callback function */
|
alpm_cb_download dlcb; /* Download callback function */
|
||||||
|
|
||||||
|
/* filesystem paths */
|
||||||
char *root; /* Root path, default '/' */
|
char *root; /* Root path, default '/' */
|
||||||
char *dbpath; /* Base path to pacman's DBs */
|
char *dbpath; /* Base path to pacman's DBs */
|
||||||
alpm_list_t *cachedirs; /* Paths to pacman cache directories */
|
char *logfile; /* Name of the log file */
|
||||||
char *logfile; /* Name of the file to log to */ /*TODO is this used?*/
|
|
||||||
char *lockfile; /* Name of the lock file */
|
char *lockfile; /* Name of the lock file */
|
||||||
unsigned short usesyslog; /* Use syslog instead of logfile? */ /* TODO move to frontend */
|
alpm_list_t *cachedirs; /* Paths to pacman cache directories */
|
||||||
|
|
||||||
|
/* package lists */
|
||||||
alpm_list_t *noupgrade; /* List of packages NOT to be upgraded */
|
alpm_list_t *noupgrade; /* List of packages NOT to be upgraded */
|
||||||
alpm_list_t *noextract; /* List of packages NOT to extract */ /*TODO is this used?*/
|
alpm_list_t *noextract; /* List of packages NOT to extract */ /*TODO is this used?*/
|
||||||
alpm_list_t *ignorepkg; /* List of packages to ignore */
|
alpm_list_t *ignorepkg; /* List of packages to ignore */
|
||||||
alpm_list_t *holdpkg; /* List of packages which 'hold' pacman */
|
alpm_list_t *holdpkg; /* List of packages which 'hold' pacman */
|
||||||
|
|
||||||
time_t upgradedelay; /* Amount of time to wait before upgrading a package */
|
/* options */
|
||||||
/* servers */
|
unsigned short usesyslog; /* Use syslog instead of logfile? */ /* TODO move to frontend */
|
||||||
char *xfercommand; /* External download command */
|
|
||||||
unsigned short nopassiveftp; /* Don't use PASV ftp connections */
|
unsigned short nopassiveftp; /* Don't use PASV ftp connections */
|
||||||
|
time_t upgradedelay; /* Time to wait before upgrading a package */
|
||||||
|
char *xfercommand; /* External download command */
|
||||||
} pmhandle_t;
|
} pmhandle_t;
|
||||||
|
|
||||||
extern pmhandle_t *handle;
|
extern pmhandle_t *handle;
|
||||||
|
|
|
@ -52,7 +52,7 @@ int SYMEXPORT alpm_logaction(char *fmt, ...)
|
||||||
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
|
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
ret = _alpm_logaction(handle->usesyslog, handle->logfd, fmt, args);
|
ret = _alpm_logaction(handle->usesyslog, handle->logstream, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
/* TODO We should add a prefix to log strings depending on who called us.
|
/* TODO We should add a prefix to log strings depending on who called us.
|
||||||
|
|
|
@ -165,12 +165,6 @@ int SYMEXPORT alpm_trans_commit(alpm_list_t **data)
|
||||||
ASSERT(handle->trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
ASSERT(handle->trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
||||||
ASSERT(handle->trans->state == STATE_PREPARED, RET_ERR(PM_ERR_TRANS_NOT_PREPARED, -1));
|
ASSERT(handle->trans->state == STATE_PREPARED, RET_ERR(PM_ERR_TRANS_NOT_PREPARED, -1));
|
||||||
|
|
||||||
/* Check for database R/W permission */
|
|
||||||
if(!(handle->trans->flags & PM_TRANS_FLAG_PRINTURIS)) {
|
|
||||||
/* The print-uris operation is a bit odd. So we explicitly check for it */
|
|
||||||
ASSERT(handle->access == PM_ACCESS_RW, RET_ERR(PM_ERR_BADPERMS, -1));
|
|
||||||
}
|
|
||||||
|
|
||||||
return(_alpm_trans_commit(handle->trans, data));
|
return(_alpm_trans_commit(handle->trans, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue