diff options
Diffstat (limited to 'src/pacman/pacman.c')
-rw-r--r-- | src/pacman/pacman.c | 74 |
1 files changed, 24 insertions, 50 deletions
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 1a6e3eb4..afc79f6f 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -50,7 +50,6 @@ /* pacman */ #include "pacman.h" #include "util.h" -#include "callback.h" #include "conf.h" /* list of targets specified on command line */ @@ -264,8 +263,8 @@ static void setuseragent(void) */ static void cleanup(int ret) { /* free alpm library resources */ - if(alpm_release() == -1) { - pm_printf(PM_LOG_ERROR, "%s\n", alpm_strerrorlast()); + if(config->handle && alpm_release(config->handle) == -1) { + pm_printf(PM_LOG_ERROR, "error releasing alpm library\n"); } /* free memory */ @@ -308,12 +307,12 @@ static void handler(int signum) } else if(signum == SIGINT) { const char *msg = "\nInterrupt signal received\n"; xwrite(err, msg, strlen(msg)); - if(alpm_trans_interrupt() == 0) { + if(alpm_trans_interrupt(config->handle) == 0) { /* a transaction is being interrupted, don't exit pacman yet. */ return; } /* no commiting transaction, we can release it now and then exit pacman */ - alpm_trans_release(); + alpm_trans_release(config->handle); /* output a newline to be sure we clear any line we may be on */ xwrite(out, "\n", 1); } @@ -322,18 +321,16 @@ static void handler(int signum) #define check_optarg() if(!optarg) { return 1; } -typedef int (*fn_add) (const char *s); - -static int parsearg_util_addlist(fn_add fn) +static int parsearg_util_addlist(alpm_list_t **list) { - alpm_list_t *list = NULL, *item = NULL; /* lists for splitting strings */ + alpm_list_t *split, *item; check_optarg(); - list = strsplit(optarg, ','); - for(item = list; item; item = alpm_list_next(item)) { - fn((char *)alpm_list_getdata(item)); + split = strsplit(optarg, ','); + for(item = split; item; item = alpm_list_next(item)) { + *list = alpm_list_add(*list, item->data); } - FREELIST(list); + alpm_list_free(split); return 0; } @@ -385,7 +382,7 @@ static int parsearg_global(int opt) switch(opt) { case OP_ARCH: check_optarg(); - config_set_arch(optarg); + config_set_arch(strdup(optarg)); break; case OP_ASK: check_optarg(); @@ -394,11 +391,7 @@ static int parsearg_global(int opt) break; case OP_CACHEDIR: check_optarg(); - if(alpm_option_add_cachedir(optarg) != 0) { - pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"), - optarg, alpm_strerrorlast()); - return 1; - } + config->cachedirs = alpm_list_add(config->cachedirs, strdup(optarg)); break; case OP_CONFIG: check_optarg(); @@ -535,10 +528,10 @@ static int parsearg_upgrade(int opt) case OP_ASDEPS: config->flags |= PM_TRANS_FLAG_ALLDEPS; break; case OP_ASEXPLICIT: config->flags |= PM_TRANS_FLAG_ALLEXPLICIT; break; case OP_IGNORE: - parsearg_util_addlist(alpm_option_add_ignorepkg); + parsearg_util_addlist(&(config->ignorepkg)); break; case OP_IGNOREGROUP: - parsearg_util_addlist(alpm_option_add_ignoregrp); + parsearg_util_addlist(&(config->ignoregrp)); break; default: return 1; } @@ -732,8 +725,9 @@ static void cl_to_log(int argc, char* argv[]) size += strlen(argv[i]) + 1; } char *cl_text = malloc(size); - if(!cl_text) + if(!cl_text) { return; + } char *p = cl_text; for(i = 0; i<argc-1; i++) { strcpy(p, argv[i]); @@ -741,7 +735,7 @@ static void cl_to_log(int argc, char* argv[]) *p++ = ' '; } strcpy(p, argv[i]); - alpm_logaction("Running '%s'\n", cl_text); + alpm_logaction(config->handle, "Running '%s'\n", cl_text); free(cl_text); } @@ -799,22 +793,6 @@ int main(int argc, char *argv[]) config->noprogressbar = 1; } - /* initialize library */ - if(alpm_initialize() == -1) { - pm_printf(PM_LOG_ERROR, _("failed to initialize alpm library (%s)\n"), - alpm_strerrorlast()); - cleanup(EXIT_FAILURE); - } - - /* Setup logging as soon as possible, to print out maximum debugging info */ - alpm_option_set_logcb(cb_log); - alpm_option_set_dlcb(cb_dl_progress); - /* define paths to reasonable defaults */ - alpm_option_set_root(ROOTDIR); - alpm_option_set_dbpath(DBPATH); - alpm_option_set_signaturedir(GPGDIR); - alpm_option_set_logfile(LOGFILE); - /* Priority of options: * 1. command line * 2. config file @@ -873,18 +851,13 @@ int main(int argc, char *argv[]) cleanup(ret); } - /* set TotalDownload callback if option enabled */ - if(config->totaldownload) { - alpm_option_set_totaldlcb(cb_dl_total); - } - /* noask is meant to be non-interactive */ if(config->noask) { config->noconfirm = 1; } /* set up the print operations */ - if(config->print) { + if(config->print && !config->op_s_clean) { config->noconfirm = 1; config->flags |= PM_TRANS_FLAG_NOCONFLICTS; config->flags |= PM_TRANS_FLAG_NOLOCK; @@ -902,16 +875,17 @@ int main(int argc, char *argv[]) if(config->verbose > 0) { alpm_list_t *i; - printf("Root : %s\n", alpm_option_get_root()); + printf("Root : %s\n", alpm_option_get_root(config->handle)); printf("Conf File : %s\n", config->configfile); - printf("DB Path : %s\n", alpm_option_get_dbpath()); + printf("DB Path : %s\n", alpm_option_get_dbpath(config->handle)); printf("Cache Dirs: "); - for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) { + for(i = alpm_option_get_cachedirs(config->handle); i; i = alpm_list_next(i)) { printf("%s ", (char *)alpm_list_getdata(i)); } printf("\n"); - printf("Lock File : %s\n", alpm_option_get_lockfile()); - printf("Log File : %s\n", alpm_option_get_logfile()); + printf("Lock File : %s\n", alpm_option_get_lockfile(config->handle)); + printf("Log File : %s\n", alpm_option_get_logfile(config->handle)); + printf("GPG Dir : %s\n", alpm_option_get_signaturedir(config->handle)); list_display("Targets :", pm_targets); } |