diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/pacman/callback.c | 124 | ||||
-rw-r--r-- | src/pacman/callback.h | 3 | ||||
-rw-r--r-- | src/pacman/deptest.c | 46 | ||||
-rw-r--r-- | src/pacman/pacman.c | 10 | ||||
-rw-r--r-- | src/pacman/remove.c | 6 | ||||
-rw-r--r-- | src/pacman/sync.c | 83 | ||||
-rw-r--r-- | src/pacman/util.c | 63 | ||||
-rw-r--r-- | src/pacman/util.h | 2 | ||||
-rw-r--r-- | src/util/testdb.c | 8 |
9 files changed, 142 insertions, 203 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 01e65a95..47b538e5 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -34,9 +34,6 @@ #include "util.h" #include "conf.h" -/* TODO this should not have to be defined twice- trans.c & log.c */ -#define LOG_STR_LEN 256 - /* download progress bar */ static float rate_last; static int xfered_last; @@ -86,17 +83,14 @@ static float get_update_timediff(int first_call) } /* refactored from cb_trans_progress */ -static void fill_progress(const int graph_percent, const int display_percent, - const int proglen) +static void fill_progress(const int percent, const int proglen) { const unsigned int hashlen = proglen - 8; - const unsigned int hash = graph_percent * hashlen / 100; + const unsigned int hash = percent * hashlen / 100; static unsigned int lasthash = 0, mouth = 0; unsigned int i; - /* printf("\ndebug: proglen: %i\n", proglen); DEBUG*/ - - if(graph_percent == 0) { + if(percent == 0) { lasthash = 0; mouth = 0; } @@ -141,10 +135,10 @@ static void fill_progress(const int graph_percent, const int display_percent, } /* print percent after progress bar */ if(proglen > 5) { - printf(" %3d%%", display_percent); + printf(" %3d%%", percent); } - if(graph_percent == 100) { + if(percent == 100) { printf("\n"); } else { printf("\r"); @@ -157,8 +151,6 @@ static void fill_progress(const int graph_percent, const int display_percent, /* callback to handle messages/notifications from libalpm transactions */ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) { - char str[LOG_STR_LEN] = ""; - switch(event) { case PM_TRANS_EVT_CHECKDEPS_START: printf(_("checking dependencies...\n")); @@ -180,10 +172,9 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) } break; case PM_TRANS_EVT_ADD_DONE: - snprintf(str, LOG_STR_LEN, "installed %s (%s)\n", + alpm_logaction("installed %s (%s)\n", alpm_pkg_get_name(data1), alpm_pkg_get_version(data1)); - alpm_logaction(str); break; case PM_TRANS_EVT_REMOVE_START: if(config->noprogressbar) { @@ -191,10 +182,9 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) } break; case PM_TRANS_EVT_REMOVE_DONE: - snprintf(str, LOG_STR_LEN, "removed %s (%s)\n", + alpm_logaction("removed %s (%s)\n", alpm_pkg_get_name(data1), alpm_pkg_get_version(data1)); - alpm_logaction(str); break; case PM_TRANS_EVT_UPGRADE_START: if(config->noprogressbar) { @@ -202,11 +192,10 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) } break; case PM_TRANS_EVT_UPGRADE_DONE: - snprintf(str, LOG_STR_LEN, "upgraded %s (%s -> %s)\n", + alpm_logaction("upgraded %s (%s -> %s)\n", (char *)alpm_pkg_get_name(data1), (char *)alpm_pkg_get_version(data2), (char *)alpm_pkg_get_version(data1)); - alpm_logaction(str); break; case PM_TRANS_EVT_INTEGRITY_START: printf(_("checking package integrity...\n")); @@ -255,67 +244,46 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) void cb_trans_conv(pmtransconv_t event, void *data1, void *data2, void *data3, int *response) { - char str[LOG_STR_LEN] = ""; - switch(event) { case PM_TRANS_CONV_INSTALL_IGNOREPKG: if(data2) { /* TODO we take this route based on data2 being not null? WTF */ - snprintf(str, LOG_STR_LEN, _(":: %s requires installing %s from IgnorePkg/IgnoreGroup. Install anyway? [Y/n] "), + *response = yesno(1, _(":: %s requires installing %s from IgnorePkg/IgnoreGroup. Install anyway?"), alpm_pkg_get_name(data1), alpm_pkg_get_name(data2)); - *response = yesno(str); } else { - snprintf(str, LOG_STR_LEN, _(":: %s is in IgnorePkg/IgnoreGroup. Install anyway? [Y/n] "), + *response = yesno(1, _(":: %s is in IgnorePkg/IgnoreGroup. Install anyway?"), alpm_pkg_get_name(data1)); - *response = yesno(str); } break; case PM_TRANS_CONV_REMOVE_HOLDPKG: - snprintf(str, LOG_STR_LEN, _(":: %s is designated as a HoldPkg. Remove anyway? [Y/n] "), + *response = yesno(1, _(":: %s is designated as a HoldPkg. Remove anyway?"), alpm_pkg_get_name(data1)); - *response = yesno(str); break; case PM_TRANS_CONV_REPLACE_PKG: - if(!config->noconfirm) { - snprintf(str, LOG_STR_LEN, _(":: Replace %s with %s/%s? [Y/n] "), - alpm_pkg_get_name(data1), - (char *)data3, - alpm_pkg_get_name(data2)); - *response = yesno(str); - } else { - printf(_("Replacing %s with %s/%s\n"), - alpm_pkg_get_name(data1), - (char *)data3, - alpm_pkg_get_name(data2)); - *response = 1; - } + *response = yesno(1, _(":: Replace %s with %s/%s?"), + alpm_pkg_get_name(data1), + (char *)data3, + alpm_pkg_get_name(data2)); break; case PM_TRANS_CONV_CONFLICT_PKG: - snprintf(str, LOG_STR_LEN, _(":: %s conflicts with %s. Remove %s? [Y/n] "), + *response = yesno(1, _(":: %s conflicts with %s. Remove %s?"), (char *)data1, (char *)data2, (char *)data2); - *response = yesno(str); break; case PM_TRANS_CONV_LOCAL_NEWER: if(!config->op_s_downloadonly) { - snprintf(str, LOG_STR_LEN, _(":: %s-%s: local version is newer. Upgrade anyway? [Y/n] "), + *response = yesno(1, _(":: %s-%s: local version is newer. Upgrade anyway?"), alpm_pkg_get_name(data1), alpm_pkg_get_version(data1)); - *response = yesno(str); } else { *response = 1; } break; case PM_TRANS_CONV_CORRUPTED_PKG: - if(!config->noconfirm) { - snprintf(str, LOG_STR_LEN, _(":: File %s is corrupted. Do you want to delete it? [Y/n] "), - (char *)data1); - *response = yesno(str); - } else { - *response = 1; - } + *response = yesno(1, _(":: File %s is corrupted. Do you want to delete it?"), + (char *)data1); break; } } @@ -417,7 +385,7 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, free(wcstr); /* call refactored fill progress function */ - fill_progress(percent, percent, getcols() - infolen); + fill_progress(percent, getcols() - infolen); if(percent == 100) { alpm_list_t *i = NULL; @@ -433,8 +401,7 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, } /* callback to handle display of download progress */ -void cb_dl_progress(const char *filename, int file_xfered, int file_total, - int list_xfered, int list_total) +void cb_dl_progress(const char *filename, int xfered, int total) { const int infolen = 50; const int filenamelen = infolen - 27; @@ -445,43 +412,22 @@ void cb_dl_progress(const char *filename, int file_xfered, int file_total, float rate = 0.0, timediff = 0.0, f_xfered = 0.0; unsigned int eta_h = 0, eta_m = 0, eta_s = 0; - int graph_percent = 0, display_percent = 0; + int percent; char rate_size = 'K', xfered_size = 'K'; - int xfered = 0, total = 0; - - /* Need this variable when TotalDownload is set to know if we should - * reset xfered_last and rate_last. */ - static int has_init = 0; if(config->noprogressbar) { return; } - /* Choose how to display the amount downloaded, rate, ETA, and - * percentage depending on the TotalDownload option. */ - if (config->totaldownload && list_total > 0) { - xfered = list_xfered; - total = list_total; - } else { - xfered = file_xfered; - total = file_total; - } - /* this is basically a switch on file_xferred: 0, file_total, and * anything else */ - if(file_xfered == 0) { - /* set default starting values, but only once for TotalDownload */ - if (!(config->totaldownload && list_total > 0) || - (config->totaldownload && list_total > 0 && !has_init)) { - gettimeofday(&initial_time, NULL); - timediff = get_update_timediff(1); - xfered_last = 0; - rate_last = 0.0; - has_init = 1; - } - rate = 0.0; - eta_s = 0; - } else if(file_xfered == file_total) { + if(xfered == 0) { + /* set default starting values */ + gettimeofday(&initial_time, NULL); + xfered_last = 0; + rate_last = 0.0; + timediff = get_update_timediff(1); + } else if(xfered == total) { /* compute final values */ struct timeval current_time; float diff_sec, diff_usec; @@ -490,7 +436,7 @@ void cb_dl_progress(const char *filename, int file_xfered, int 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 = total / (timediff * 1024.0); /* round elapsed time to the nearest second */ eta_s = (int)(timediff + 0.5); @@ -504,12 +450,14 @@ void cb_dl_progress(const char *filename, int file_xfered, int file_total, } rate = (xfered - xfered_last) / (timediff * 1024.0); /* average rate to reduce jumpiness */ - rate = (rate + 2*rate_last) / 3; + rate = (rate + 2 * rate_last) / 3; eta_s = (total - xfered) / (rate * 1024.0); rate_last = rate; xfered_last = xfered; } + percent = (int)((float)xfered) / ((float)total) * 100; + /* fix up time for display */ eta_h = eta_s / 3600; eta_s -= eta_h * 3600; @@ -581,11 +529,7 @@ void cb_dl_progress(const char *filename, int file_xfered, int file_total, free(fname); free(wcfname); - /* The progress bar is based on the file percent regardless of the - * TotalDownload option. */ - graph_percent = (int)((float)file_xfered) / ((float)file_total) * 100; - display_percent = (int)((float)xfered) / ((float)total) * 100; - fill_progress(graph_percent, display_percent, getcols() - infolen); + fill_progress(percent, getcols() - infolen); return; } diff --git a/src/pacman/callback.h b/src/pacman/callback.h index aa8d9370..39d59d8b 100644 --- a/src/pacman/callback.h +++ b/src/pacman/callback.h @@ -33,8 +33,7 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, int howmany, int remain); /* callback to handle display of download progress */ -void cb_dl_progress(const char *filename, int file_xfered, int file_total, - int list_xfered, int list_total); +void cb_dl_progress(const char *filename, int file_xfered, int file_total); /* callback to handle messages/notifications from pacman library */ void cb_log(pmloglevel_t level, char *fmt, va_list args); diff --git a/src/pacman/deptest.c b/src/pacman/deptest.c index 2481c0b6..2feca5c4 100644 --- a/src/pacman/deptest.c +++ b/src/pacman/deptest.c @@ -31,53 +31,23 @@ #include "util.h" #include "conf.h" -/* TODO: This should use _alpm_checkdeps() */ int pacman_deptest(alpm_list_t *targets) { - int retval = 0; alpm_list_t *i; - if(targets == NULL) { + alpm_list_t *deps = alpm_deptest(alpm_option_get_localdb(), targets); + if(deps == NULL) { return(0); } - for(i = targets; i; i = alpm_list_next(i)) { - int found = 0; - pmpkg_t *pkg; - pmdepend_t *dep; - const char *target; - alpm_list_t *j, *provides; + for(i = deps; i; i = alpm_list_next(i)) { + const char *dep; - target = alpm_list_getdata(i); - dep = alpm_splitdep(target); - - pkg = alpm_db_get_pkg(alpm_option_get_localdb(), - alpm_dep_get_name(dep)); - if(pkg && alpm_depcmp(pkg, dep)) { - found = 1; - } else { - /* not found, can we find anything that provides this in the local DB? */ - provides = alpm_db_whatprovides(alpm_option_get_localdb(), - alpm_dep_get_name(dep)); - for(j = provides; j; j = alpm_list_next(j)) { - pmpkg_t *pkg; - pkg = alpm_list_getdata(j); - - if(pkg && alpm_depcmp(pkg, dep)) { - found = 1; - break; - } - } - alpm_list_free(provides); - } - - if(!found) { - printf("%s\n", target); - retval = 127; - } - free(dep); + dep = alpm_list_getdata(i); + printf("%s\n", dep); } - return(retval); + alpm_list_free(deps); + return(127); } /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 377ea3fe..f1853203 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -79,6 +79,7 @@ static void usage(int op, const char * const myname) printf("%s: %s {-A --add} [%s] <%s>\n", str_usg, myname, str_opt, str_file); printf("%s:\n", str_opt); printf(_(" --asdeps install packages as non-explicitly installed\n")); + printf(_(" --asexplicit install packages as explicitly installed\n")); printf(_(" -d, --nodeps skip dependency checks\n")); printf(_(" -f, --force force install, overwrite conflicting files\n")); } else if(op == PM_OP_REMOVE) { @@ -89,10 +90,12 @@ static void usage(int op, const char * const myname) printf(_(" -k, --dbonly only remove database entry, do not remove files\n")); printf(_(" -n, --nosave remove configuration files as well\n")); printf(_(" -s, --recursive remove dependencies also (that won't break packages)\n")); + printf(_(" -u, --unneeded remove unneeded packages (that won't break packages)\n")); } else if(op == PM_OP_UPGRADE) { printf("%s: %s {-U --upgrade} [%s] <%s>\n", str_usg, myname, str_opt, str_file); printf("%s:\n", str_opt); printf(_(" --asdeps install packages as non-explicitly installed\n")); + printf(_(" --asexplicit install packages as explicitly installed\n")); printf(_(" -d, --nodeps skip dependency checks\n")); printf(_(" -f, --force force install, overwrite conflicting files\n")); } else if(op == PM_OP_QUERY) { @@ -115,6 +118,7 @@ static void usage(int op, const char * const myname) printf("%s: %s {-S --sync} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg); printf("%s:\n", str_opt); printf(_(" --asdeps install packages as non-explicitly installed\n")); + printf(_(" --asexplicit install packages as explicitly installed\n")); printf(_(" -c, --clean remove old packages from cache directory (-cc for all)\n")); printf(_(" -d, --nodeps skip dependency checks\n")); printf(_(" -e, --dependsonly install dependencies only\n")); @@ -331,6 +335,7 @@ static int parseargs(int argc, char *argv[]) {"unrequired", no_argument, 0, 't'}, {"upgrades", no_argument, 0, 'u'}, {"sysupgrade", no_argument, 0, 'u'}, + {"unneeded", no_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"downloadonly", no_argument, 0, 'w'}, {"refresh", no_argument, 0, 'y'}, @@ -345,6 +350,7 @@ static int parseargs(int argc, char *argv[]) {"logfile", required_argument, 0, 1009}, {"ignoregroup", required_argument, 0, 1010}, {"needed", no_argument, 0, 1011}, + {"asexplicit", no_argument, 0, 1012}, {0, 0, 0, 0} }; @@ -416,6 +422,9 @@ static int parseargs(int argc, char *argv[]) FREELIST(list); break; case 1011: config->flags |= PM_TRANS_FLAG_NEEDED; break; + case 1012: + config->flags |= PM_TRANS_FLAG_ALLEXPLICIT; + break; case 'A': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_ADD); 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; @@ -469,6 +478,7 @@ static int parseargs(int argc, char *argv[]) case 'u': config->op_s_upgrade = 1; config->op_q_upgrade = 1; + config->flags |= PM_TRANS_FLAG_UNNEEDED; break; case 'v': (config->verbose)++; break; case 'w': diff --git a/src/pacman/remove.c b/src/pacman/remove.c index e3750e4c..2fb69d35 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -75,11 +75,11 @@ int pacman_remove(alpm_list_t *targets) printf(_(":: group %s:\n"), alpm_grp_get_name(grp)); list_display(" ", pkgnames); - all = yesno(_(" Remove whole content? [Y/n] ")); + all = yesno(1, _(" Remove whole content?")); for(p = pkgnames; p; p = alpm_list_next(p)) { char *pkg = alpm_list_getdata(p); - if(all || yesno(_(":: Remove %s from group %s? [Y/n] "), pkg, (char *)alpm_list_getdata(i))) { + if(all || yesno(1, _(":: Remove %s from group %s?"), pkg, (char *)alpm_list_getdata(i))) { finaltargs = alpm_list_add(finaltargs, strdup(pkg)); } } @@ -153,7 +153,7 @@ int pacman_remove(alpm_list_t *targets) list_display(_("Targets:"), lst); FREELIST(lst); /* get confirmation */ - if(yesno(_("\nDo you want to remove these packages? [Y/n] ")) == 0) { + if(yesno(1, _("\nDo you want to remove these packages?")) == 0) { remove_cleanup(); FREELIST(finaltargs); return(1); diff --git a/src/pacman/sync.c b/src/pacman/sync.c index e3e87703..f2d8f4bc 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -89,7 +89,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(_("Do you want to remove %s? [Y/n] "), path)) { + if(!yesno(1, _("Do you want to remove %s?"), path)) { continue; } @@ -108,7 +108,7 @@ static int sync_cleandb_all(void) { char newdbpath[PATH_MAX]; printf(_("Database directory: %s\n"), dbpath); - if(!yesno(_("Do you want to remove unused repositories? [Y/n] "))) { + if(!yesno(1, _("Do you want to remove unused repositories?"))) { return(0); } /* The sync dbs were previously put in dbpath/, but are now in dbpath/sync/, @@ -138,7 +138,7 @@ static int sync_cleancache(int level) * package and see if it has an entry in the local DB; if not, delete it. */ printf(_("Cache directory: %s\n"), cachedir); - if(!yesno(_("Do you want to remove uninstalled packages from cache? [Y/n] "))) { + if(!yesno(1, _("Do you want to remove uninstalled packages from cache?"))) { return(0); } printf(_("removing old packages from cache... ")); @@ -185,7 +185,7 @@ static int sync_cleancache(int level) } else { /* full cleanup */ printf(_("Cache directory: %s\n"), cachedir); - if(!yesno(_("Do you want to remove ALL packages from cache? [Y/n] "))) { + if(!yesno(0, _("Do you want to remove ALL packages from cache?"))) { return(0); } printf(_("removing all packages from cache... ")); @@ -232,6 +232,10 @@ static int sync_synctree(int level, alpm_list_t *syncs) alpm_list_t *i; int success = 0, ret; + if(sync_trans_init(0) == -1) { + return(0); + } + for(i = syncs; i; i = alpm_list_next(i)) { pmdb_t *db = alpm_list_getdata(i); @@ -259,10 +263,16 @@ static int sync_synctree(int level, alpm_list_t *syncs) } } + if(sync_trans_release() == -1) { + 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 * expected */ + if(!success) { + fprintf(stderr, _("error: failed to synchronize any databases\n")); + } return(success > 0); } @@ -499,7 +509,7 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets) return(0); } -static int sync_trans(alpm_list_t *targets, int sync_only) +static int sync_trans(alpm_list_t *targets) { int retval = 0; alpm_list_t *data = NULL; @@ -510,23 +520,8 @@ static int sync_trans(alpm_list_t *targets, int sync_only) return(1); } - if(config->op_s_sync) { - /* grab a fresh package list */ - printf(_(":: Synchronizing package databases...\n")); - alpm_logaction("synchronizing package lists\n"); - if(!sync_synctree(config->op_s_sync, sync_dbs)) { - fprintf(stderr, _("error: failed to synchronize any databases\n")); - retval = 1; - goto cleanup; - } - if(sync_only) { - goto cleanup; - } - } - if(config->op_s_upgrade) { alpm_list_t *pkgs, *i; - printf(_(":: Starting full system upgrade...\n")); alpm_logaction("starting full system upgrade\n"); if(alpm_trans_sysupgrade() == -1) { @@ -550,8 +545,8 @@ static int sync_trans(alpm_list_t *targets, int sync_only) if(strcmp("pacman", alpm_pkg_get_name(spkg)) == 0) { printf("\n"); printf(_(":: pacman has detected a newer version of itself.\n")); - if(yesno(_(":: Do you want to cancel the current operation\n" - ":: and install the new pacman version now? [Y/n] "))) { + if(yesno(1, _(":: Do you want to cancel the current operation\n" + ":: and install the new pacman version now?"))) { if(sync_trans_release() == -1) { return(1); } @@ -602,14 +597,14 @@ static int sync_trans(alpm_list_t *targets, int sync_only) const alpm_list_t *grppkgs = alpm_grp_get_pkgs(grp); alpm_list_t *pkgs = alpm_list_remove_dupes(grppkgs); list_display(" ", pkgs); - if(yesno(_(":: Install whole content? [Y/n] "))) { + if(yesno(1, _(":: Install whole content?"))) { for(k = pkgs; k; k = alpm_list_next(k)) { targets = alpm_list_add(targets, strdup(alpm_list_getdata(k))); } } else { for(k = pkgs; k; k = alpm_list_next(k)) { char *pkgname = alpm_list_getdata(k); - if(yesno(_(":: Install %s from group %s? [Y/n] "), pkgname, targ)) { + if(yesno(1, _(":: Install %s from group %s?"), pkgname, targ)) { targets = alpm_list_add(targets, strdup(pkgname)); } } @@ -698,19 +693,9 @@ static int sync_trans(alpm_list_t *targets, int sync_only) printf("\n"); if(config->op_s_downloadonly) { - if(config->noconfirm) { - printf(_("Beginning download...\n")); - confirm = 1; - } else { - confirm = yesno(_("Proceed with download? [Y/n] ")); - } + confirm = yesno(1, _("Proceed with download?")); } else { - if(config->noconfirm) { - printf(_("Beginning upgrade process...\n")); - confirm = 1; - } else { - confirm = yesno(_("Proceed with installation? [Y/n] ")); - } + confirm = yesno(1, _("Proceed with installation?")); } if(!confirm) { goto cleanup; @@ -741,9 +726,11 @@ static int sync_trans(alpm_list_t *targets, int sync_only) } } break; - case PM_ERR_PKG_CORRUPTED: + case PM_ERR_PKG_INVALID: + case PM_ERR_DLT_INVALID: for(i = data; i; i = alpm_list_next(i)) { - printf("%s", (char*)alpm_list_getdata(i)); + char *filename = alpm_list_getdata(i); + printf(_("%s is invalid or corrupted\n"), filename); } break; default: @@ -770,7 +757,6 @@ cleanup: int pacman_sync(alpm_list_t *targets) { alpm_list_t *sync_dbs = NULL; - int sync_only = 0; /* clean the cache */ if(config->op_s_clean) { @@ -797,18 +783,27 @@ int pacman_sync(alpm_list_t *targets) return(1); } - if(config->op_s_search || config->group - || config->op_s_info || config->op_q_list) { - sync_only = 1; - } else if(targets == NULL && !(config->op_s_sync || config->op_s_upgrade)) { + if(targets == NULL && !(config->op_s_sync || config->op_s_upgrade + || config->op_s_search || config->group + || config->op_s_info || config->op_q_list)) { /* 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); } + if(config->op_s_sync) { + /* grab a fresh package list */ + printf(_(":: Synchronizing package databases...\n")); + alpm_logaction("synchronizing package lists\n"); + if(!sync_synctree(config->op_s_sync, sync_dbs)) { + return(1); + } + config->op_s_sync = 0; + } + if(needs_transaction()) { - if(sync_trans(targets, sync_only) == 1) { + if(sync_trans(targets) == 1) { return(1); } } diff --git a/src/pacman/util.c b/src/pacman/util.c index aa08eb26..2623dbdb 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -234,6 +234,10 @@ void indentprint(const char *str, int indent) p = wcstr; cidx = indent; + if(!p) { + return; + } + while(*p) { if(*p == L' ') { const wchar_t *q, *next; @@ -464,20 +468,17 @@ void display_targets(const alpm_list_t *syncpkgs, pmdb_t *db_local) pmsyncpkg_t *sync = alpm_list_getdata(i); pmpkg_t *pkg = alpm_sync_get_pkg(sync); - /* If this sync record is a replacement, the data member contains - * a list of packages to be removed due to the package that is being - * installed. */ - if(alpm_sync_get_type(sync) == PM_SYNC_TYPE_REPLACE) { - alpm_list_t *to_replace = alpm_sync_get_data(sync); + /* The removes member contains a list of packages to be removed + * due to the package that is being installed. */ + alpm_list_t *to_replace = alpm_sync_get_removes(sync); - for(j = to_replace; j; j = alpm_list_next(j)) { - pmpkg_t *rp = alpm_list_getdata(j); - const char *name = alpm_pkg_get_name(rp); + for(j = to_replace; j; j = alpm_list_next(j)) { + pmpkg_t *rp = alpm_list_getdata(j); + const char *name = alpm_pkg_get_name(rp); - if(!alpm_list_find_str(to_remove, name)) { - rsize += alpm_pkg_get_isize(rp); - to_remove = alpm_list_add(to_remove, strdup(name)); - } + if(!alpm_list_find_str(to_remove, name)) { + rsize += alpm_pkg_get_isize(rp); + to_remove = alpm_list_add(to_remove, strdup(name)); } } @@ -520,38 +521,50 @@ void display_targets(const alpm_list_t *syncpkgs, pmdb_t *db_local) printf("\n"); printf(_("Total Download Size: %.2f MB\n"), mbdlsize); - - /* TODO because all pkgs don't include isize, this is a crude hack */ - if(mbisize > mbdlsize) { - printf(_("Total Installed Size: %.2f MB\n"), mbisize); - } + printf(_("Total Installed Size: %.2f MB\n"), mbisize); FREELIST(targets); } /* presents a prompt and gets a Y/N answer */ -/* TODO there must be a better way */ -int yesno(char *fmt, ...) +int yesno(short preset, char *fmt, ...) { char response[32]; va_list args; + FILE *stream; if(config->noconfirm) { - return(1); + stream = stdout; + } else { + /* Use stderr so questions are always displayed when redirecting output */ + stream = stderr; } va_start(args, fmt); - /* Use stderr so questions are always displayed when redirecting output */ - vfprintf(stderr, fmt, args); + vfprintf(stream, fmt, args); va_end(args); + if(preset) { + fprintf(stream, " %s ", _("[Y/n]")); + } else { + fprintf(stream, " %s ", _("[y/N]")); + } + + if(config->noconfirm) { + fprintf(stream, "\n"); + return(preset); + } + if(fgets(response, 32, stdin)) { - if(strlen(response) != 0) { - strtrim(response); + strtrim(response); + if(strlen(response) == 0) { + return(preset); } - if(!strcasecmp(response, _("Y")) || !strcasecmp(response, _("YES")) || strlen(response) == 0) { + if(!strcasecmp(response, _("Y")) || !strcasecmp(response, _("YES"))) { return(1); + } else if (!strcasecmp(response, _("N")) || !strcasecmp(response, _("NO"))) { + return(0); } } return(0); diff --git a/src/pacman/util.h b/src/pacman/util.h index 0273512e..f2facbfc 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -50,7 +50,7 @@ alpm_list_t *strsplit(const char *str, const char splitchar); void string_display(const char *title, const char *string); void list_display(const char *title, const alpm_list_t *list); void display_targets(const alpm_list_t *syncpkgs, pmdb_t *db_local); -int yesno(char *fmt, ...); +int yesno(short preset, 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))); diff --git a/src/util/testdb.c b/src/util/testdb.c index 122a3fb5..f354ecab 100644 --- a/src/util/testdb.c +++ b/src/util/testdb.c @@ -147,6 +147,14 @@ int main(int argc, char **argv) free(depstring); } + /* check conflicts */ + data = alpm_checkdbconflicts(db); + for(i = data; i; i = i->next) { + pmconflict_t *conflict = alpm_list_getdata(i); + printf("%s conflicts with %s\n", alpm_conflict_get_package1(conflict), + alpm_conflict_get_package2(conflict)); + } + cleanup(retval); } |