1
0
mirror of https://github.com/moparisthebest/pacman synced 2025-03-07 20:59:41 -05:00

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:
Dan McGee 2007-07-09 15:22:01 -04:00
parent 4906e15d0d
commit 1480ac29e4
4 changed files with 36 additions and 66 deletions

View File

@ -53,31 +53,10 @@ pmhandle_t *_alpm_handle_new()
memset(handle, 0, sizeof(pmhandle_t));
handle->lckfd = -1;
handle->logstream = NULL;
#ifndef CYGWIN
/* see if we're root or not */
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->dbpath = NULL;
handle->cachedirs = NULL;
@ -95,10 +74,10 @@ void _alpm_handle_free(pmhandle_t *handle)
return;
}
/* close logfiles */
if(handle->logfd) {
fclose(handle->logfd);
handle->logfd = NULL;
/* close logfile */
if(handle->logstream) {
fclose(handle->logstream);
handle->logstream= NULL;
}
if(handle->usesyslog) {
handle->usesyslog = 0;
@ -231,14 +210,14 @@ void SYMEXPORT alpm_option_set_logfile(const char *logfile)
if(handle->logfile) {
FREE(handle->logfile);
if(handle->logfd) {
fclose(handle->logfd);
handle->logfd = NULL;
if(handle->logstream) {
fclose(handle->logstream);
handle->logstream = NULL;
}
}
if(logfile) {
handle->logfile = strdup(logfile);
handle->logfd = fopen(logfile, "a");
handle->logstream = fopen(logfile, "a");
}
}

View File

@ -30,40 +30,37 @@
#include "alpm.h"
#include "trans.h"
typedef enum _pmaccess_t {
PM_ACCESS_RO,
PM_ACCESS_RW
} pmaccess_t;
typedef struct _pmhandle_t {
/* Internal */
pmaccess_t access;
uid_t uid;
pmdb_t *db_local;
alpm_list_t *dbs_sync; /* List of (pmdb_t *) */
FILE *logfd;
int lckfd;
/* internal usage */
uid_t uid; /* current UID */ /* TODO is this used? */
pmdb_t *db_local; /* local db pointer */
alpm_list_t *dbs_sync; /* List of (pmdb_t *) */
FILE *logstream; /* log file stream pointer */
int lckfd; /* lock file descriptor if one exists */
pmtrans_t *trans;
/* options */
alpm_cb_log logcb; /* Log callback function */
alpm_cb_download dlcb; /* Download callback function */
char *root; /* Root path, default '/' */
char *dbpath; /* Base path to pacman's DBs */
alpm_list_t *cachedirs; /* Paths to pacman cache directories */
char *logfile; /* Name of the file to log to */ /*TODO is this used?*/
char *lockfile; /* Name of the lock file */
unsigned short usesyslog; /* Use syslog instead of logfile? */ /* TODO move to frontend */
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 *ignorepkg; /* List of packages to ignore */
alpm_list_t *holdpkg; /* List of packages which 'hold' pacman */
/* callback functions */
alpm_cb_log logcb; /* Log callback function */
alpm_cb_download dlcb; /* Download callback function */
time_t upgradedelay; /* Amount of time to wait before upgrading a package */
/* servers */
char *xfercommand; /* External download command */
/* filesystem paths */
char *root; /* Root path, default '/' */
char *dbpath; /* Base path to pacman's DBs */
char *logfile; /* Name of the log file */
char *lockfile; /* Name of the lock file */
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 *noextract; /* List of packages NOT to extract */ /*TODO is this used?*/
alpm_list_t *ignorepkg; /* List of packages to ignore */
alpm_list_t *holdpkg; /* List of packages which 'hold' pacman */
/* options */
unsigned short usesyslog; /* Use syslog instead of logfile? */ /* TODO move to frontend */
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;
extern pmhandle_t *handle;

View File

@ -52,7 +52,7 @@ int SYMEXPORT alpm_logaction(char *fmt, ...)
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
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);
/* TODO We should add a prefix to log strings depending on who called us.

View File

@ -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->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));
}