diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/pacman/callback.c | 17 | ||||
-rw-r--r-- | src/pacman/conf.h | 1 | ||||
-rw-r--r-- | src/pacman/pacman.c | 3 | ||||
-rw-r--r-- | src/pacman/remove.c | 6 | ||||
-rw-r--r-- | src/pacman/sync.c | 57 | ||||
-rw-r--r-- | src/pacman/util.c | 29 | ||||
-rw-r--r-- | src/pacman/util.h | 3 |
7 files changed, 73 insertions, 43 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c index a6349874..3c98d398 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -226,9 +226,6 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) case PM_TRANS_EVT_SCRIPTLET_INFO: printf("%s", (char*)data1); break; - case PM_TRANS_EVT_PRINTURI: - printf("%s/%s\n", (char*)data1, (char*)data2); - break; case PM_TRANS_EVT_RETRIEVE_START: printf(_(":: Retrieving packages from %s...\n"), (char*)data1); break; @@ -255,33 +252,33 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2, case PM_TRANS_CONV_INSTALL_IGNOREPKG: if(data2) { /* TODO we take this route based on data2 being not null? WTF */ - *response = yesno(1, _(":: %s requires installing %s from IgnorePkg/IgnoreGroup. Install anyway?"), + *response = yesno(_(":: %s requires installing %s from IgnorePkg/IgnoreGroup. Install anyway?"), alpm_pkg_get_name(data2), alpm_pkg_get_name(data1)); } else { - *response = yesno(1, _(":: %s is in IgnorePkg/IgnoreGroup. Install anyway?"), + *response = yesno(_(":: %s is in IgnorePkg/IgnoreGroup. Install anyway?"), alpm_pkg_get_name(data1)); } break; case PM_TRANS_CONV_REMOVE_HOLDPKG: - *response = yesno(1, _(":: %s is designated as a HoldPkg. Remove anyway?"), + *response = yesno(_(":: %s is designated as a HoldPkg. Remove anyway?"), alpm_pkg_get_name(data1)); break; case PM_TRANS_CONV_REPLACE_PKG: - *response = yesno(1, _(":: Replace %s with %s/%s?"), + *response = yesno(_(":: Replace %s with %s/%s?"), alpm_pkg_get_name(data1), (char *)data3, alpm_pkg_get_name(data2)); break; case PM_TRANS_CONV_CONFLICT_PKG: - *response = yesno(1, _(":: %s conflicts with %s. Remove %s?"), + *response = yesno(_(":: %s conflicts with %s. Remove %s?"), (char *)data1, (char *)data2, (char *)data2); break; case PM_TRANS_CONV_LOCAL_NEWER: if(!config->op_s_downloadonly) { - *response = yesno(1, _(":: %s-%s: local version is newer. Upgrade anyway?"), + *response = yesno(_(":: %s-%s: local version is newer. Upgrade anyway?"), alpm_pkg_get_name(data1), alpm_pkg_get_version(data1)); } else { @@ -289,7 +286,7 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2, } break; case PM_TRANS_CONV_CORRUPTED_PKG: - *response = yesno(1, _(":: File %s is corrupted. Do you want to delete it?"), + *response = yesno(_(":: File %s is corrupted. Do you want to delete it?"), (char *)data1); break; } diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 9d2318df..8ea66629 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -57,6 +57,7 @@ typedef struct __config_t { unsigned short op_s_sync; unsigned short op_s_search; unsigned short op_s_upgrade; + unsigned short op_s_printuris; unsigned short group; pmtransflag_t flags; diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 04b5e491..83e713a8 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -462,7 +462,8 @@ static int parseargs(int argc, char *argv[]) case 'o': config->op_q_owns = 1; break; case 'p': config->op_q_isfile = 1; - config->flags |= PM_TRANS_FLAG_PRINTURIS; + config->op_s_printuris = 1; + config->flags |= PM_TRANS_FLAG_NOCONFLICTS; break; case 'q': config->quiet = 1; diff --git a/src/pacman/remove.c b/src/pacman/remove.c index f091fa4d..b70f7035 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -75,10 +75,10 @@ int pacman_remove(alpm_list_t *targets) } printf(_(":: group %s:\n"), targ); list_display(" ", pkgnames); - int all = yesno(1, _(" Remove whole content?")); + int all = yesno(_(" Remove whole content?")); for(p = pkgnames; p; p = alpm_list_next(p)) { char *pkgn = alpm_list_getdata(p); - if(all || yesno(1, _(":: Remove %s from group %s?"), pkgn, targ)) { + if(all || yesno(_(":: Remove %s from group %s?"), pkgn, targ)) { if(alpm_trans_addtarget(pkgn) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ, alpm_strerrorlast()); @@ -131,7 +131,7 @@ int pacman_remove(alpm_list_t *targets) printf("\n"); /* get confirmation */ - if(yesno(1, _("Do you want to remove these packages?")) == 0) { + if(yesno(_("Do you want to remove these packages?")) == 0) { retval = 1; goto cleanup; } diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 8d0c529a..e8507143 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -85,7 +85,7 @@ static int sync_cleandb(const char *dbpath, int keep_used) { /* We have a directory that doesn't match any syncdb. * Ask the user if he wants to remove it. */ if(!found) { - if(!yesno(1, _("Do you want to remove %s?"), path)) { + if(!yesno(_("Do you want to remove %s?"), path)) { continue; } @@ -105,7 +105,7 @@ static int sync_cleandb_all(void) { char newdbpath[PATH_MAX]; printf(_("Database directory: %s\n"), dbpath); - if(!yesno(1, _("Do you want to remove unused repositories?"))) { + if(!yesno(_("Do you want to remove unused repositories?"))) { return(0); } /* The sync dbs were previously put in dbpath/, but are now in dbpath/sync/, @@ -135,12 +135,12 @@ static int sync_cleancache(int level) printf(_("Cache directory: %s\n"), cachedir); switch(config->cleanmethod) { case PM_CLEAN_KEEPINST: - if(!yesno(1, _("Do you want to remove uninstalled packages from cache?"))) { + if(!yesno(_("Do you want to remove uninstalled packages from cache?"))) { return(0); } break; case PM_CLEAN_KEEPCUR: - if(!yesno(1, _("Do you want to remove outdated packages from cache?"))) { + if(!yesno(_("Do you want to remove outdated packages from cache?"))) { return(0); } break; @@ -215,7 +215,7 @@ static int sync_cleancache(int level) } else { /* full cleanup */ printf(_("Cache directory: %s\n"), cachedir); - if(!yesno(0, _("Do you want to remove ALL packages from cache?"))) { + if(!noyes(_("Do you want to remove ALL packages from cache?"))) { return(0); } printf(_("removing all packages from cache... ")); @@ -604,14 +604,14 @@ static int sync_trans(alpm_list_t *targets) (char*)alpm_pkg_get_name(k->data)); } list_display(" ", pkgnames); - if(yesno(1, _(":: Install whole content?"))) { + if(yesno(_(":: Install whole content?"))) { for(k = pkgnames; k; k = alpm_list_next(k)) { targets = alpm_list_add(targets, strdup(alpm_list_getdata(k))); } } else { for(k = pkgnames; k; k = alpm_list_next(k)) { char *pkgname = alpm_list_getdata(k); - if(yesno(1, _(":: Install %s from group %s?"), pkgname, targ)) { + if(yesno(_(":: Install %s from group %s?"), pkgname, targ)) { targets = alpm_list_add(targets, strdup(pkgname)); } } @@ -666,23 +666,32 @@ static int sync_trans(alpm_list_t *targets) goto cleanup; } - if(!(alpm_trans_get_flags() & PM_TRANS_FLAG_PRINTURIS)) { - int confirm; + /* Step 3: actually perform the operation */ + if(config->op_s_printuris) { + /* print uris */ + alpm_list_t *i; + for(i = packages; i; i = alpm_list_next(i)) { + pmpkg_t *pkg = alpm_sync_get_pkg((pmsyncpkg_t *)alpm_list_getdata(i)); + pmdb_t *db = alpm_pkg_get_db(pkg); + printf("%s/%s\n", alpm_db_get_url(db), alpm_pkg_get_filename(pkg)); + } + /* we are done */ + goto cleanup; + } - display_synctargets(packages); - printf("\n"); + display_synctargets(packages); + printf("\n"); - if(config->op_s_downloadonly) { - confirm = yesno(1, _("Proceed with download?")); - } else { - confirm = yesno(1, _("Proceed with installation?")); - } - if(!confirm) { - goto cleanup; - } - }/* else 'print uris' requested. We're done at this point */ + int confirm; + if(config->op_s_downloadonly) { + confirm = yesno(_("Proceed with download?")); + } else { + confirm = yesno(_("Proceed with installation?")); + } + if(!confirm) { + goto cleanup; + } - /* Step 3: actually perform the installation */ if(alpm_trans_commit(&data) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"), alpm_strerrorlast()); @@ -739,7 +748,7 @@ int pacman_sync(alpm_list_t *targets) alpm_list_t *sync_dbs = NULL; /* Display only errors with -Sp and -Sw operations */ - if(config->flags & (PM_TRANS_FLAG_DOWNLOADONLY | PM_TRANS_FLAG_PRINTURIS)) { + if((config->flags & PM_TRANS_FLAG_DOWNLOADONLY) || config->op_s_printuris) { config->logmask &= ~PM_LOG_WARNING; } @@ -811,13 +820,13 @@ int pacman_sync(alpm_list_t *targets) } alpm_list_t *targs = alpm_list_strdup(targets); - if(!(config->flags & (PM_TRANS_FLAG_DOWNLOADONLY | PM_TRANS_FLAG_PRINTURIS))) { + if(!(config->flags & PM_TRANS_FLAG_DOWNLOADONLY) && !config->op_s_printuris) { /* check for newer versions of packages to be upgraded first */ alpm_list_t *packages = syncfirst(); if(packages) { printf(_(":: The following packages should be upgraded first :\n")); list_display(" ", packages); - if(yesno(1, _(":: Do you want to cancel the current operation\n" + if(yesno(_(":: Do you want to cancel the current operation\n" ":: and upgrade these packages now?"))) { FREELIST(targs); targs = packages; diff --git a/src/pacman/util.c b/src/pacman/util.c index c31714e4..14ae0ed3 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -619,10 +619,9 @@ void display_optdepends(pmpkg_t *pkg) } /* presents a prompt and gets a Y/N answer */ -int yesno(short preset, char *fmt, ...) +static int question(short preset, char *fmt, va_list args) { char response[32]; - va_list args; FILE *stream; if(config->noconfirm) { @@ -632,9 +631,7 @@ int yesno(short preset, char *fmt, ...) stream = stderr; } - va_start(args, fmt); vfprintf(stream, fmt, args); - va_end(args); if(preset) { fprintf(stream, " %s ", _("[Y/n]")); @@ -662,6 +659,30 @@ int yesno(short preset, char *fmt, ...) return(0); } +int yesno(char *fmt, ...) +{ + int ret; + va_list args; + + va_start(args, fmt); + ret = question(1, fmt, args); + va_end(args); + + return(ret); +} + +int noyes(char *fmt, ...) +{ + int ret; + va_list args; + + va_start(args, fmt); + ret = question(0, fmt, args); + va_end(args); + + return(ret); +} + int pm_printf(pmloglevel_t level, const char *format, ...) { int ret; diff --git a/src/pacman/util.h b/src/pacman/util.h index f94f0aed..66a9c4e7 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -55,7 +55,8 @@ void list_display_linebreak(const char *title, const alpm_list_t *list); void display_targets(const alpm_list_t *pkgs, int install); void display_synctargets(const alpm_list_t *syncpkgs); void display_optdepends(pmpkg_t *pkg); -int yesno(short preset, char *fmt, ...); +int yesno(char *fmt, ...); +int noyes(char *fmt, ...); int pm_printf(pmloglevel_t level, const char *format, ...) __attribute__((format(printf,2,3))); int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...) __attribute__((format(printf,3,4))); int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0))); |