From 273950473ea4fed67c0af0a4905bd3d3cbac15b3 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 16 Feb 2008 17:44:21 -0600 Subject: Add gettext call to 2 'failed' messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Noticed-by: Vojtěch Gondžala Signed-off-by: Dan McGee --- src/pacman/add.c | 2 +- src/pacman/remove.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/pacman') diff --git a/src/pacman/add.c b/src/pacman/add.c index debe5c47..9d646e11 100644 --- a/src/pacman/add.c +++ b/src/pacman/add.c @@ -115,7 +115,7 @@ int pacman_add(alpm_list_t *targets) for(i = targets; i; i = alpm_list_next(i)) { char *targ = alpm_list_getdata(i); if(alpm_trans_addtarget(targ) == -1) { - printf("failed.\n"); + printf(_("failed.\n")); fprintf(stderr, _("error: '%s': %s\n"), targ, alpm_strerrorlast()); add_cleanup(); diff --git a/src/pacman/remove.c b/src/pacman/remove.c index 0722057f..4c5b5c09 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -107,7 +107,7 @@ int pacman_remove(alpm_list_t *targets) for(i = finaltargs; i; i = alpm_list_next(i)) { char *targ = alpm_list_getdata(i); if(alpm_trans_addtarget(targ) == -1) { - printf("failed.\n"); + printf(_("failed.\n")); fprintf(stderr, _("error: '%s': %s\n"), targ, alpm_strerrorlast()); remove_cleanup(); -- cgit v1.2.3-70-g09d2 From 2374c81e55abc0f7252fad7eb53d2b75bb33f750 Mon Sep 17 00:00:00 2001 From: Chantry Xavier Date: Sun, 17 Feb 2008 23:31:26 +0100 Subject: Fix conflict progress bar with UTF-8 chars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes FS#6437. Dan already explained the problem in that bug report. Instead of letting printf deal with the length of utf8 strings, we can handle it more explicitly in the case of conflict progress bar, just like we do for add/remove progress bars. We compute the remaining space left for displaying the pkgname in case of add/remove, and an empty string in case of conflict. Before : (1/1) Prüfe auf Dateikonflikte [###################] 100% (1/1) Aktualisiere rxvt-unicode [###################] 100% After : (1/1) Prüfe auf Dateikonflikte [###################] 100% (1/1) Aktualisiere rxvt-unicode [###################] 100% Signed-off-by: Chantry Xavier Signed-off-by: Dan McGee --- src/pacman/callback.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) (limited to 'src/pacman') diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 268a8a7f..cf07a09d 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -329,9 +329,8 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, /* size of line to allocate for text printing (e.g. not progressbar) */ const int infolen = 50; - int tmp, digits, oprlen, textlen, pkglen; + int tmp, digits, oprlen, textlen, remainlen; char *opr = NULL; - wchar_t *wcopr = NULL; if(config->noprogressbar) { return; @@ -373,15 +372,6 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, opr = _("checking for file conflicts"); break; } - /* convert above strings to wide chars */ - oprlen = strlen(opr); - wcopr = calloc(oprlen, sizeof(wchar_t)); - if(!wcopr) { - fprintf(stderr, "malloc failure: could not allocate %zd bytes\n", - strlen(opr) * sizeof(wchar_t)); - return; - } - oprlen = mbstowcs(wcopr, opr, oprlen); /* find # of digits in package counts to scale output */ digits = 1; @@ -392,30 +382,24 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, /* determine room left for non-digits text [not ( 1/12) part] */ textlen = infolen - 3 - (2 * digits); - /* room left for package name */ - pkglen = textlen - oprlen - 1; + + oprlen = mbstowcs(NULL, opr, 0); + /* room left (eg for package name) */ + remainlen = textlen - oprlen - 1; switch (event) { case PM_TRANS_PROGRESS_ADD_START: case PM_TRANS_PROGRESS_UPGRADE_START: case PM_TRANS_PROGRESS_REMOVE_START: - /* old way of doing it, but ISO C does not recognize it - printf("(%2$*1$d/%3$*1$d) %4$s %6$-*5$.*5$s", digits, remain, howmany, - opr, pkglen, pkgname);*/ printf("(%*d/%*d) %s %-*.*s", digits, remain, digits, howmany, - opr, pkglen, pkglen, pkgname); + opr, remainlen, remainlen, pkgname); break; case PM_TRANS_PROGRESS_CONFLICTS_START: - /* old way of doing it, but ISO C does not recognize it - printf("(%2$*1$d/%3$*1$d) %5$-*4$s", digits, remain, howmany, - textlen, opr);*/ - printf("(%*d/%*d) %-*s", digits, remain, digits, howmany, - textlen, opr); + printf("(%*d/%*d) %s %-*s", digits, remain, digits, howmany, + opr, remainlen, ""); break; } - free(wcopr); - /* call refactored fill progress function */ fill_progress(percent, percent, getcols() - infolen); -- cgit v1.2.3-70-g09d2 From fc9d12bef039f558d9731c7dcb2f441ad5832def Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 19 Feb 2008 08:47:05 -0600 Subject: When cleaning DBs, only look at directories FS#9609 brought up an interesting issue where a user was prompted to remove db.lck when running a -Sc operation concurrently with an -Syu operation during a long download. Although there are other problems here, this fixes the issue where files other than directories could be considered to be databases. Fix this. Signed-off-by: Dan McGee --- src/pacman/sync.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/pacman') diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 27218d61..244fedce 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -57,6 +58,7 @@ static int sync_cleandb(const char *dbpath, int keep_used) { /* step through the directory one file at a time */ while((ent = readdir(dir)) != NULL) { char path[PATH_MAX]; + struct stat buf; alpm_list_t *syncdbs = NULL, *i; int found = 0; char *dname = ent->d_name; @@ -68,6 +70,15 @@ static int sync_cleandb(const char *dbpath, int keep_used) { if(!strcmp(dname, "sync") || !strcmp(dname, "local")) { continue; } + + /* build the full path */ + snprintf(path, PATH_MAX, "%s%s", dbpath, ent->d_name); + /* skip entries that are not dirs (lock file, etc.) */ + stat(path, &buf); + if(!S_ISDIR(buf.st_mode)) { + continue; + } + if(keep_used) { syncdbs = alpm_option_get_syncdbs(); for(i = syncdbs; i && !found; i = alpm_list_next(i)) { @@ -78,9 +89,6 @@ 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) { - /* build the full path */ - snprintf(path, PATH_MAX, "%s%s", dbpath, ent->d_name); - if(!yesno(_("Do you want to remove %s? [Y/n] "), path)) { continue; } -- cgit v1.2.3-70-g09d2 From 6f3949e3da4325f61ac53d7c8b86a18ff6acb64e Mon Sep 17 00:00:00 2001 From: Chantry Xavier Date: Tue, 19 Feb 2008 20:32:48 +0100 Subject: Add new sync_trans_init and sync_trans_release. Factorize these two functions to avoid code duplication, especially since they could be used for locking the database during -Sc and -Sy operation too. Signed-off-by: Chantry Xavier --- src/pacman/sync.c | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'src/pacman') diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 244fedce..5f83c753 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -205,6 +205,28 @@ static int sync_cleancache(int level) return(0); } +static int sync_trans_init(pmtransflag_t flags) { + if(alpm_trans_init(PM_TRANS_TYPE_SYNC, flags, cb_trans_evt, + cb_trans_conv, cb_trans_progress) == -1) { + fprintf(stderr, _("error: failed to init transaction (%s)\n"), + alpm_strerrorlast()); + if(pm_errno == PM_ERR_HANDLE_LOCK) { + printf(_(" if you're sure a package manager is not already\n" + " running, you can remove %s.\n"), alpm_option_get_lockfile()); + } + return(-1); + } + return(0); +} + +static int sync_trans_release() { + if(alpm_trans_release() == -1) { + fprintf(stderr, _("error: failed to release transaction (%s)\n"), + alpm_strerrorlast()); + return(-1); + } + return(0); +} static int sync_synctree(int level, alpm_list_t *syncs) { alpm_list_t *i; @@ -484,14 +506,7 @@ static int sync_trans(alpm_list_t *targets, int sync_only) alpm_list_t *sync_dbs = alpm_option_get_syncdbs(); /* Step 1: create a new transaction... */ - if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt, - cb_trans_conv, cb_trans_progress) == -1) { - fprintf(stderr, _("error: failed to init transaction (%s)\n"), - alpm_strerrorlast()); - if(pm_errno == PM_ERR_HANDLE_LOCK) { - printf(_(" if you're sure a package manager is not already\n" - " running, you can remove %s.\n"), alpm_option_get_lockfile()); - } + if(sync_trans_init(config->flags) == -1) { return(1); } @@ -537,22 +552,15 @@ static int sync_trans(alpm_list_t *targets, int sync_only) 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(alpm_trans_release() == -1) { - fprintf(stderr, _("error: failed to release transaction (%s)\n"), - alpm_strerrorlast()); - retval = 1; - goto cleanup; + if(sync_trans_release() == -1) { + return(1); } - if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, - cb_trans_evt, cb_trans_conv, cb_trans_progress) == -1) { - fprintf(stderr, _("error: failed to init transaction (%s)\n"), - alpm_strerrorlast()); + if(sync_trans_init(0) == -1) { return(1); } if(alpm_trans_addtarget("pacman") == -1) { fprintf(stderr, _("error: pacman: %s\n"), alpm_strerrorlast()); - retval = 1; - goto cleanup; + return(1); } break; } @@ -752,9 +760,7 @@ cleanup: if(data) { FREELIST(data); } - if(alpm_trans_release() == -1) { - fprintf(stderr, _("error: failed to release transaction (%s)\n"), - alpm_strerrorlast()); + if(sync_trans_release() == -1) { retval = 1; } -- cgit v1.2.3-70-g09d2 From 7879e4bef7c158814a547d232f0bde8960ee1341 Mon Sep 17 00:00:00 2001 From: Chantry Xavier Date: Tue, 19 Feb 2008 21:57:40 +0100 Subject: Lock the database on -Sc operation. This partly fixes FS#9609. Weird things could happen when running -Sc while another instance was already running. The cleancache function could delete packages that were just being downloaded. Signed-off-by: Chantry Xavier --- src/pacman/sync.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/pacman') diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 5f83c753..e3e87703 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -774,8 +774,19 @@ int pacman_sync(alpm_list_t *targets) /* clean the cache */ if(config->op_s_clean) { - int ret = sync_cleancache(config->op_s_clean); + int ret = 0; + + if(sync_trans_init(0) == -1) { + return(1); + } + + ret += sync_cleancache(config->op_s_clean); ret += sync_cleandb_all(); + + if(sync_trans_release() == -1) { + ret++; + } + return(ret); } -- cgit v1.2.3-70-g09d2