summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2005-10-28 12:20:40 +0000
committerAurelien Foret <aurelien@archlinux.org>2005-10-28 12:20:40 +0000
commit98df67cd183bf75065d3e7a0f892427c4de21143 (patch)
treea3c11955afd735f9c9be86d23e755ea4e94b3783 /src
parentcce9d780c99feae8600249e9a81cb2a24e8589d9 (diff)
downloadpacman-98df67cd183bf75065d3e7a0f892427c4de21143.tar.xz
added pmconfig_t structure to hold all the configuration
(patch from VMiklos <vmiklos@frugalware.org>)
Diffstat (limited to 'src')
-rw-r--r--src/pacman/add.c8
-rw-r--r--src/pacman/conf.c86
-rw-r--r--src/pacman/conf.h45
-rw-r--r--src/pacman/download.c44
-rw-r--r--src/pacman/log.c6
-rw-r--r--src/pacman/pacman.c215
-rw-r--r--src/pacman/query.c39
-rw-r--r--src/pacman/remove.c7
-rw-r--r--src/pacman/sync.c50
-rw-r--r--src/pacman/upgrade.c5
10 files changed, 265 insertions, 240 deletions
diff --git a/src/pacman/add.c b/src/pacman/add.c
index bf262b0e..960f5eed 100644
--- a/src/pacman/add.c
+++ b/src/pacman/add.c
@@ -29,9 +29,9 @@
#include "list.h"
#include "download.h"
#include "trans.h"
+#include "conf.h"
-extern unsigned char pmo_upgrade;
-extern unsigned char pmo_flags;
+extern pmconfig_t *config;
int pacman_add(list_t *targets)
{
@@ -58,8 +58,8 @@ int pacman_add(list_t *targets)
/* Step 1: create a new transaction
*/
- if(alpm_trans_init((pmo_upgrade == 0) ? PM_TRANS_TYPE_ADD : PM_TRANS_TYPE_UPGRADE,
- pmo_flags, cb_trans_evt, cb_trans_conv) == -1) {
+ if(alpm_trans_init((config->upgrade == 0) ? PM_TRANS_TYPE_ADD : PM_TRANS_TYPE_UPGRADE,
+ config->flags, cb_trans_evt, cb_trans_conv) == -1) {
ERR(NL, "%s\n", alpm_strerror(pm_errno));
return(1);
}
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index a62ef609..7f407535 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -31,21 +31,47 @@
#include "list.h"
#include "sync.h"
#include "download.h"
+#include "conf.h"
+#include "pacman.h"
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
-extern char *pmo_dbpath;
-extern char *pmo_cachedir;
-extern list_t *pmo_holdpkg;
-extern char *pmo_proxyhost;
-extern unsigned short pmo_proxyport;
-extern char *pmo_xfercommand;
-extern unsigned short pmo_chomp;
-extern unsigned short pmo_nopassiveftp;
-
extern list_t *pmc_syncs;
-int parseconfig(char *file)
+pmconfig_t *config_new()
+{
+ pmconfig_t *config;
+
+ config = (pmconfig_t *)malloc(sizeof(pmconfig_t));
+ if(config == NULL) {
+ return(NULL);
+ }
+
+ memset(config, 0, sizeof(pmconfig_t));
+
+ return(config);
+}
+
+int config_free(pmconfig_t *config)
+{
+ if(config == NULL) {
+ return(-1);
+ }
+
+ FREE(config->root);
+ FREE(config->dbpath);
+ FREE(config->cachedir);
+ FREE(config->configfile);
+ FREELIST(config->op_s_ignore);
+ FREE(config->proxyhost);
+ FREE(config->xfercommand);
+ FREELIST(config->holdpkg);
+ free(config);
+
+ return(0);
+}
+
+int parseconfig(pmconfig_t *config)
{
FILE *fp = NULL;
char line[PATH_MAX+1];
@@ -55,7 +81,11 @@ int parseconfig(char *file)
char section[256] = "";
sync_t *sync = NULL;
- fp = fopen(file, "r");
+ if(config == NULL) {
+ return(-1);
+ }
+
+ fp = fopen(config->configfile, "r");
if(fp == NULL) {
return(0);
}
@@ -119,7 +149,7 @@ int parseconfig(char *file)
}
if(ptr == NULL) {
if(!strcmp(key, "NOPASSIVEFTP")) {
- pmo_nopassiveftp = 1;
+ config->nopassiveftp = 1;
vprint("config: nopassiveftp\n");
} else if(!strcmp(key, "USESYSLOG")) {
if(alpm_set_option(PM_OPT_USESYSLOG, (long)1) == -1) {
@@ -128,7 +158,7 @@ int parseconfig(char *file)
}
vprint("config: usesyslog\n");
} else if(!strcmp(key, "ILOVECANDY")) {
- pmo_chomp = 1;
+ config->chomp = 1;
} else {
ERR(NL, "config: line %d: syntax error\n", linenum);
return(1);
@@ -200,28 +230,28 @@ int parseconfig(char *file)
char *q;
while((q = strchr(p, ' '))) {
*q = '\0';
- pmo_holdpkg = list_add(pmo_holdpkg, strdup(p));
+ config->holdpkg = list_add(config->holdpkg, strdup(p));
vprint("config: holdpkg: %s\n", p);
p = q;
p++;
}
- pmo_holdpkg = list_add(pmo_holdpkg, strdup(p));
+ config->holdpkg = list_add(config->holdpkg, strdup(p));
vprint("config: holdpkg: %s\n", p);
} else if(!strcmp(key, "DBPATH")) {
/* shave off the leading slash, if there is one */
if(*ptr == '/') {
ptr++;
}
- FREE(pmo_dbpath);
- pmo_dbpath = strdup(ptr);
+ FREE(config->dbpath);
+ config->dbpath = strdup(ptr);
vprint("config: dbpath: %s\n", ptr);
} else if(!strcmp(key, "CACHEDIR")) {
/* shave off the leading slash, if there is one */
if(*ptr == '/') {
ptr++;
}
- FREE(pmo_cachedir);
- pmo_cachedir = strdup(ptr);
+ FREE(config->cachedir);
+ config->cachedir = strdup(ptr);
vprint("config: cachedir: %s\n", ptr);
} else if (!strcmp(key, "LOGFILE")) {
if(alpm_set_option(PM_OPT_LOGFILE, (long)ptr) == -1) {
@@ -230,13 +260,13 @@ int parseconfig(char *file)
}
vprint("config: log file: %s\n", ptr);
} else if (!strcmp(key, "XFERCOMMAND")) {
- FREE(pmo_xfercommand);
- pmo_xfercommand = strndup(ptr, PATH_MAX);
- vprint("config: xfercommand: %s\n", pmo_xfercommand);
+ FREE(config->xfercommand);
+ config->xfercommand = strndup(ptr, PATH_MAX);
+ vprint("config: xfercommand: %s\n", config->xfercommand);
} else if (!strcmp(key, "PROXYSERVER")) {
char *p;
- if(pmo_proxyhost) {
- FREE(pmo_proxyhost);
+ if(config->proxyhost) {
+ FREE(config->proxyhost);
}
p = strstr(ptr, "://");
if(p) {
@@ -247,11 +277,11 @@ int parseconfig(char *file)
}
ptr = p;
}
- pmo_proxyhost = strndup(ptr, PATH_MAX);
- vprint("config: proxyserver: %s\n", pmo_proxyhost);
+ config->proxyhost = strndup(ptr, PATH_MAX);
+ vprint("config: proxyserver: %s\n", config->proxyhost);
} else if (!strcmp(key, "PROXYPORT")) {
- pmo_proxyport = (unsigned short)atoi(ptr);
- vprint("config: proxyport: %u\n", pmo_proxyport);
+ config->proxyport = (unsigned short)atoi(ptr);
+ vprint("config: proxyport: %u\n", config->proxyport);
} else {
ERR(NL, "config: line %d: syntax error\n", linenum);
return(1);
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 809e702e..390f84a2 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -21,7 +21,50 @@
#ifndef _PM_CONF_H
#define _PM_CONF_H
-int parseconfig(char *file);
+typedef struct __pmconfig_t {
+ /* command line options */
+ char *root;
+ char *dbpath;
+ char *cachedir;
+ char *configfile;
+ unsigned short op;
+ unsigned short verbose;
+ unsigned short version;
+ unsigned short help;
+ unsigned short upgrade;
+ unsigned short noconfirm;
+ unsigned short op_d_vertest;
+ unsigned short op_d_resolve;
+ unsigned short op_q_isfile;
+ unsigned short op_q_info;
+ unsigned short op_q_list;
+ unsigned short op_q_orphans;
+ unsigned short op_q_owns;
+ unsigned short op_q_search;
+ unsigned short op_s_clean;
+ unsigned short op_s_downloadonly;
+ list_t *op_s_ignore;
+ unsigned short op_s_info;
+ unsigned short op_s_printuris;
+ unsigned short op_s_sync;
+ unsigned short op_s_search;
+ unsigned short op_s_upgrade;
+ unsigned short group;
+ unsigned char flags;
+ unsigned short debug;
+ /* configuration file option */
+ char *proxyhost;
+ unsigned short proxyport;
+ char *xfercommand;
+ unsigned short chomp;
+ unsigned short nopassiveftp;
+ list_t *holdpkg;
+} pmconfig_t;
+
+#define FREECONF(p) do { if(p) { config_free(p); p = NULL; } } while(0)
+pmconfig_t *config_new();
+int config_free(pmconfig_t *config);
+int parseconfig(pmconfig_t *config);
#endif /* _PM_CONF_H */
diff --git a/src/pacman/download.c b/src/pacman/download.c
index cd5888fe..5f237b6c 100644
--- a/src/pacman/download.c
+++ b/src/pacman/download.c
@@ -35,6 +35,7 @@
#include "log.h"
#include "list.h"
#include "download.h"
+#include "conf.h"
/* progress bar */
static char sync_fnm[25];
@@ -45,12 +46,7 @@ static int xfered1;
static unsigned char eta_h, eta_m, eta_s;
/* pacman options */
-extern char *pmo_proxyhost;
-extern char *pmo_xfercommand;
-
-extern unsigned short pmo_proxyport;
-extern unsigned short pmo_nopassiveftp;
-extern unsigned short pmo_chomp;
+extern pmconfig_t *config;
extern int maxcols;
@@ -98,7 +94,7 @@ static int log_progress(netbuf *ctl, int xfered, void *arg)
printf(" %s [", sync_fnm);
cur = (int)((maxcols-64)*pct/100);
for(i = 0; i < maxcols-64; i++) {
- if(pmo_chomp) {
+ if(config->chomp) {
if(i < cur) {
printf("-");
} else {
@@ -204,8 +200,8 @@ int downloadfiles_forreal(list_t *servers, const char *localpath,
for(i = servers; i && !done; i = i->next) {
server_t *server = (server_t*)i->data;
- if(!pmo_xfercommand && strcmp(server->protocol, "file")) {
- if(!strcmp(server->protocol, "ftp") && !pmo_proxyhost) {
+ if(!config->xfercommand && strcmp(server->protocol, "file")) {
+ if(!strcmp(server->protocol, "ftp") && !config->proxyhost) {
FtpInit();
vprint("connecting to %s:21\n", server->server);
if(!FtpConnect(server->server, &control)) {
@@ -223,18 +219,18 @@ int downloadfiles_forreal(list_t *servers, const char *localpath,
FtpQuit(control);
continue;
}
- if(!pmo_nopassiveftp) {
+ if(!config->nopassiveftp) {
if(!FtpOptions(FTPLIB_CONNMODE, FTPLIB_PASSIVE, control)) {
fprintf(stderr, "warning: failed to set passive mode\n");
}
} else {
vprint("FTP passive mode not set\n");
}
- } else if(pmo_proxyhost) {
+ } else if(config->proxyhost) {
char *host;
unsigned port;
- host = (pmo_proxyhost) ? pmo_proxyhost : server->server;
- port = (pmo_proxyport) ? pmo_proxyport : 80;
+ host = (config->proxyhost) ? config->proxyhost : server->server;
+ port = (config->proxyport) ? config->proxyport : 80;
if(strchr(host, ':')) {
vprint("connecting to %s\n", host);
} else {
@@ -263,7 +259,7 @@ int downloadfiles_forreal(list_t *servers, const char *localpath,
continue;
}
- if(pmo_xfercommand && strcmp(server->protocol, "file")) {
+ if(config->xfercommand && strcmp(server->protocol, "file")) {
int ret;
int usepart = 0;
char *ptr1, *ptr2;
@@ -275,7 +271,7 @@ int downloadfiles_forreal(list_t *servers, const char *localpath,
snprintf(url, PATH_MAX, "%s://%s%s%s", server->protocol, server->server,
server->path, fn);
/* replace all occurrences of %o with fn.part */
- strncpy(origCmd, pmo_xfercommand, sizeof(origCmd));
+ strncpy(origCmd, config->xfercommand, sizeof(origCmd));
ptr1 = origCmd;
while((ptr2 = strstr(ptr1, "%o"))) {
usepart = 1;
@@ -354,7 +350,7 @@ int downloadfiles_forreal(list_t *servers, const char *localpath,
eta_m = 0;
eta_s = 0;
- if(!strcmp(server->protocol, "ftp") && !pmo_proxyhost) {
+ if(!strcmp(server->protocol, "ftp") && !config->proxyhost) {
if(!FtpSize(fn, &fsz, FTPLIB_IMAGE, control)) {
fprintf(stderr, "warning: failed to get filesize for %s\n", fn);
}
@@ -395,16 +391,16 @@ int downloadfiles_forreal(list_t *servers, const char *localpath,
filedone = 1;
}
}
- } else if(!strcmp(server->protocol, "http") || (pmo_proxyhost && strcmp(server->protocol, "file"))) {
+ } else if(!strcmp(server->protocol, "http") || (config->proxyhost && strcmp(server->protocol, "file"))) {
char src[PATH_MAX];
char *host;
unsigned port;
- if(!strcmp(server->protocol, "http") && !pmo_proxyhost) {
+ if(!strcmp(server->protocol, "http") && !config->proxyhost) {
/* HTTP servers hang up after each request (but not proxies), so
* we have to re-connect for each file.
*/
- host = (pmo_proxyhost) ? pmo_proxyhost : server->server;
- port = (pmo_proxyhost) ? pmo_proxyport : 80;
+ host = (config->proxyhost) ? config->proxyhost : server->server;
+ port = (config->proxyhost) ? config->proxyport : 80;
if(strchr(host, ':')) {
vprint("Connecting to %s\n", host);
} else {
@@ -426,7 +422,7 @@ int downloadfiles_forreal(list_t *servers, const char *localpath,
if(!stat(output, &st)) {
offset = (int)st.st_size;
}
- if(!pmo_proxyhost) {
+ if(!config->proxyhost) {
snprintf(src, PATH_MAX, "%s%s", server->path, fn);
} else {
snprintf(src, PATH_MAX, "%s://%s%s%s", server->protocol, server->server, server->path, fn);
@@ -475,10 +471,10 @@ int downloadfiles_forreal(list_t *servers, const char *localpath,
fflush(stdout);
}
}
- if(!pmo_xfercommand) {
- if(!strcmp(server->protocol, "ftp") && !pmo_proxyhost) {
+ if(!config->xfercommand) {
+ if(!strcmp(server->protocol, "ftp") && !config->proxyhost) {
FtpQuit(control);
- } else if(!strcmp(server->protocol, "http") || (pmo_proxyhost && strcmp(server->protocol, "file"))) {
+ } else if(!strcmp(server->protocol, "http") || (config->proxyhost && strcmp(server->protocol, "file"))) {
HttpQuit(control);
}
}
diff --git a/src/pacman/log.c b/src/pacman/log.c
index b5ab2400..6ff488a9 100644
--- a/src/pacman/log.c
+++ b/src/pacman/log.c
@@ -28,10 +28,12 @@
/* pacman */
#include "log.h"
+#include "list.h"
+#include "conf.h"
#define LOG_STR_LEN 256
-extern unsigned short pmo_verbose;
+extern pmconfig_t *config;
static int neednl; /* for cleaner message output */
@@ -101,7 +103,7 @@ void vprint(char *fmt, ...)
{
va_list args;
- if(pmo_verbose > 1) {
+ if(config->verbose > 1) {
if(neednl == 1) {
fprintf(stdout, "\n");
neednl = 0;
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index f5b0e152..418a1591 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -48,43 +48,7 @@
#include "sync.h"
#include "pacman.h"
-/* command line options */
-char *pmo_root = NULL;
-char *pmo_dbpath = NULL;
-char *pmo_cachedir = NULL;
-char *pmo_configfile = NULL;
-unsigned short pmo_op = PM_OP_MAIN;
-unsigned short pmo_verbose = 0;
-unsigned short pmo_version = 0;
-unsigned short pmo_help = 0;
-unsigned short pmo_upgrade = 0;
-unsigned short pmo_noconfirm = 0;
-unsigned short pmo_d_vertest = 0;
-unsigned short pmo_d_resolve = 0;
-unsigned short pmo_q_isfile = 0;
-unsigned short pmo_q_info = 0;
-unsigned short pmo_q_list = 0;
-unsigned short pmo_q_orphans = 0;
-unsigned short pmo_q_owns = 0;
-unsigned short pmo_q_search = 0;
-unsigned short pmo_s_clean = 0;
-unsigned short pmo_s_downloadonly = 0;
-list_t *pmo_s_ignore = NULL;
-unsigned short pmo_s_info = 0;
-unsigned short pmo_s_printuris = 0;
-unsigned short pmo_s_sync = 0;
-unsigned short pmo_s_search = 0;
-unsigned short pmo_s_upgrade = 0;
-unsigned short pmo_group = 0;
-unsigned char pmo_flags = 0;
-unsigned short pmo_debug = PM_LOG_WARNING;
-/* configuration file option */
-char *pmo_proxyhost = NULL;
-unsigned short pmo_proxyport = 0;
-char *pmo_xfercommand = NULL;
-unsigned short pmo_chomp = 0;
-unsigned short pmo_nopassiveftp = 0;
-list_t *pmo_holdpkg = NULL;
+pmconfig_t *config = NULL;
PM_DB *db_local;
/* list of (sync_t *) structs for sync locations */
@@ -119,6 +83,15 @@ int main(int argc, char *argv[])
signal(SIGINT, cleanup);
signal(SIGTERM, cleanup);
+ /* init config data */
+ config = config_new();
+ if(config == NULL) {
+ ERR(NL, "could not allocate memory for pacman config data.\n");
+ return(1);
+ }
+ config->op = PM_OP_MAIN;
+ config->debug |= PM_LOG_WARNING;
+
/* parse the command line */
ret = parseargs(argc, argv);
if(ret != 0) {
@@ -134,11 +107,11 @@ int main(int argc, char *argv[])
/* check if we have sufficient permission for the requested operation */
if(myuid > 0) {
- if(pmo_op != PM_OP_MAIN && pmo_op != PM_OP_QUERY && pmo_op != PM_OP_DEPTEST) {
- if((pmo_op == PM_OP_SYNC && !pmo_s_sync &&
- (pmo_s_search || pmo_s_printuris || pmo_group || pmo_q_list ||
- pmo_q_info)) || (pmo_op == PM_OP_DEPTEST && !pmo_d_resolve)) {
- /* special case: PM_OP_SYNC can be used w/ pmo_s_search by any user */
+ if(config->op != PM_OP_MAIN && config->op != PM_OP_QUERY && config->op != PM_OP_DEPTEST) {
+ if((config->op == PM_OP_SYNC && !config->op_s_sync &&
+ (config->op_s_search || config->op_s_printuris || config->group || config->op_q_list ||
+ config->op_q_info)) || (config->op == PM_OP_DEPTEST && !config->op_d_resolve)) {
+ /* special case: PM_OP_SYNC can be used w/ config->op_s_search by any user */
} else {
ERR(NL, "you cannot perform this operation unless you are root.\n");
exit(1);
@@ -146,41 +119,41 @@ int main(int argc, char *argv[])
}
}
- if(pmo_root == NULL) {
- pmo_root = strdup("/");
- }
-
- /* initialize pm library */
- if(alpm_initialize(pmo_root) == -1) {
- ERR(NL, "failed to initilize alpm library (%s)\n", alpm_strerror(pm_errno));
- cleanup(1);
+ if(config->root == NULL) {
+ config->root = strdup("/");
}
/* add a trailing '/' if there isn't one */
- if(pmo_root[strlen(pmo_root)-1] != '/') {
+ if(config->root[strlen(config->root)-1] != '/') {
char *ptr;
- MALLOC(ptr, strlen(pmo_root)+2);
- strcpy(ptr, pmo_root);
+ MALLOC(ptr, strlen(config->root)+2);
+ strcpy(ptr, config->root);
strcat(ptr, "/");
- FREE(pmo_root);
- pmo_root = ptr;
+ FREE(config->root);
+ config->root = ptr;
}
- if(pmo_configfile == NULL) {
- pmo_configfile = strdup(PACCONF);
+ /* initialize pm library */
+ if(alpm_initialize(config->root) == -1) {
+ ERR(NL, "failed to initilize alpm library (%s)\n", alpm_strerror(pm_errno));
+ cleanup(1);
}
- if(parseconfig(pmo_configfile) == -1) {
+
+ if(config->configfile == NULL) {
+ config->configfile = strdup(PACCONF);
+ }
+ if(parseconfig(config) == -1) {
cleanup(1);
}
- if(pmo_dbpath == NULL) {
- pmo_dbpath = strdup("var/lib/pacman");
+ if(config->dbpath == NULL) {
+ config->dbpath = strdup("var/lib/pacman");
}
- if(pmo_cachedir == NULL) {
- pmo_cachedir = strdup("var/cache/pacman");
+ if(config->cachedir == NULL) {
+ config->cachedir = strdup("var/cache/pacman");
}
/* set library parameters */
- if(alpm_set_option(PM_OPT_LOGMASK, (long)pmo_debug) == -1) {
+ if(alpm_set_option(PM_OPT_LOGMASK, (long)config->debug) == -1) {
ERR(NL, "failed to set option LOGMASK (%s)\n", alpm_strerror(pm_errno));
cleanup(1);
}
@@ -188,18 +161,18 @@ int main(int argc, char *argv[])
ERR(NL, "failed to set option LOGCB (%s)\n", alpm_strerror(pm_errno));
cleanup(1);
}
- if(alpm_set_option(PM_OPT_DBPATH, (long)pmo_dbpath) == -1) {
+ if(alpm_set_option(PM_OPT_DBPATH, (long)config->dbpath) == -1) {
ERR(NL, "failed to set option DBPATH (%s)\n", alpm_strerror(pm_errno));
cleanup(1);
}
- if(alpm_set_option(PM_OPT_CACHEDIR, (long)pmo_cachedir) == -1) {
+ if(alpm_set_option(PM_OPT_CACHEDIR, (long)config->cachedir) == -1) {
ERR(NL, "failed to set option CACHEDIR (%s)\n", alpm_strerror(pm_errno));
cleanup(1);
}
- if(pmo_verbose > 1) {
- printf("Root : %s\n", pmo_root);
- printf("DBPath: %s\n", pmo_dbpath);
+ if(config->verbose > 1) {
+ printf("Root : %s\n", config->root);
+ printf("DBPath: %s\n", config->dbpath);
list_display("Targets:", pm_targets);
}
@@ -211,7 +184,7 @@ int main(int argc, char *argv[])
}
/* start the requested operation */
- switch(pmo_op) {
+ switch(config->op) {
case PM_OP_ADD: ret = pacman_add(pm_targets); break;
case PM_OP_REMOVE: ret = pacman_remove(pm_targets); break;
case PM_OP_UPGRADE: ret = pacman_upgrade(pm_targets); break;
@@ -223,7 +196,7 @@ int main(int argc, char *argv[])
ERR(NL, "no operation specified (use -h for help)\n");
ret = 1;
}
- if(ret != 0 && pmo_d_vertest == 0) {
+ if(ret != 0 && config->op_d_vertest == 0) {
MSG(NL, "\n");
}
@@ -255,14 +228,8 @@ void cleanup(int signum)
FREE(sync->treename);
}
FREELIST(pmc_syncs);
- FREE(pmo_root);
- FREE(pmo_dbpath);
- FREE(pmo_configfile);
- FREE(pmo_proxyhost);
- FREE(pmo_xfercommand);
- FREELIST(pmo_holdpkg);
-
FREELIST(pm_targets);
+ FREECONF(config);
#ifndef CYGWIN
/* debug */
@@ -284,7 +251,7 @@ int pacman_deptest(list_t *targets)
return(0);
}
- if(pmo_d_vertest) {
+ if(config->op_d_vertest) {
if(targets->data && targets->next && targets->next->data) {
int ret = alpm_pkg_vercmp(targets->data, targets->next->data);
printf("%d\n", ret);
@@ -329,7 +296,7 @@ int pacman_deptest(list_t *targets)
case PM_ERR_UNSATISFIED_DEPS:
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
PM_DEPMISS *miss = alpm_list_getdata(lp);
- if(!pmo_d_resolve) {
+ if(!config->op_d_resolve) {
MSG(NL, "requires: %s", alpm_dep_getinfo(miss, PM_DEP_NAME));
switch((int)alpm_dep_getinfo(miss, PM_DEP_MOD)) {
case PM_DEP_MOD_EQ: MSG(CL, "=%s", alpm_dep_getinfo(miss, PM_DEP_VERSION)); break;
@@ -364,7 +331,7 @@ int pacman_deptest(list_t *targets)
/* attempt to resolve missing dependencies */
/* TODO: handle version comparators (eg, glibc>=2.2.5) */
if(ret == 126 && synctargs != NULL) {
- if(!pmo_d_resolve || pacman_sync(synctargs) != 0) {
+ if(!config->op_d_resolve || pacman_sync(synctargs) != 0) {
/* error (or -D not used) */
ret = 127;
}
@@ -439,75 +406,75 @@ int parseargs(int argc, char *argv[])
}
switch(opt) {
case 0: break;
- case 1000: pmo_noconfirm = 1; break;
+ case 1000: config->noconfirm = 1; break;
case 1001:
- if(pmo_configfile) {
- free(pmo_configfile);
+ if(config->configfile) {
+ free(config->configfile);
}
- pmo_configfile = strndup(optarg, PATH_MAX);
+ config->configfile = strndup(optarg, PATH_MAX);
break;
- case 1002: pmo_s_ignore = list_add(pmo_s_ignore, strdup(optarg)); break;
+ case 1002: config->op_s_ignore = list_add(config->op_s_ignore, strdup(optarg)); break;
case 1003:
- pmo_debug = atoi(optarg);
+ config->debug = atoi(optarg);
break;
- case 'A': pmo_op = (pmo_op != PM_OP_MAIN ? 0 : PM_OP_ADD); break;
- case 'D': pmo_op = (pmo_op != PM_OP_MAIN ? 0 : PM_OP_DEPTEST); pmo_d_resolve = 1; break;
- case 'F': pmo_op = (pmo_op != PM_OP_MAIN ? 0 : PM_OP_UPGRADE); pmo_flags |= PM_TRANS_FLAG_FRESHEN; break;
- case 'Q': pmo_op = (pmo_op != PM_OP_MAIN ? 0 : PM_OP_QUERY); break;
- case 'R': pmo_op = (pmo_op != PM_OP_MAIN ? 0 : PM_OP_REMOVE); break;
- case 'S': pmo_op = (pmo_op != PM_OP_MAIN ? 0 : PM_OP_SYNC); break;
- case 'T': pmo_op = (pmo_op != PM_OP_MAIN ? 0 : PM_OP_DEPTEST); break;
- case 'U': pmo_op = (pmo_op != PM_OP_MAIN ? 0 : PM_OP_UPGRADE); break;
- case 'V': pmo_version = 1; break;
- case 'Y': pmo_op = (pmo_op != PM_OP_MAIN ? 0 : PM_OP_DEPTEST); pmo_d_vertest = 1; break;
+ case 'A': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_ADD); break;
+ case 'D': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_DEPTEST); config->op_d_resolve = 1; break;
+ case 'F': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_UPGRADE); config->flags |= PM_TRANS_FLAG_FRESHEN; break;
+ case 'Q': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_QUERY); break;
+ case 'R': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_REMOVE); break;
+ case 'S': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_SYNC); break;
+ case 'T': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_DEPTEST); break;
+ case 'U': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_UPGRADE); break;
+ case 'V': config->version = 1; break;
+ case 'Y': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_DEPTEST); config->op_d_vertest = 1; break;
case 'b':
- if(pmo_dbpath) {
- free(pmo_dbpath);
+ if(config->dbpath) {
+ free(config->dbpath);
}
- pmo_dbpath = strdup(optarg);
+ config->dbpath = strdup(optarg);
break;
- case 'c': pmo_s_clean++; pmo_flags |= PM_TRANS_FLAG_CASCADE; break;
- case 'd': pmo_flags |= PM_TRANS_FLAG_NODEPS; break;
- case 'e': pmo_q_orphans = 1; break;
- case 'f': pmo_flags |= PM_TRANS_FLAG_FORCE; break;
- case 'g': pmo_group = 1; break;
- case 'h': pmo_help = 1; break;
- case 'i': pmo_q_info++; pmo_s_info++; break;
- case 'k': pmo_flags |= PM_TRANS_FLAG_DBONLY; break;
- case 'l': pmo_q_list = 1; break;
- case 'n': pmo_flags |= PM_TRANS_FLAG_NOSAVE; break;
- case 'o': pmo_q_owns = 1; break;
- case 'p': pmo_q_isfile = 1; pmo_s_printuris = 1; break;
+ case 'c': config->op_s_clean++; config->flags |= PM_TRANS_FLAG_CASCADE; break;
+ case 'd': config->flags |= PM_TRANS_FLAG_NODEPS; break;
+ case 'e': config->op_q_orphans = 1; break;
+ case 'f': config->flags |= PM_TRANS_FLAG_FORCE; break;
+ case 'g': config->group = 1; break;
+ case 'h': config->help = 1; break;
+ case 'i': config->op_q_info++; config->op_s_info++; break;
+ case 'k': config->flags |= PM_TRANS_FLAG_DBONLY; break;
+ case 'l': config->op_q_list = 1; break;
+ case 'n': config->flags |= PM_TRANS_FLAG_NOSAVE; break;
+ case 'o': config->op_q_owns = 1; break;
+ case 'p': config->op_q_isfile = 1; config->op_s_printuris = 1; break;
case 'r':
if(realpath(optarg, root) == NULL) {
perror("bad root path");
return(1);
}
- if(pmo_root) {
- free(pmo_root);
+ if(config->root) {
+ free(config->root);
}
- pmo_root = strdup(root);
+ config->root = strdup(root);
break;
- case 's': pmo_s_search = 1; pmo_q_search = 1; pmo_flags |= PM_TRANS_FLAG_RECURSE; break;
- case 'u': pmo_s_upgrade = 1; break;
- case 'v': pmo_verbose++; break;
- case 'w': pmo_s_downloadonly = 1; break;
- case 'y': pmo_s_sync = 1; break;
+ case 's': config->op_s_search = 1; config->op_q_search = 1; config->flags |= PM_TRANS_FLAG_RECURSE; break;
+ case 'u': config->op_s_upgrade = 1; break;
+ case 'v': config->verbose++; break;
+ case 'w': config->op_s_downloadonly = 1; break;
+ case 'y': config->op_s_sync = 1; break;
case '?': return(1);
default: return(1);
}
}
- if(pmo_op == 0) {
+ if(config->op == 0) {
ERR(NL, "only one operation may be used at a time\n");
return(1);
}
- if(pmo_help) {
- usage(pmo_op, basename(argv[0]));
+ if(config->help) {
+ usage(config->op, basename(argv[0]));
return(2);
}
- if(pmo_version) {
+ if(config->version) {
version();
return(2);
}
@@ -552,7 +519,7 @@ void usage(int op, char *myname)
printf(" -n, --nosave remove configuration files as well\n");
printf(" -s, --recursive remove dependencies also (that won't break packages)\n");
} else if(op == PM_OP_UPGRADE) {
- if(pmo_flags & PM_TRANS_FLAG_FRESHEN) {
+ if(config->flags & PM_TRANS_FLAG_FRESHEN) {
printf("usage: %s {-F --freshen} [options] <file>\n", myname);
} else {
printf("usage: %s {-U --upgrade} [options] <file>\n", myname);
diff --git a/src/pacman/query.c b/src/pacman/query.c
index d13c1af9..ce444c48 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -32,14 +32,9 @@
#include "db.h"
#include "query.h"
#include "log.h"
+#include "conf.h"
-extern unsigned short pmo_q_isfile;
-extern unsigned short pmo_q_info;
-extern unsigned short pmo_q_list;
-extern unsigned short pmo_q_orphans;
-extern unsigned short pmo_q_owns;
-extern unsigned short pmo_q_search;
-extern unsigned short pmo_group;
+extern pmconfig_t *config;
extern PM_DB *db_local;
static int query_fileowner(PM_DB *db, char *filename)
@@ -98,7 +93,7 @@ int pacman_query(list_t *targets)
char *package = NULL;
int done = 0;
- if(pmo_q_search) {
+ if(config->op_q_search) {
if(db_search(db_local, "local", targets)) {
return(1);
}
@@ -116,7 +111,7 @@ int pacman_query(list_t *targets)
}
/* looking for groups */
- if(pmo_group) {
+ if(config->group) {
PM_LIST *lp;
if(targets == NULL) {
for(lp = alpm_db_getgrpcache(db_local); lp; lp = alpm_list_next(lp)) {
@@ -147,7 +142,7 @@ int pacman_query(list_t *targets)
}
/* output info for a .tar.gz package */
- if(pmo_q_isfile) {
+ if(config->op_q_isfile) {
if(package == NULL) {
ERR(NL, "no package file was specified for --file\n");
return(1);
@@ -156,14 +151,14 @@ int pacman_query(list_t *targets)
ERR(NL, "failed to load package '%s' (%s)\n", package, alpm_strerror(pm_errno));
return(1);
}
- if(pmo_q_info) {
+ if(config->op_q_info) {
dump_pkg_full(info, 0);
MSG(NL, "\n");
}
- if(pmo_q_list) {
+ if(config->op_q_list) {
dump_pkg_files(info);
}
- if(!pmo_q_info && !pmo_q_list) {
+ if(!config->op_q_info && !config->op_q_list) {
MSG(NL, "%s %s\n", (char *)alpm_pkg_getinfo(info, PM_PKG_NAME),
(char *)alpm_pkg_getinfo(info, PM_PKG_VERSION));
}
@@ -172,7 +167,7 @@ int pacman_query(list_t *targets)
}
/* determine the owner of a file */
- if(pmo_q_owns) {
+ if(config->op_q_owns) {
return(query_fileowner(db_local, package));
}
@@ -187,17 +182,17 @@ int pacman_query(list_t *targets)
pkgname = alpm_pkg_getinfo(tmpp, PM_PKG_NAME);
pkgver = alpm_pkg_getinfo(tmpp, PM_PKG_VERSION);
- if(pmo_q_list || pmo_q_orphans) {
+ if(config->op_q_list || config->op_q_orphans) {
info = alpm_db_readpkg(db_local, pkgname);
if(info == NULL) {
/* something weird happened */
ERR(NL, "package \"%s\" not found\n", pkgname);
return(1);
}
- if(pmo_q_list) {
+ if(config->op_q_list) {
dump_pkg_files(info);
}
- if(pmo_q_orphans) {
+ if(config->op_q_orphans) {
if(alpm_pkg_getinfo(info, PM_PKG_REQUIREDBY) == NULL
&& (int)alpm_pkg_getinfo(info, PM_PKG_REASON) == PM_PKG_REASON_EXPLICIT) {
MSG(NL, "%s %s\n", pkgname, pkgver);
@@ -217,14 +212,14 @@ int pacman_query(list_t *targets)
}
/* find a target */
- if(pmo_q_info || pmo_q_list) {
- if(pmo_q_info) {
- dump_pkg_full(info, pmo_q_info);
+ if(config->op_q_info || config->op_q_list) {
+ if(config->op_q_info) {
+ dump_pkg_full(info, config->op_q_info);
}
- if(pmo_q_list) {
+ if(config->op_q_list) {
dump_pkg_files(info);
}
- } else if(pmo_q_orphans) {
+ } else if(config->op_q_orphans) {
if(alpm_pkg_getinfo(info, PM_PKG_REQUIREDBY) == NULL) {
MSG(NL, "%s %s\n", pkgname, pkgver);
}
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index fd292151..100e22f3 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -29,8 +29,9 @@
#include "log.h"
#include "list.h"
#include "trans.h"
+#include "conf.h"
-extern unsigned char pmo_flags;
+extern pmconfig_t *config;
extern PM_DB *db_local;
@@ -73,7 +74,7 @@ int pacman_remove(list_t *targets)
/* Step 1: create a new transaction
*/
- if(alpm_trans_init(PM_TRANS_TYPE_REMOVE, pmo_flags, cb_trans_evt, cb_trans_conv) == -1) {
+ if(alpm_trans_init(PM_TRANS_TYPE_REMOVE, config->flags, cb_trans_evt, cb_trans_conv) == -1) {
ERR(NL, "failed to init transaction (%s)\n", alpm_strerror(pm_errno));
goto error;
}
@@ -106,7 +107,7 @@ int pacman_remove(list_t *targets)
/* Warn user in case of dangerous operation
*/
- if(pmo_flags & PM_TRANS_FLAG_RECURSE || pmo_flags & PM_TRANS_FLAG_CASCADE) {
+ if(config->flags & PM_TRANS_FLAG_RECURSE || config->flags & PM_TRANS_FLAG_CASCADE) {
PM_LIST *lp;
/* list transaction targets */
for(lp = alpm_list_first(alpm_trans_getinfo(PM_TRANS_PACKAGES)); lp; lp = alpm_list_next(lp)) {
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 16a05099..968632f4 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -41,19 +41,9 @@
#include "trans.h"
#include "sync.h"
#include "pacman.h"
+#include "conf.h"
-extern unsigned short pmo_noconfirm;
-extern unsigned short pmo_d_resolve;
-extern unsigned short pmo_q_list;
-extern unsigned short pmo_s_clean;
-extern unsigned short pmo_s_downloadonly;
-extern unsigned short pmo_s_info;
-extern unsigned short pmo_s_printuris;
-extern unsigned short pmo_s_search;
-extern unsigned short pmo_s_sync;
-extern unsigned short pmo_s_upgrade;
-extern unsigned short pmo_group;
-extern unsigned char pmo_flags;
+extern pmconfig_t *config;
extern PM_DB *db_local;
extern list_t *pmc_syncs;
@@ -379,8 +369,8 @@ int pacman_sync(list_t *targets)
return(1);
}
- if(pmo_s_clean) {
- return(sync_cleancache(pmo_s_clean));
+ if(config->op_s_clean) {
+ return(sync_cleancache(config->op_s_clean));
}
/* open the database(s) */
@@ -393,7 +383,7 @@ int pacman_sync(list_t *targets)
}
}
- if(pmo_s_sync) {
+ if(config->op_s_sync) {
/* grab a fresh package list */
MSG(NL, ":: Synchronizing package databases...\n");
alpm_logaction("synchronizing package lists");
@@ -402,31 +392,31 @@ int pacman_sync(list_t *targets)
}
}
- if(pmo_s_search) {
+ if(config->op_s_search) {
return(sync_search(pmc_syncs, targets));
}
- if(pmo_group) {
+ if(config->group) {
return(sync_group(pmc_syncs, targets));
}
- if(pmo_s_info) {
+ if(config->op_s_info) {
return(sync_info(pmc_syncs, targets));
}
- if(pmo_q_list) {
+ if(config->op_q_list) {
return(sync_list(pmc_syncs, targets));
}
/* Step 1: create a new transaction...
*/
- if(alpm_trans_init(PM_TRANS_TYPE_SYNC, pmo_flags, cb_trans_evt, cb_trans_conv) == -1) {
+ if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt, cb_trans_conv) == -1) {
ERR(NL, "failed to init transaction (%s)\n", alpm_strerror(pm_errno));
retval = 1;
goto cleanup;
}
- if(pmo_s_upgrade) {
+ if(config->op_s_upgrade) {
MSG(NL, ":: Starting local database upgrade...\n");
alpm_logaction("starting full system upgrade");
if(alpm_trans_sysupgrade() == -1) {
@@ -514,7 +504,7 @@ int pacman_sync(list_t *targets)
}
/* list targets and get confirmation */
- if(!pmo_s_printuris) {
+ if(!config->op_s_printuris) {
list_t *list = NULL;
char *str;
unsigned long totalsize = 0;
@@ -573,8 +563,8 @@ int pacman_sync(list_t *targets)
FREELIST(list);
FREE(str);
- if(pmo_s_downloadonly) {
- if(pmo_noconfirm) {
+ if(config->op_s_downloadonly) {
+ if(config->noconfirm) {
MSG(NL, "\nBeginning download...\n");
confirm = 1;
} else {
@@ -583,10 +573,10 @@ int pacman_sync(list_t *targets)
}
} else {
/* don't get any confirmation if we're called from makepkg */
- if(pmo_d_resolve) {
+ if(config->op_d_resolve) {
confirm = 1;
} else {
- if(pmo_noconfirm) {
+ if(config->noconfirm) {
MSG(NL, "\nBeginning upgrade process...\n");
confirm = 1;
} else {
@@ -622,7 +612,7 @@ int pacman_sync(list_t *targets)
pkgname = alpm_pkg_getinfo(spkg, PM_PKG_NAME);
pkgver = alpm_pkg_getinfo(spkg, PM_PKG_VERSION);
- if(pmo_s_printuris) {
+ if(config->op_s_printuris) {
server_t *server = (server_t*)current->servers->data;
snprintf(path, PATH_MAX, "%s-%s" PM_EXT_PKG, pkgname, pkgver);
if(!strcmp(server->protocol, "file")) {
@@ -670,7 +660,7 @@ int pacman_sync(list_t *targets)
FREELIST(files);
}
}
- if(pmo_s_printuris) {
+ if(config->op_s_printuris) {
goto cleanup;
}
MSG(NL, "\n");
@@ -711,7 +701,7 @@ int pacman_sync(list_t *targets)
}
MSG(CL, "done.\n");
- if(pmo_s_downloadonly) {
+ if(config->op_s_downloadonly) {
goto cleanup;
}
@@ -722,7 +712,7 @@ int pacman_sync(list_t *targets)
goto cleanup;
}
- if(!varcache && !pmo_s_downloadonly) {
+ if(!varcache && !config->op_s_downloadonly) {
/* delete packages */
for(i = files; i; i = i->next) {
unlink(i->data);
diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c
index 9149ee69..283c1a98 100644
--- a/src/pacman/upgrade.c
+++ b/src/pacman/upgrade.c
@@ -27,14 +27,15 @@
/* pacman */
#include "list.h"
#include "add.h"
+#include "conf.h"
-extern unsigned char pmo_upgrade;
+extern pmconfig_t *config;
int pacman_upgrade(list_t *targets)
{
/* this is basically just a remove-then-add process. pacman_add() will */
/* handle it */
- pmo_upgrade = 1;
+ config->upgrade = 1;
return(pacman_add(targets));
}