diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/pacman/Makefile.am | 2 | ||||
-rw-r--r-- | src/pacman/callback.c | 47 | ||||
-rw-r--r-- | src/pacman/conf.c | 8 | ||||
-rw-r--r-- | src/pacman/conf.h | 5 | ||||
-rw-r--r-- | src/pacman/database.c | 10 | ||||
-rw-r--r-- | src/pacman/deptest.c | 4 | ||||
-rw-r--r-- | src/pacman/package.c | 22 | ||||
-rw-r--r-- | src/pacman/pacman.c | 158 | ||||
-rw-r--r-- | src/pacman/query.c | 68 | ||||
-rw-r--r-- | src/pacman/remove.c | 16 | ||||
-rw-r--r-- | src/pacman/sync.c | 94 | ||||
-rw-r--r-- | src/pacman/upgrade.c | 22 | ||||
-rw-r--r-- | src/pacman/util.c | 227 | ||||
-rw-r--r-- | src/pacman/util.h | 1 | ||||
-rw-r--r-- | src/util/cleanupdelta.c | 2 | ||||
-rw-r--r-- | src/util/pactree.c | 18 | ||||
-rw-r--r-- | src/util/testdb.c | 20 | ||||
-rw-r--r-- | src/util/testpkg.c | 6 | ||||
-rw-r--r-- | src/util/vercmp.c | 6 |
19 files changed, 396 insertions, 340 deletions
diff --git a/src/pacman/Makefile.am b/src/pacman/Makefile.am index 31e8b134..333b8193 100644 --- a/src/pacman/Makefile.am +++ b/src/pacman/Makefile.am @@ -1,6 +1,7 @@ # paths set at make time conffile = ${sysconfdir}/pacman.conf dbpath = ${localstatedir}/lib/pacman/ +gpgdir = ${sysconfdir}/pacman.d/gnupg/ cachedir = ${localstatedir}/cache/pacman/pkg/ logfile = ${localstatedir}/log/pacman.log @@ -10,6 +11,7 @@ DEFS = -DLOCALEDIR=\"@localedir@\" \ -DCONFFILE=\"$(conffile)\" \ -DROOTDIR=\"$(ROOTDIR)\" \ -DDBPATH=\"$(dbpath)\" \ + -DGPGDIR=\"$(gpgdir)\" \ -DCACHEDIR=\"$(cachedir)\" \ -DLOGFILE=\"$(logfile)\" \ @DEFS@ diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 5edcc966..7fb52129 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -81,7 +81,7 @@ static double get_update_timediff(int first_call) } } - return(retval); + return retval; } /* refactored from cb_trans_progress */ @@ -492,10 +492,11 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) int totaldownload = 0; off_t xfered, total; - double rate = 0.0, timediff = 0.0, f_xfered = 0.0; + double rate = 0.0, timediff = 0.0; unsigned int eta_h = 0, eta_m = 0, eta_s = 0; + double rate_human, xfered_human; + const char *rate_label, *xfered_label; int file_percent = 0, total_percent = 0; - char rate_size = 'K', xfered_size = 'K'; if(config->noprogressbar || file_total == -1) { if(file_xfered == 0) { @@ -557,7 +558,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) diff_sec = current_time.tv_sec - initial_time.tv_sec; diff_usec = current_time.tv_usec - initial_time.tv_usec; timediff = diff_sec + (diff_usec / 1000000.0); - rate = xfered / (timediff * 1024.0); + rate = xfered / timediff; /* round elapsed time to the nearest second */ eta_s = (int)(timediff + 0.5); @@ -569,10 +570,10 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) /* return if the calling interval was too short */ return; } - rate = (xfered - xfered_last) / (timediff * 1024.0); + rate = (xfered - xfered_last) / timediff; /* average rate to reduce jumpiness */ rate = (rate + 2 * rate_last) / 3; - eta_s = (total - xfered) / (rate * 1024.0); + eta_s = (total - xfered) / rate; rate_last = rate; xfered_last = xfered; } @@ -626,37 +627,13 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) } - /* Awesome formatting for progress bar. We need a mess of Kb->Mb->Gb stuff - * here. We'll use limit of 2048 for each until we get some empirical */ - /* rate_size = 'K'; was set above */ - if(rate > 2048.0) { - rate /= 1024.0; - rate_size = 'M'; - if(rate > 2048.0) { - rate /= 1024.0; - rate_size = 'G'; - /* we should not go higher than this for a few years (9999.9 Gb/s?)*/ - } - } - - f_xfered = xfered / 1024.0; /* convert to K by default */ - /* xfered_size = 'K'; was set above */ - if(f_xfered > 2048.0) { - f_xfered /= 1024.0; - xfered_size = 'M'; - if(f_xfered > 2048.0) { - f_xfered /= 1024.0; - xfered_size = 'G'; - /* I should seriously hope that archlinux packages never break - * the 9999.9GB mark... we'd have more serious problems than the progress - * bar in pacman */ - } - } + rate_human = humanize_size((off_t)rate, '\0', 0, &rate_label); + xfered_human = humanize_size(xfered, '\0', 0, &xfered_label); /* 1 space + filenamelen + 1 space + 7 for size + 1 + 7 for rate + 2 for /s + 1 space + 8 for eta */ - printf(" %ls%-*s %6.1f%c %#6.1f%c/s %02u:%02u:%02u", wcfname, - padwid, "", f_xfered, xfered_size, - rate, rate_size, eta_h, eta_m, eta_s); + printf(" %ls%-*s %6.1f%s %#6.1f%s/s %02u:%02u:%02u", wcfname, + padwid, "", xfered_human, xfered_label, rate_human, rate_label, + eta_h, eta_m, eta_s); free(fname); free(wcfname); diff --git a/src/pacman/conf.c b/src/pacman/conf.c index e2a168ee..69110ab9 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -38,7 +38,7 @@ config_t *config_new(void) pm_fprintf(stderr, PM_LOG_ERROR, _("malloc failure: could not allocate %zd bytes\n"), sizeof(config_t)); - return(NULL); + return NULL; } /* defaults which may get overridden later */ newconfig->op = PM_OP_MAIN; @@ -46,13 +46,13 @@ config_t *config_new(void) /* CONFFILE is defined at compile-time */ newconfig->configfile = strdup(CONFFILE); - return(newconfig); + return newconfig; } int config_free(config_t *oldconfig) { if(oldconfig == NULL) { - return(-1); + return -1; } FREELIST(oldconfig->holdpkg); @@ -66,7 +66,7 @@ int config_free(config_t *oldconfig) free(oldconfig); oldconfig = NULL; - return(0); + return 0; } /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 92c379fc..d85f33ee 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -40,6 +40,7 @@ typedef struct __config_t { char *rootdir; char *dbpath; char *logfile; + char *gpgdir; /* TODO how to handle cachedirs? */ unsigned short op_q_isfile; @@ -69,7 +70,6 @@ typedef struct __config_t { /* conf file options */ unsigned short chomp; /* I Love Candy! */ - unsigned short showsize; /* show individual package sizes */ /* When downloading, display the amount downloaded, rate, ETA, and percent * downloaded of the total download list */ unsigned short totaldownload; @@ -106,7 +106,8 @@ enum { OP_NEEDED, OP_ASEXPLICIT, OP_ARCH, - OP_PRINTFORMAT + OP_PRINTFORMAT, + OP_GPGDIR }; /* clean method */ diff --git a/src/pacman/database.c b/src/pacman/database.c index 36433f33..9d6edab5 100644 --- a/src/pacman/database.c +++ b/src/pacman/database.c @@ -47,7 +47,7 @@ int pacman_database(alpm_list_t *targets) if(targets == NULL) { pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n")); - return(1); + return 1; } if(config->flags & PM_TRANS_FLAG_ALLDEPS) { /* --asdeps */ @@ -56,12 +56,12 @@ int pacman_database(alpm_list_t *targets) reason = PM_PKG_REASON_EXPLICIT; } else { pm_printf(PM_LOG_ERROR, _("no install reason specified (use -h for help)\n")); - return(1); + return 1; } /* Lock database */ if(trans_init(0) == -1) { - return(1); + return 1; } db_local = alpm_option_get_localdb(); @@ -82,9 +82,9 @@ int pacman_database(alpm_list_t *targets) /* Unlock database */ if(trans_release() == -1) { - return(1); + return 1; } - return(retval); + return retval; } /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/deptest.c b/src/pacman/deptest.c index 8895b487..cc1e565b 100644 --- a/src/pacman/deptest.c +++ b/src/pacman/deptest.c @@ -47,7 +47,7 @@ int pacman_deptest(alpm_list_t *targets) } if(deps == NULL) { - return(0); + return 0; } for(i = deps; i; i = alpm_list_next(i)) { @@ -56,7 +56,7 @@ int pacman_deptest(alpm_list_t *targets) printf("%s\n", dep); } alpm_list_free(deps); - return(127); + return 127; } /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/package.c b/src/pacman/package.c index 77a5ee72..e3a4614a 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -51,6 +51,8 @@ void dump_pkg_full(pmpkg_t *pkg, int level) const char *reason; time_t bdate, idate; char bdatestr[50] = "", idatestr[50] = ""; + const char *label; + double size; const alpm_list_t *i; alpm_list_t *requiredby = NULL, *depstrings = NULL; @@ -105,17 +107,17 @@ void dump_pkg_full(pmpkg_t *pkg, int level) } list_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg)); list_display(_("Replaces :"), alpm_pkg_get_replaces(pkg)); + + size = humanize_size(alpm_pkg_get_size(pkg), 'K', 1, &label); if(level < 0) { - printf(_("Download Size : %6.2f K\n"), - (double)alpm_pkg_get_size(pkg) / 1024.0); - } - if(level == 0) { - printf(_("Compressed Size: %6.2f K\n"), - (double)alpm_pkg_get_size(pkg) / 1024.0); + printf(_("Download Size : %6.2f %s\n"), size, label); + } else if(level == 0) { + printf(_("Compressed Size: %6.2f %s\n"), size, label); } - printf(_("Installed Size : %6.2f K\n"), - (double)alpm_pkg_get_isize(pkg) / 1024.0); + size = humanize_size(alpm_pkg_get_isize(pkg), 'K', 1, &label); + printf(_("Installed Size : %6.2f %s\n"), size, label); + string_display(_("Packager :"), alpm_pkg_get_packager(pkg)); string_display(_("Architecture :"), alpm_pkg_get_arch(pkg)); string_display(_("Build Date :"), bdatestr); @@ -173,7 +175,7 @@ static const char *get_backup_file_status(const char *root, if(md5sum == NULL) { pm_fprintf(stderr, PM_LOG_ERROR, _("could not calculate checksums for %s\n"), path); - return(NULL); + return NULL; } /* if checksums don't match, file has been modified */ @@ -195,7 +197,7 @@ static const char *get_backup_file_status(const char *root, ret = "UNKNOWN"; } } - return(ret); + return ret; } /* Display list of backup files and their modification states diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 0ad03540..db819a7d 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -66,9 +66,9 @@ static int options_cmp(const void *p1, const void *p2) const char *s1 = p1; const char *s2 = p2; - if(s1 == s2) return(0); - if(!s1) return(-1); - if(!s2) return(1); + if(s1 == s2) return 0; + if(!s1) return -1; + if(!s2) return 1; /* First skip all spaces in both strings */ while(isspace((unsigned char)*s1)) { s1++; @@ -87,15 +87,15 @@ static int options_cmp(const void *p1, const void *p2) s2++; } else if(*s2 == '-') { /* s1 short, s2 long */ - return(-1); + return -1; } else if(*s1 == '-') { /* s1 long, s2 short */ - return(1); + return 1; } /* two short -> strcmp */ } - return(strcmp(s1, s2)); + return strcmp(s1, s2); } /** Display usage/syntax for the specified operation. @@ -207,6 +207,7 @@ static void usage(int op, const char * const myname) addlist(_(" --cachedir <dir> set an alternate package cache location\n")); addlist(_(" --config <path> set an alternate configuration file\n")); addlist(_(" --debug display debug messages\n")); + addlist(_(" --gpgdir <path> set an alternate home directory for GnuPG\n")); addlist(_(" --logfile <path> set an alternate log file\n")); addlist(_(" --noconfirm do not ask for any confirmation\n")); } @@ -302,7 +303,7 @@ static ssize_t xwrite(int fd, const void *buf, size_t count) do { ret = write(fd, buf, count); } while(ret == -1 && errno == EINTR); - return(ret); + return ret; } /** Catches thrown signals. Performs necessary cleanup to ensure database is @@ -321,7 +322,7 @@ static void handler(int signum) xwrite(out, msg1, strlen(msg1)); xwrite(err, msg2, strlen(msg2)); exit(signum); - } else if((signum == SIGINT)) { + } else if(signum == SIGINT) { const char *msg = "\nInterrupt signal received\n"; xwrite(err, msg, strlen(msg)); if(alpm_trans_interrupt() == 0) { @@ -390,6 +391,17 @@ static void setlibpaths(void) } } + /* Set GnuPG's home directory. This is not relative to rootdir, even if + * rootdir is defined. Reasoning: gpgdir contains configuration data. */ + if(config->gpgdir) { + ret = alpm_option_set_signaturedir(config->gpgdir); + if(ret != 0) { + pm_printf(PM_LOG_ERROR, _("problem setting gpgdir '%s' (%s)\n"), + config->gpgdir, alpm_strerrorlast()); + cleanup(ret); + } + } + /* add a default cachedir if one wasn't specified */ if(alpm_option_get_cachedirs() == NULL) { alpm_option_add_cachedir(CACHEDIR); @@ -398,9 +410,9 @@ static void setlibpaths(void) } } -#define check_optarg() if(!optarg) { return(1); } +#define check_optarg() if(!optarg) { return 1; } -typedef void (*fn_add) (const char *s); +typedef int (*fn_add) (const char *s); static int parsearg_util_addlist(fn_add fn) { @@ -412,7 +424,7 @@ static int parsearg_util_addlist(fn_add fn) fn((char *)alpm_list_getdata(item)); } FREELIST(list); - return(0); + return 0; } /** Helper function for parsing operation from command-line arguments. @@ -449,9 +461,9 @@ static int parsearg_op(int opt, int dryrun) if(dryrun) break; config->help = 1; break; default: - return(1); + return 1; } - return(0); + return 0; } /** Helper functions for parsing command-line arguments. @@ -472,7 +484,7 @@ static int parsearg_global(int opt) if(alpm_option_add_cachedir(optarg) != 0) { pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"), optarg, alpm_strerrorlast()); - return(1); + return 1; } break; case OP_CONFIG: @@ -497,7 +509,7 @@ static int parsearg_global(int opt) default: pm_printf(PM_LOG_ERROR, _("'%s' is not a valid debug level\n"), optarg); - return(1); + return 1; } } else { config->logmask |= PM_LOG_DEBUG; @@ -505,6 +517,9 @@ static int parsearg_global(int opt) /* progress bars get wonky with debug on, shut them off */ config->noprogressbar = 1; break; + case OP_GPGDIR: + config->gpgdir = strdup(optarg); + break; case OP_LOGFILE: check_optarg(); config->logfile = strndup(optarg, PATH_MAX); @@ -516,9 +531,9 @@ static int parsearg_global(int opt) break; case 'r': check_optarg(); config->rootdir = strdup(optarg); break; case 'v': (config->verbose)++; break; - default: return(1); + default: return 1; } - return(0); + return 0; } static int parsearg_database(int opt) @@ -526,9 +541,9 @@ static int parsearg_database(int opt) switch(opt) { case OP_ASDEPS: config->flags |= PM_TRANS_FLAG_ALLDEPS; break; case OP_ASEXPLICIT: config->flags |= PM_TRANS_FLAG_ALLEXPLICIT; break; - default: return(1); + default: return 1; } - return(0); + return 0; } static int parsearg_query(int opt) @@ -548,9 +563,9 @@ static int parsearg_query(int opt) case 's': config->op_q_search = 1; break; case 't': config->op_q_unrequired = 1; break; case 'u': config->op_q_upgrade = 1; break; - default: return(1); + default: return 1; } - return(0); + return 0; } /* options common to -S -R -U */ @@ -572,15 +587,15 @@ static int parsearg_trans(int opt) check_optarg(); config->print_format = strdup(optarg); break; - default: return(1); + default: return 1; } - return(0); + return 0; } static int parsearg_remove(int opt) { if (parsearg_trans(opt) == 0) - return(0); + return 0; switch(opt) { case 'c': config->flags |= PM_TRANS_FLAG_CASCADE; break; case 'n': config->flags |= PM_TRANS_FLAG_NOSAVE; break; @@ -592,16 +607,16 @@ static int parsearg_remove(int opt) } break; case 'u': config->flags |= PM_TRANS_FLAG_UNNEEDED; break; - default: return(1); + default: return 1; } - return(0); + return 0; } /* options common to -S -U */ static int parsearg_upgrade(int opt) { if (parsearg_trans(opt) == 0) - return(0); + return 0; switch(opt) { case 'f': config->flags |= PM_TRANS_FLAG_FORCE; break; case OP_ASDEPS: config->flags |= PM_TRANS_FLAG_ALLDEPS; break; @@ -612,15 +627,15 @@ static int parsearg_upgrade(int opt) case OP_IGNOREGROUP: parsearg_util_addlist(alpm_option_add_ignoregrp); break; - default: return(1); + default: return 1; } - return(0); + return 0; } static int parsearg_sync(int opt) { if (parsearg_upgrade(opt) == 0) - return(0); + return 0; switch(opt) { case OP_NEEDED: config->flags |= PM_TRANS_FLAG_NEEDED; break; case 'c': (config->op_s_clean)++; break; @@ -636,9 +651,9 @@ static int parsearg_sync(int opt) config->flags |= PM_TRANS_FLAG_NOCONFLICTS; break; case 'y': (config->op_s_sync)++; break; - default: return(1); + default: return 1; } - return(0); + return 0; } /** Parse command-line arguments for each operation. @@ -706,6 +721,7 @@ static int parseargs(int argc, char *argv[]) {"asexplicit", no_argument, 0, OP_ASEXPLICIT}, {"arch", required_argument, 0, OP_ARCH}, {"print-format", required_argument, 0, OP_PRINTFORMAT}, + {"gpgdir", required_argument, 0, OP_GPGDIR}, {0, 0, 0, 0} }; @@ -717,22 +733,22 @@ static int parseargs(int argc, char *argv[]) continue; } else if(opt == '?') { /* unknown option, getopt printed an error */ - return(1); + return 1; } parsearg_op(opt, 0); } if(config->op == 0) { pm_printf(PM_LOG_ERROR, _("only one operation may be used at a time\n")); - return(1); + return 1; } if(config->help) { usage(config->op, mbasename(argv[0])); - return(2); + return 2; } if(config->version) { version(); - return(2); + return 2; } /* parse all other options */ @@ -744,7 +760,7 @@ static int parseargs(int argc, char *argv[]) continue; } else if(opt == '?') { /* this should have failed during first pass already */ - return(1); + return 1; } else if(parsearg_op(opt, 1) == 0) { /* opt is an operation */ continue; @@ -780,7 +796,7 @@ static int parseargs(int argc, char *argv[]) if(result != 0) { /* global option parsing failed, abort */ pm_printf(PM_LOG_ERROR, _("invalid option\n")); - return(result); + return result; } } @@ -790,21 +806,23 @@ static int parseargs(int argc, char *argv[]) optind++; } - return(0); + return 0; } /* helper for being used with setrepeatingoption */ -static void option_add_holdpkg(const char *name) { +static int option_add_holdpkg(const char *name) { config->holdpkg = alpm_list_add(config->holdpkg, strdup(name)); + return 0; } /* helper for being used with setrepeatingoption */ -static void option_add_syncfirst(const char *name) { +static int option_add_syncfirst(const char *name) { config->syncfirst = alpm_list_add(config->syncfirst, strdup(name)); + return 0; } /* helper for being used with setrepeatingoption */ -static void option_add_cleanmethod(const char *value) { +static int option_add_cleanmethod(const char *value) { if (strcmp(value, "KeepInstalled") == 0) { config->cleanmethod |= PM_CLEAN_KEEPINST; } else if (strcmp(value, "KeepCurrent") == 0) { @@ -813,6 +831,7 @@ static void option_add_cleanmethod(const char *value) { pm_printf(PM_LOG_ERROR, _("invalid value for 'CleanMethod' : '%s'\n"), value); } + return 0; } /** Add repeating options such as NoExtract, NoUpgrade, etc to libalpm @@ -823,7 +842,7 @@ static void option_add_cleanmethod(const char *value) { * @param optionfunc a function pointer to an alpm_option_add_* function */ static void setrepeatingoption(char *ptr, const char *option, - void (*optionfunc)(const char*)) + int (*optionfunc)(const char*)) { char *q; @@ -843,7 +862,7 @@ static char *get_filename(const char *url) { if(filename != NULL) { filename++; } - return(filename); + return filename; } static char *get_destfile(const char *path, const char *filename) { @@ -853,7 +872,7 @@ static char *get_destfile(const char *path, const char *filename) { destfile = calloc(len, sizeof(char)); snprintf(destfile, len, "%s%s", path, filename); - return(destfile); + return destfile; } static char *get_tempfile(const char *path, const char *filename) { @@ -863,7 +882,7 @@ static char *get_tempfile(const char *path, const char *filename) { tempfile = calloc(len, sizeof(char)); snprintf(tempfile, len, "%s%s.part", path, filename); - return(tempfile); + return tempfile; } /** External fetch callback */ @@ -955,7 +974,7 @@ cleanup: free(tempfile); free(parsedcmd); - return(ret); + return ret; } static int _parse_options(const char *key, char *value, @@ -969,9 +988,6 @@ static int _parse_options(const char *key, char *value, } else if(strcmp(key, "ILoveCandy") == 0) { config->chomp = 1; pm_printf(PM_LOG_DEBUG, "config: chomp\n"); - } else if(strcmp(key, "ShowSize") == 0) { - config->showsize = 1; - pm_printf(PM_LOG_DEBUG, "config: showsize\n"); } else if(strcmp(key, "UseDelta") == 0) { alpm_option_set_usedelta(1); pm_printf(PM_LOG_DEBUG, "config: usedelta\n"); @@ -1013,7 +1029,7 @@ static int _parse_options(const char *key, char *value, if(alpm_option_add_cachedir(value) != 0) { pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"), value, alpm_strerrorlast()); - return(1); + return 1; } pm_printf(PM_LOG_DEBUG, "config: cachedir: %s\n", value); } else if(strcmp(key, "RootDir") == 0) { @@ -1022,6 +1038,11 @@ static int _parse_options(const char *key, char *value, config->rootdir = strdup(value); pm_printf(PM_LOG_DEBUG, "config: rootdir: %s\n", value); } + } else if (strcmp(key, "GPGDir") == 0) { + if(!config->gpgdir) { + config->gpgdir = strdup(value); + pm_printf(PM_LOG_DEBUG, "config: gpgdir: %s\n", value); + } } else if (strcmp(key, "LogFile") == 0) { if(!config->logfile) { config->logfile = strdup(value); @@ -1041,7 +1062,7 @@ static int _parse_options(const char *key, char *value, } } - return(0); + return 0; } static int _add_mirror(pmdb_t *db, char *value) @@ -1060,7 +1081,7 @@ static int _add_mirror(pmdb_t *db, char *value) free(temp); pm_printf(PM_LOG_ERROR, _("The mirror '%s' contains the $arch" " variable, but no Architecture is defined.\n"), value); - return(1); + return 1; } server = temp; } @@ -1070,11 +1091,11 @@ static int _add_mirror(pmdb_t *db, char *value) pm_printf(PM_LOG_ERROR, _("could not add server URL to database '%s': %s (%s)\n"), dbname, server, alpm_strerrorlast()); free(server); - return(1); + return 1; } free(server); - return(0); + return 0; } /* The real parseconfig. Called with a null section argument by the publicly @@ -1093,7 +1114,7 @@ static int _parseconfig(const char *file, const char *givensection, fp = fopen(file, "r"); if(fp == NULL) { pm_printf(PM_LOG_ERROR, _("config file %s could not be read.\n"), file); - return(1); + return 1; } /* if we are passed a section, use it as our starting point */ @@ -1225,6 +1246,24 @@ static int _parseconfig(const char *file, const char *givensection, ret = 1; goto cleanup; } + } else if(strcmp(key, "VerifySig") == 0) { + if (strcmp(value, "Always") == 0) { + ret = alpm_db_set_pgp_verify(db,PM_PGP_VERIFY_ALWAYS); + } else if (strcmp(value, "Optional") == 0) { + ret = alpm_db_set_pgp_verify(db,PM_PGP_VERIFY_OPTIONAL); + } else if (strcmp(value, "Never") == 0) { + ret = alpm_db_set_pgp_verify(db,PM_PGP_VERIFY_NEVER); + } else { + pm_printf(PM_LOG_ERROR, _("invalid value for 'VerifySig' : '%s'\n"), value); + ret = 1; + goto cleanup; + } + if (ret != 0) { + pm_printf(PM_LOG_ERROR, _("could not add pgp verify option to database '%s': %s (%s)\n"), + alpm_db_get_name(db), value, alpm_strerrorlast()); + goto cleanup; + } + pm_printf(PM_LOG_DEBUG, "config: VerifySig for %s: %s\n",alpm_db_get_name(db), value); } else { pm_printf(PM_LOG_WARNING, _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"), @@ -1242,7 +1281,7 @@ cleanup: /* call setlibpaths here to ensure we have called it at least once */ setlibpaths(); pm_printf(PM_LOG_DEBUG, "config: finished parsing %s\n", file); - return(ret); + return ret; } /** Parse a configuration file. @@ -1252,7 +1291,7 @@ cleanup: static int parseconfig(const char *file) { /* call the real parseconfig function with a null section & db argument */ - return(_parseconfig(file, NULL, NULL)); + return _parseconfig(file, NULL, NULL); } /** print commandline to logfile @@ -1345,6 +1384,7 @@ int main(int argc, char *argv[]) /* 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: @@ -1479,7 +1519,7 @@ int main(int argc, char *argv[]) cleanup(ret); /* not reached */ - return(EXIT_SUCCESS); + return EXIT_SUCCESS; } /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/query.c b/src/pacman/query.c index 5d036881..5f751191 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -43,15 +43,15 @@ static char *resolve_path(const char *file) str = calloc(PATH_MAX + 1, sizeof(char)); if(!str) { - return(NULL); + return NULL; } if(!realpath(file, str)) { free(str); - return(NULL); + return NULL; } - return(str); + return str; } /* check if filename exists in PATH */ @@ -61,10 +61,10 @@ static int search_path(char **filename, struct stat *bufptr) size_t flen; if ((envpath = getenv("PATH")) == NULL) { - return(-1); + return -1; } if ((envpath = envpathsplit = strdup(envpath)) == NULL) { - return(-1); + return -1; } flen = strlen(*filename); @@ -84,12 +84,12 @@ static int search_path(char **filename, struct stat *bufptr) free(*filename); *filename = fullname; free(envpath); - return(0); + return 0; } free(fullname); } free(envpath); - return(-1); + return -1; } static void print_query_fileowner(const char *filename, pmpkg_t *info) @@ -115,7 +115,7 @@ static int query_fileowner(alpm_list_t *targets) /* This code is here for safety only */ if(targets == NULL) { pm_fprintf(stderr, PM_LOG_ERROR, _("no file was specified for --owns\n")); - return(1); + return 1; } /* Set up our root path buffer. We only need to copy the location of root in @@ -248,7 +248,7 @@ static int query_search(alpm_list_t *targets) freelist = 0; } if(searchlist == NULL) { - return(1); + return 1; } for(i = searchlist; i; i = alpm_list_next(i)) { @@ -261,14 +261,6 @@ static int query_search(alpm_list_t *targets) printf("%s", alpm_pkg_get_name(pkg)); } - /* print the package size with the output if ShowSize option set */ - if(!config->quiet && config->showsize) { - /* Convert byte size to MB */ - double mbsize = (double)alpm_pkg_get_size(pkg) / (1024.0 * 1024.0); - - printf(" [%.2f MB]", mbsize); - } - if (!config->quiet) { if((grp = alpm_pkg_get_groups(pkg)) != NULL) { @@ -296,7 +288,7 @@ static int query_search(alpm_list_t *targets) if(freelist) { alpm_list_free(searchlist); } - return(0); + return 0; } static int query_group(alpm_list_t *targets) @@ -359,19 +351,19 @@ static int is_foreign(pmpkg_t *pkg) } } if(match == 0) { - return(1); + return 1; } - return(0); + return 0; } static int is_unrequired(pmpkg_t *pkg) { alpm_list_t *requiredby = alpm_pkg_compute_requiredby(pkg); if(requiredby == NULL) { - return(1); + return 1; } FREELIST(requiredby); - return(0); + return 0; } static int filter(pmpkg_t *pkg) @@ -379,26 +371,26 @@ static int filter(pmpkg_t *pkg) /* check if this package was explicitly installed */ if(config->op_q_explicit && alpm_pkg_get_reason(pkg) != PM_PKG_REASON_EXPLICIT) { - return(0); + return 0; } /* check if this package was installed as a dependency */ if(config->op_q_deps && alpm_pkg_get_reason(pkg) != PM_PKG_REASON_DEPEND) { - return(0); + return 0; } /* check if this pkg isn't in a sync DB */ if(config->op_q_foreign && !is_foreign(pkg)) { - return(0); + return 0; } /* check if this pkg is unrequired */ if(config->op_q_unrequired && !is_unrequired(pkg)) { - return(0); + return 0; } /* check if this pkg is outdated */ if(config->op_q_upgrade && (alpm_sync_newversion(pkg, alpm_option_get_syncdbs()) == NULL)) { - return(0); + return 0; } - return(1); + return 1; } /* Loop through the packages. For each package, @@ -416,7 +408,7 @@ static int check(pmpkg_t *pkg) if(rootlen + 1 > PATH_MAX) { /* we are in trouble here */ pm_fprintf(stderr, PM_LOG_ERROR, _("path too long: %s%s\n"), root, ""); - return(1); + return 1; } strcpy(f, root); @@ -450,7 +442,7 @@ static int check(pmpkg_t *pkg) (unsigned long)errors), errors); } - return(errors != 0 ? 1 : 0); + return (errors != 0 ? 1 : 0); } static int display(pmpkg_t *pkg) @@ -482,7 +474,7 @@ static int display(pmpkg_t *pkg) printf("%s\n", alpm_pkg_get_name(pkg)); } } - return(ret); + return ret; } int pacman_query(alpm_list_t *targets) @@ -498,13 +490,13 @@ int pacman_query(alpm_list_t *targets) /* search for a package */ if(config->op_q_search) { ret = query_search(targets); - return(ret); + return ret; } /* looking for groups */ if(config->group) { ret = query_group(targets); - return(ret); + return ret; } if(config->op_q_foreign) { @@ -512,7 +504,7 @@ int pacman_query(alpm_list_t *targets) alpm_list_t *sync_dbs = alpm_option_get_syncdbs(); if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) { pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n")); - return(1); + return 1; } } @@ -524,7 +516,7 @@ int pacman_query(alpm_list_t *targets) if(targets == NULL) { if(config->op_q_isfile || config->op_q_owns) { pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n")); - return(1); + return 1; } for(i = alpm_db_get_pkgcache(db_local); i; i = alpm_list_next(i)) { @@ -540,7 +532,7 @@ int pacman_query(alpm_list_t *targets) if(!match) { ret = 1; } - return(ret); + return ret; } /* Second: operations that require target(s) */ @@ -548,7 +540,7 @@ int pacman_query(alpm_list_t *targets) /* determine the owner of a file */ if(config->op_q_owns) { ret = query_fileowner(targets); - return(ret); + return ret; } /* operations on named packages in the local DB @@ -586,7 +578,7 @@ int pacman_query(alpm_list_t *targets) ret = 1; } - return(ret); + return ret; } /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/remove.c b/src/pacman/remove.c index fb02e242..58e6edd5 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -40,25 +40,25 @@ static int remove_target(char *target) if((info = alpm_db_get_pkg(db_local, target)) != NULL) { if(alpm_remove_pkg(info) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, alpm_strerrorlast()); - return(-1); + return -1; } - return(0); + return 0; } /* fallback to group */ pmgrp_t *grp = alpm_db_readgrp(db_local, target); if(grp == NULL) { pm_fprintf(stderr, PM_LOG_ERROR, "'%s': target not found\n", target); - return(-1); + return -1; } for(p = alpm_grp_get_pkgs(grp); p; p = alpm_list_next(p)) { pmpkg_t *pkg = alpm_list_getdata(p); if(alpm_remove_pkg(pkg) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, alpm_strerrorlast()); - return(-1); + return -1; } } - return(0); + return 0; } /** @@ -75,12 +75,12 @@ int pacman_remove(alpm_list_t *targets) if(targets == NULL) { pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n")); - return(1); + return 1; } /* Step 0: create a new transaction */ if(trans_init(config->flags) == -1) { - return(1); + return 1; } /* Step 1: add targets to the created transaction */ @@ -173,7 +173,7 @@ cleanup: if(trans_release() == -1) { retval = 1; } - return(retval); + return retval; } /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/sync.c b/src/pacman/sync.c index c56934b6..5e8a8e0f 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -47,7 +47,7 @@ static int sync_cleandb(const char *dbpath, int keep_used) { dir = opendir(dbpath); if(dir == NULL) { pm_fprintf(stderr, PM_LOG_ERROR, _("could not access database directory\n")); - return(1); + return 1; } syncdbs = alpm_option_get_syncdbs(); @@ -84,7 +84,7 @@ static int sync_cleandb(const char *dbpath, int keep_used) { pm_fprintf(stderr, PM_LOG_ERROR, _("could not remove %s\n"), path); closedir(dir); - return(1); + return 1; } continue; } @@ -110,12 +110,12 @@ static int sync_cleandb(const char *dbpath, int keep_used) { pm_fprintf(stderr, PM_LOG_ERROR, _("could not remove %s\n"), path); closedir(dir); - return(1); + return 1; } } } closedir(dir); - return(0); + return 0; } static int sync_cleandb_all(void) { @@ -126,7 +126,7 @@ static int sync_cleandb_all(void) { dbpath = alpm_option_get_dbpath(); printf(_("Database directory: %s\n"), dbpath); if(!yesno(_("Do you want to remove unused repositories?"))) { - return(0); + return 0; } /* The sync dbs were previously put in dbpath/ but are now in dbpath/sync/. * We will clean everything in dbpath/ except local/, sync/ and db.lck, and @@ -137,7 +137,7 @@ static int sync_cleandb_all(void) { ret += sync_cleandb(newdbpath, 1); printf(_("Database directory cleaned up\n")); - return(ret); + return ret; } static int sync_cleancache(int level) @@ -165,12 +165,12 @@ static int sync_cleancache(int level) printf(_(" All current sync database packages\n")); } if(!yesno(_("Do you want to remove all other packages from cache?"))) { - return(0); + return 0; } printf(_("removing old packages from cache...\n")); } else { if(!noyes(_("Do you want to remove ALL files from cache?"))) { - return(0); + return 0; } printf(_("removing all files from cache...\n")); } @@ -258,7 +258,7 @@ static int sync_cleancache(int level) closedir(dir); } - return(ret); + return ret; } static int sync_synctree(int level, alpm_list_t *syncs) @@ -267,7 +267,7 @@ static int sync_synctree(int level, alpm_list_t *syncs) int success = 0, ret; if(trans_init(0) == -1) { - return(0); + return 0; } for(i = syncs; i; i = alpm_list_next(i)) { @@ -286,7 +286,7 @@ static int sync_synctree(int level, alpm_list_t *syncs) } if(trans_release() == -1) { - return(0); + return 0; } /* We should always succeed if at least one DB was upgraded - we may possibly * fail later with unresolved deps, but that should be rare, and would be @@ -295,7 +295,7 @@ static int sync_synctree(int level, alpm_list_t *syncs) if(!success) { pm_fprintf(stderr, PM_LOG_ERROR, _("failed to synchronize any databases\n")); } - return(success > 0); + return (success > 0); } static void print_installed(pmdb_t *db_local, pmpkg_t *pkg) @@ -347,14 +347,6 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets) printf("%s", alpm_pkg_get_name(pkg)); } - /* print the package size with the output if ShowSize option set */ - if(!config->quiet && config->showsize) { - /* Convert byte size to MB */ - double mbsize = (double)alpm_pkg_get_size(pkg) / (1024.0 * 1024.0); - - printf(" [%.2f MB]", mbsize); - } - if (!config->quiet) { if((grp = alpm_pkg_get_groups(pkg)) != NULL) { alpm_list_t *k; @@ -384,7 +376,7 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets) } } - return(!found); + return !found; } static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets) @@ -432,7 +424,7 @@ static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets) } } - return(0); + return 0; } static int sync_info(alpm_list_t *syncs, alpm_list_t *targets) @@ -466,7 +458,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets) if(!db) { pm_fprintf(stderr, PM_LOG_ERROR, _("repository '%s' does not exist\n"), repo); - return(1); + return 1; } for(k = alpm_db_get_pkgcache(db); k; k = alpm_list_next(k)) { @@ -517,7 +509,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets) } } - return(ret); + return ret; } static int sync_list(alpm_list_t *syncs, alpm_list_t *targets) @@ -543,7 +535,7 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets) pm_fprintf(stderr, PM_LOG_ERROR, _("repository \"%s\" was not found.\n"),repo); alpm_list_free(ls); - return(1); + return 1; } ls = alpm_list_add(ls, db); @@ -573,7 +565,7 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets) alpm_list_free(ls); } - return(0); + return 0; } static alpm_list_t *syncfirst(void) { @@ -592,7 +584,7 @@ static alpm_list_t *syncfirst(void) { } } - return(res); + return res; } static pmdb_t *get_db(const char *dbname) @@ -601,10 +593,10 @@ static pmdb_t *get_db(const char *dbname) for(i = alpm_option_get_syncdbs(); i; i = i->next) { pmdb_t *db = i->data; if(strcmp(alpm_db_get_name(db), dbname) == 0) { - return(db); + return db; } } - return(NULL); + return NULL; } static int process_pkg(pmpkg_t *pkg) @@ -616,14 +608,14 @@ static int process_pkg(pmpkg_t *pkg) || pm_errno == PM_ERR_PKG_IGNORED) { /* just skip duplicate or ignored targets */ pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), alpm_pkg_get_name(pkg)); - return(0); + return 0; } else { pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", alpm_pkg_get_name(pkg), alpm_strerrorlast()); - return(1); + return 1; } } - return(0); + return 0; } static int process_group(alpm_list_t *dbs, char *group) @@ -635,7 +627,7 @@ static int process_group(alpm_list_t *dbs, char *group) if(!count) { pm_fprintf(stderr, PM_LOG_ERROR, _("target not found: %s\n"), group); - return(1); + return 1; } @@ -669,7 +661,7 @@ static int process_group(alpm_list_t *dbs, char *group) } cleanup: alpm_list_free(pkgs); - return(ret); + return ret; } static int process_targname(alpm_list_t *dblist, char *targname) @@ -680,14 +672,14 @@ static int process_targname(alpm_list_t *dblist, char *targname) if(pm_errno == PM_ERR_PKG_IGNORED) { pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), targname); pm_errno = 0; - return(0); + return 0; } if(pkg) { - return(process_pkg(pkg)); + return process_pkg(pkg); } /* fallback on group */ - return(process_group(dblist, targname)); + return process_group(dblist, targname); } static int process_target(char *target) @@ -722,7 +714,7 @@ static int process_target(char *target) } cleanup: free(targstring); - return(ret); + return ret; } static int sync_trans(alpm_list_t *targets) @@ -734,7 +726,7 @@ static int sync_trans(alpm_list_t *targets) /* Step 1: create a new transaction... */ if(trans_init(config->flags) == -1) { - return(1); + return 1; } /* process targets */ @@ -874,7 +866,7 @@ cleanup: retval = 1; } - return(retval); + return retval; } int pacman_sync(alpm_list_t *targets) @@ -886,7 +878,7 @@ int pacman_sync(alpm_list_t *targets) int ret = 0; if(trans_init(0) == -1) { - return(1); + return 1; } ret += sync_cleancache(config->op_s_clean); @@ -897,14 +889,14 @@ int pacman_sync(alpm_list_t *targets) ret++; } - return(ret); + return ret; } /* ensure we have at least one valid sync db set up */ sync_dbs = alpm_option_get_syncdbs(); if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) { pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n")); - return(1); + return 1; } if(config->op_s_sync) { @@ -912,40 +904,40 @@ int pacman_sync(alpm_list_t *targets) printf(_(":: Synchronizing package databases...\n")); alpm_logaction("synchronizing package lists\n"); if(!sync_synctree(config->op_s_sync, sync_dbs)) { - return(1); + return 1; } } /* search for a package */ if(config->op_s_search) { - return(sync_search(sync_dbs, targets)); + return sync_search(sync_dbs, targets); } /* look for groups */ if(config->group) { - return(sync_group(config->group, sync_dbs, targets)); + return sync_group(config->group, sync_dbs, targets); } /* get package info */ if(config->op_s_info) { - return(sync_info(sync_dbs, targets)); + return sync_info(sync_dbs, targets); } /* get a listing of files in sync DBs */ if(config->op_q_list) { - return(sync_list(sync_dbs, targets)); + return sync_list(sync_dbs, targets); } if(targets == NULL) { if(config->op_s_upgrade) { /* proceed */ } else if(config->op_s_sync) { - return(0); + return 0; } else { /* don't proceed here unless we have an operation that doesn't require a * target list */ pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n")); - return(1); + return 1; } } @@ -980,7 +972,7 @@ int pacman_sync(alpm_list_t *targets) int ret = sync_trans(targs); FREELIST(targs); - return(ret); + return ret; } /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c index 8cd29da0..5b894001 100644 --- a/src/pacman/upgrade.c +++ b/src/pacman/upgrade.c @@ -46,7 +46,7 @@ int pacman_upgrade(alpm_list_t *targets) if(targets == NULL) { pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n")); - return(1); + return 1; } /* Check for URL targets and process them @@ -57,7 +57,7 @@ int pacman_upgrade(alpm_list_t *targets) if(str == NULL) { pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", (char *)i->data, alpm_strerrorlast()); - return(1); + return 1; } else { free(i->data); i->data = str; @@ -67,7 +67,7 @@ int pacman_upgrade(alpm_list_t *targets) /* Step 1: create a new transaction */ if(trans_init(config->flags) == -1) { - return(1); + return 1; } /* add targets to the created transaction */ @@ -79,14 +79,14 @@ int pacman_upgrade(alpm_list_t *targets) pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ, alpm_strerrorlast()); trans_release(); - return(1); + return 1; } if(alpm_add_pkg(pkg) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ, alpm_strerrorlast()); alpm_pkg_free(pkg); trans_release(); - return(1); + return 1; } } @@ -135,7 +135,7 @@ int pacman_upgrade(alpm_list_t *targets) } trans_release(); FREELIST(data); - return(1); + return 1; } /* Step 3: perform the installation */ @@ -143,7 +143,7 @@ int pacman_upgrade(alpm_list_t *targets) if(config->print) { print_packages(alpm_trans_get_add()); trans_release(); - return(0); + return 0; } /* print targets and ask user confirmation */ @@ -151,7 +151,7 @@ int pacman_upgrade(alpm_list_t *targets) if(packages == NULL) { /* we are done */ printf(_(" there is nothing to do\n")); trans_release(); - return(retval); + return retval; } display_targets(alpm_trans_get_remove(), 0); display_targets(alpm_trans_get_add(), 1); @@ -159,7 +159,7 @@ int pacman_upgrade(alpm_list_t *targets) int confirm = yesno(_("Proceed with installation?")); if(!confirm) { trans_release(); - return(retval); + return retval; } if(alpm_trans_commit(&data) == -1) { @@ -197,13 +197,13 @@ int pacman_upgrade(alpm_list_t *targets) } FREELIST(data); trans_release(); - return(1); + return 1; } if(trans_release() == -1) { retval = 1; } - return(retval); + return retval; } /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/util.c b/src/pacman/util.c index 3d268031..8d5ada61 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -37,6 +37,9 @@ #include <unistd.h> #include <limits.h> #include <wchar.h> +#ifdef HAVE_TERMIOS_H +#include <termios.h> /* tcflush */ +#endif #include <alpm.h> #include <alpm_list.h> @@ -68,9 +71,9 @@ int trans_init(pmtransflag_t flags) fprintf(stderr, _(" try running pacman-db-upgrade\n")); } - return(-1); + return -1; } - return(0); + return 0; } int trans_release(void) @@ -78,28 +81,40 @@ int trans_release(void) if(alpm_trans_release() == -1) { pm_fprintf(stderr, PM_LOG_ERROR, _("failed to release transaction (%s)\n"), alpm_strerrorlast()); - return(-1); + return -1; } - return(0); + return 0; } int needs_root(void) { switch(config->op) { case PM_OP_DATABASE: - return(1); + return 1; case PM_OP_UPGRADE: case PM_OP_REMOVE: - return(!config->print); + return !config->print; case PM_OP_SYNC: - return(config->op_s_clean || config->op_s_sync || + return (config->op_s_clean || config->op_s_sync || (!config->group && !config->op_s_info && !config->op_q_list && !config->op_s_search && !config->print)); default: - return(0); + return 0; } } +/* discard unhandled input on the terminal's input buffer */ +static int flush_term_input(void) { +#ifdef HAVE_TCFLUSH + if(isatty(fileno(stdin))) { + return(tcflush(fileno(stdin), TCIFLUSH)); + } +#endif + + /* fail silently */ + return 0; +} + /* gets the current screen column width */ int getcols(void) { @@ -125,24 +140,24 @@ int rmrf(const char *path) DIR *dirp; if(!unlink(path)) { - return(0); + return 0; } else { if(errno == ENOENT) { - return(0); + return 0; } else if(errno == EPERM) { /* fallthrough */ } else if(errno == EISDIR) { /* fallthrough */ } else if(errno == ENOTDIR) { - return(1); + return 1; } else { /* not a directory */ - return(1); + return 1; } dirp = opendir(path); if(!dirp) { - return(1); + return 1; } for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { if(dp->d_ino) { @@ -157,7 +172,7 @@ int rmrf(const char *path) if(rmdir(path)) { errflag++; } - return(errflag); + return errflag; } } @@ -170,9 +185,9 @@ const char *mbasename(const char *path) { const char *last = strrchr(path, '/'); if(last) { - return(last + 1); + return last + 1; } - return(path); + return path; } /** Parse the dirname of a program from a path. @@ -187,7 +202,7 @@ char *mdirname(const char *path) /* null or empty path */ if(path == NULL || path == '\0') { - return(strdup(".")); + return strdup("."); } ret = strdup(path); @@ -196,11 +211,11 @@ char *mdirname(const char *path) if(last != NULL) { /* we found a '/', so terminate our string */ *last = '\0'; - return(ret); + return ret; } /* no slash found */ free(ret); - return(strdup(".")); + return strdup("."); } /* output a string, but wrap words properly with a specified indentation @@ -286,7 +301,7 @@ char *strtrim(char *str) if(str == NULL || *str == '\0') { /* string is empty, so we're done. */ - return(str); + return str; } while(isspace((unsigned char)*pch)) { @@ -298,7 +313,7 @@ char *strtrim(char *str) /* check if there wasn't anything but whitespace in the string. */ if(*str == '\0') { - return(str); + return str; } pch = (str + (strlen(str) - 1)); @@ -307,7 +322,7 @@ char *strtrim(char *str) } *++pch = '\0'; - return(str); + return str; } /* Replace all occurances of 'needle' with 'replace' in 'str', returning @@ -321,7 +336,7 @@ char *strreplace(const char *str, const char *needle, const char *replace) size_t newsz; if(!str) { - return(NULL); + return NULL; } p = str; @@ -334,7 +349,7 @@ char *strreplace(const char *str, const char *needle, const char *replace) /* no occurences of needle found */ if(!list) { - return(strdup(str)); + return strdup(str); } /* size of new string = size of old string + "number of occurences of needle" * x "size difference between replace and needle" */ @@ -342,7 +357,7 @@ char *strreplace(const char *str, const char *needle, const char *replace) alpm_list_count(list) * (replacesz - needlesz); newstr = malloc(newsz); if(!newstr) { - return(NULL); + return NULL; } *newstr = '\0'; @@ -368,7 +383,7 @@ char *strreplace(const char *str, const char *needle, const char *replace) } *newp = '\0'; - return(newstr); + return newstr; } /** Splits a string into a list of strings using the chosen character as @@ -388,7 +403,7 @@ alpm_list_t *strsplit(const char *str, const char splitchar) while((str = strchr(str, splitchar))) { dup = strndup(prev, (size_t)(str - prev)); if(dup == NULL) { - return(NULL); + return NULL; } list = alpm_list_add(list, dup); @@ -398,11 +413,11 @@ alpm_list_t *strsplit(const char *str, const char splitchar) dup = strdup(prev); if(dup == NULL) { - return(NULL); + return NULL; } list = alpm_list_add(list, dup); - return(list); + return list; } static int string_length(const char *s) @@ -411,7 +426,7 @@ static int string_length(const char *s) wchar_t *wcstr; if(!s) { - return(0); + return 0; } /* len goes from # bytes -> # chars -> # cols */ len = strlen(s) + 1; @@ -420,7 +435,7 @@ static int string_length(const char *s) len = wcswidth(wcstr, len); free(wcstr); - return(len); + return len; } void string_display(const char *title, const char *string) @@ -503,20 +518,21 @@ void list_display_linebreak(const char *title, const alpm_list_t *list) } } } + /* prepare a list of pkgs to display */ void display_targets(const alpm_list_t *pkgs, int install) { char *str; + const char *title, *label; + double size; const alpm_list_t *i; off_t isize = 0, dlsize = 0; - double mbisize = 0.0, mbdlsize = 0.0; alpm_list_t *targets = NULL; if(!pkgs) { return; } - printf("\n"); for(i = pkgs; i; i = alpm_list_next(i)) { pmpkg_t *pkg = alpm_list_getdata(i); @@ -525,42 +541,31 @@ void display_targets(const alpm_list_t *pkgs, int install) } isize += alpm_pkg_get_isize(pkg); - /* print the package size with the output if ShowSize option set */ - if(config->showsize) { - double mbsize = (double)alpm_pkg_get_size(pkg) / (1024.0 * 1024.0); - - pm_asprintf(&str, "%s-%s [%.2f MB]", alpm_pkg_get_name(pkg), - alpm_pkg_get_version(pkg), mbsize); - } else { - pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(pkg), - alpm_pkg_get_version(pkg)); - } + pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(pkg), + alpm_pkg_get_version(pkg)); targets = alpm_list_add(targets, str); } - /* Convert byte sizes to MB */ - mbdlsize = (double)dlsize / (1024.0 * 1024.0); - mbisize = (double)isize / (1024.0 * 1024.0); + title = install ? _("Targets (%d):") : _("Remove (%d):"); + pm_asprintf(&str, title, alpm_list_count(pkgs)); - if(install) { - pm_asprintf(&str, _("Targets (%d):"), alpm_list_count(targets)); - list_display(str, targets); - free(str); - printf("\n"); + printf("\n"); + list_display(str, targets); + printf("\n"); - printf(_("Total Download Size: %.2f MB\n"), mbdlsize); + if(install) { + size = humanize_size(dlsize, 'M', 1, &label); + printf(_("Total Download Size: %.2f %s\n"), size, label); if(!(config->flags & PM_TRANS_FLAG_DOWNLOADONLY)) { - printf(_("Total Installed Size: %.2f MB\n"), mbisize); + size = humanize_size(isize, 'M', 1, &label); + printf(_("Total Installed Size: %.2f %s\n"), size, label); } } else { - pm_asprintf(&str, _("Remove (%d):"), alpm_list_count(targets)); - list_display(str, targets); - free(str); - printf("\n"); - - printf(_("Total Removed Size: %.2f MB\n"), mbisize); + size = humanize_size(isize, 'M', 1, &label); + printf(_("Total Removed Size: %.2f %s\n"), size, label); } + free(str); FREELIST(targets); } @@ -568,11 +573,11 @@ static off_t pkg_get_size(pmpkg_t *pkg) { switch(config->op) { case PM_OP_SYNC: - return(alpm_pkg_download_size(pkg)); + return alpm_pkg_download_size(pkg); case PM_OP_UPGRADE: - return(alpm_pkg_get_size(pkg)); + return alpm_pkg_get_size(pkg); default: - return(alpm_pkg_get_isize(pkg)); + return alpm_pkg_get_isize(pkg); } } @@ -588,15 +593,53 @@ static char *pkg_get_location(pmpkg_t *pkg) if(dburl) { char *pkgurl = NULL; pm_asprintf(&pkgurl, "%s/%s", dburl, alpm_pkg_get_filename(pkg)); - return(pkgurl); + return pkgurl; } case PM_OP_UPGRADE: - return(strdup(alpm_pkg_get_filename(pkg))); + return strdup(alpm_pkg_get_filename(pkg)); default: string = NULL; pm_asprintf(&string, "%s-%s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg)); - return(string); + return string; + } +} + +/** Converts sizes in bytes into human readable units. + * + * @param bytes the size in bytes + * @param target_unit '\0' or a short label. If equal to one of the short unit + * labels ('B', 'K', ...) bytes is converted to target_unit; if '\0', the first + * unit which will bring the value to below a threshold of 2048 will be chosen. + * @param long_labels whether to use short ("K") or long ("KiB") unit labels + * @param label will be set to the appropriate unit label + * + * @return the size in the appropriate unit + */ +double humanize_size(off_t bytes, const char target_unit, int long_labels, + const char **label) +{ + static const char *shortlabels[] = {"B", "K", "M", "G", "T", "P"}; + static const char *longlabels[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB"}; + static const int unitcount = sizeof(shortlabels) / sizeof(shortlabels[0]); + + const char **labels = long_labels ? longlabels : shortlabels; + double val = (double)bytes; + int index; + + for(index = 0; index < unitcount - 1; index++) { + if(target_unit != '\0' && shortlabels[index][0] == target_unit) { + break; + } else if(target_unit == '\0' && val <= 2048.0) { + break; + } + val /= 1024.0; + } + + if(label) { + *label = labels[index]; } + + return(val); } void print_packages(const alpm_list_t *packages) @@ -657,7 +700,7 @@ void print_packages(const alpm_list_t *packages) * alpm "compare func" signature */ int str_cmp(const void *s1, const void *s2) { - return(strcmp(s1, s2)); + return strcmp(s1, s2); } void display_new_optdepends(pmpkg_t *oldpkg, pmpkg_t *newpkg) @@ -726,13 +769,13 @@ static int parseindex(char *s, int *val, int min, int max) if(n < min || n > max) { fprintf(stderr, _("Invalid value: %d is not between %d and %d\n"), n, min, max); - return(-1); + return -1; } *val = n; - return(0); + return 0; } else { fprintf(stderr, _("Invalid number: %s\n"), s); - return(-1); + return -1; } } @@ -773,14 +816,14 @@ static int multiselect_parse(char *array, int count, char *response) } if(parseindex(starts, &start, 1, count) != 0) - return(-1); + return -1; if(!ends) { array[start-1] = include; } else { int d; if(parseindex(ends, &end, start, count) != 0) { - return(-1); + return -1; } for(d = start; d <= end; d++) { array[d-1] = include; @@ -788,7 +831,7 @@ static int multiselect_parse(char *array, int count, char *response) } } - return(0); + return 0; } int multiselect_question(char *array, int count) @@ -815,6 +858,8 @@ int multiselect_question(char *array, int count) break; } + flush_term_input(); + if(fgets(response, sizeof(response), stdin)) { strtrim(response); if(strlen(response) > 0) { @@ -826,7 +871,7 @@ int multiselect_question(char *array, int count) } break; } - return(0); + return 0; } int select_question(int count) @@ -852,19 +897,21 @@ int select_question(int count) break; } + flush_term_input(); + if(fgets(response, sizeof(response), stdin)) { strtrim(response); if(strlen(response) > 0) { int n; if(parseindex(response, &n, 1, count) != 0) continue; - return(n-1); + return (n - 1); } } break; } - return(preset-1); + return (preset - 1); } @@ -895,23 +942,25 @@ static int question(short preset, char *fmt, va_list args) if(config->noconfirm) { fprintf(stream, "\n"); - return(preset); + return preset; } fflush(stream); + flush_term_input(); + if(fgets(response, sizeof(response), stdin)) { strtrim(response); if(strlen(response) == 0) { - return(preset); + return preset; } if(strcasecmp(response, _("Y")) == 0 || strcasecmp(response, _("YES")) == 0) { - return(1); + return 1; } else if (strcasecmp(response, _("N")) == 0 || strcasecmp(response, _("NO")) == 0) { - return(0); + return 0; } } - return(0); + return 0; } int yesno(char *fmt, ...) @@ -923,7 +972,7 @@ int yesno(char *fmt, ...) ret = question(1, fmt, args); va_end(args); - return(ret); + return ret; } int noyes(char *fmt, ...) @@ -935,7 +984,7 @@ int noyes(char *fmt, ...) ret = question(0, fmt, args); va_end(args); - return(ret); + return ret; } int pm_printf(pmloglevel_t level, const char *format, ...) @@ -948,7 +997,7 @@ int pm_printf(pmloglevel_t level, const char *format, ...) ret = pm_vfprintf(stdout, level, format, args); va_end(args); - return(ret); + return ret; } int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...) @@ -961,7 +1010,7 @@ int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...) ret = pm_vfprintf(stream, level, format, args); va_end(args); - return(ret); + return ret; } int pm_asprintf(char **string, const char *format, ...) @@ -977,7 +1026,7 @@ int pm_asprintf(char **string, const char *format, ...) } va_end(args); - return(ret); + return ret; } int pm_vasprintf(char **string, pmloglevel_t level, const char *format, va_list args) @@ -1013,7 +1062,7 @@ int pm_vasprintf(char **string, pmloglevel_t level, const char *format, va_list } free(msg); - return(ret); + return ret; } int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list args) @@ -1061,7 +1110,7 @@ int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list ar /* print the message using va_arg list */ ret = vfprintf(stream, format, args); - return(ret); + return ret; } #ifndef HAVE_STRNDUP @@ -1070,7 +1119,7 @@ static size_t strnlen(const char *s, size_t max) { register const char *p; for(p = s; *p && max--; ++p); - return(p - s); + return (p - s); } char *strndup(const char *s, size_t n) @@ -1082,7 +1131,7 @@ char *strndup(const char *s, size_t n) return NULL; new[len] = '\0'; - return (char *) memcpy(new, s, len); + return (char *)memcpy(new, s, len); } #endif diff --git a/src/pacman/util.h b/src/pacman/util.h index 234a631d..6a20ba4f 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -52,6 +52,7 @@ char *strtrim(char *str); char *strreplace(const char *str, const char *needle, const char *replace); alpm_list_t *strsplit(const char *str, const char splitchar); void string_display(const char *title, const char *string); +double humanize_size(off_t bytes, const char target_unit, int long_labels, const char **label); void list_display(const char *title, const alpm_list_t *list); void list_display_linebreak(const char *title, const alpm_list_t *list); void display_targets(const alpm_list_t *pkgs, int install); diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c index 71ba3a47..6388e840 100644 --- a/src/util/cleanupdelta.c +++ b/src/util/cleanupdelta.c @@ -119,7 +119,7 @@ int main(int argc, char *argv[]) if(alpm_initialize() == -1) { fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast()); - return(1); + return 1; } /* let us get log messages from libalpm */ diff --git a/src/util/pactree.c b/src/util/pactree.c index 6a10006f..94e628b6 100644 --- a/src/util/pactree.c +++ b/src/util/pactree.c @@ -60,12 +60,12 @@ static int alpm_local_init(void) ret = alpm_initialize(); if(ret != 0) { - return(ret); + return ret; } ret = alpm_option_set_root(ROOTDIR); if(ret != 0) { - return(ret); + return ret; } if(dbpath) { @@ -74,15 +74,15 @@ static int alpm_local_init(void) ret = alpm_option_set_dbpath(DBPATH); } if(ret != 0) { - return(ret); + return ret; } db_local = alpm_option_get_localdb(); if(!db_local) { - return(1); + return 1; } - return(0); + return 0; } static int parse_options(int argc, char *argv[]) @@ -137,12 +137,12 @@ static int parse_options(int argc, char *argv[]) case 'h': case '?': default: - return(1); + return 1; } } if(!argv[optind]) { - return(1); + return 1; } if(!color) { @@ -159,7 +159,7 @@ static int parse_options(int argc, char *argv[]) indent_size = 0; } - return(0); + return 0; } static void usage(void) @@ -366,7 +366,7 @@ int main(int argc, char *argv[]) finish: cleanup(); - return(ret); + return ret; } /* vim: set ts=2 sw=2 noet: */ diff --git a/src/util/testdb.c b/src/util/testdb.c index 0436a23f..3d4fa6ae 100644 --- a/src/util/testdb.c +++ b/src/util/testdb.c @@ -63,7 +63,7 @@ static int check_localdb_files(void) snprintf(path, sizeof(path), "%slocal", dbpath); if(!(dir = opendir(path))) { fprintf(stderr, "error : %s : %s\n", path, strerror(errno)); - return(1); + return 1; } while ((ent = readdir(dir)) != NULL) { @@ -85,10 +85,10 @@ static int check_localdb_files(void) } if(closedir(dir)) { fprintf(stderr, "error closing dbpath : %s\n", strerror(errno)); - return(1); + return 1; } - return(ret); + return ret; } static int checkdeps(alpm_list_t *pkglist) @@ -107,7 +107,7 @@ static int checkdeps(alpm_list_t *pkglist) ret++; } FREELIST(data); - return(ret); + return ret; } static int checkconflicts(alpm_list_t *pkglist) @@ -123,7 +123,7 @@ static int checkconflicts(alpm_list_t *pkglist) ret++; } FREELIST(data); - return(ret); + return ret; } static int check_localdb(void) { @@ -133,7 +133,7 @@ static int check_localdb(void) { ret = check_localdb_files(); if(ret) { - return(ret); + return ret; } db = alpm_option_get_localdb(); @@ -145,7 +145,7 @@ static int check_localdb(void) { pkglist = alpm_db_get_pkgcache(db); ret += checkdeps(pkglist); ret += checkconflicts(pkglist); - return(ret); + return ret; } static int check_syncdbs(alpm_list_t *dbnames) { @@ -169,7 +169,7 @@ static int check_syncdbs(alpm_list_t *dbnames) { cleanup: alpm_list_free(syncpkglist); - return(ret); + return ret; } static void usage(void) { @@ -206,7 +206,7 @@ int main(int argc, char *argv[]) if(alpm_initialize() == -1) { fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast()); - return(EXIT_FAILURE); + return EXIT_FAILURE; } /* let us get log messages from libalpm */ @@ -214,7 +214,7 @@ int main(int argc, char *argv[]) if(alpm_option_set_dbpath(dbpath) != 0) { fprintf(stderr, "cannot set dbpath: %s\n", alpm_strerrorlast()); - return(EXIT_FAILURE); + return EXIT_FAILURE; } if(!dbnames) { diff --git a/src/util/testpkg.c b/src/util/testpkg.c index d0d9cac1..e562dde2 100644 --- a/src/util/testpkg.c +++ b/src/util/testpkg.c @@ -44,12 +44,12 @@ int main(int argc, char *argv[]) if(argc != 2) { fprintf(stderr, "usage: %s <package file>\n", BASENAME); - return(1); + return 1; } if(alpm_initialize() == -1) { fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast()); - return(1); + return 1; } /* let us get log messages from libalpm */ @@ -79,5 +79,5 @@ int main(int argc, char *argv[]) fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast()); } - return(retval); + return retval; } diff --git a/src/util/vercmp.c b/src/util/vercmp.c index adb5a42a..88cf49a6 100644 --- a/src/util/vercmp.c +++ b/src/util/vercmp.c @@ -45,13 +45,13 @@ int main(int argc, char *argv[]) if(argc == 1) { usage(); - return(2); + return 2; } if(argc > 1 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "--usage") == 0)) { usage(); - return(0); + return 0; } if(argc > 2) { s2 = argv[2]; @@ -62,5 +62,5 @@ int main(int argc, char *argv[]) ret = alpm_pkg_vercmp(s1, s2); printf("%d\n", ret); - return(EXIT_SUCCESS); + return EXIT_SUCCESS; } |