[pacman-dev] [PATCH] Make sync error message smarter on unfound targets

Dan McGee dan at archlinux.org
Thu Aug 25 19:37:23 EDT 2011


We had two issues here. One is a file with an absolute path passed to -S
results in a cryptic error message due to the database name being '\0'.
The second is not realizing you should be doing -U instead of -S. Fix
both of these to transform this:

    $ sudo pacman -S /tmp/binutils-2.21.1-2-i686.pkg.tar.xz
    error: database not found:

to this:

    $ sudo pacman -S /tmp/binutils-2.21.1-2-i686.pkg.tar.xz
    error: target not found: /tmp/binutils-2.21.1-2-i686.pkg.tar.xz
    warning: '/tmp/binutils-2.21.1-2-i686.pkg.tar.xz' is a file, did you mean -U/--upgrade instead of -S/--sync?

Signed-off-by: Dan McGee <dan at archlinux.org>
---
 src/pacman/sync.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index ea32a26..a7fe5be 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -672,8 +672,6 @@ static int process_targname(alpm_list_t *dblist, const char *targname)
 	/* #FS#23342 - skip ignored packages when user says no */
 	if(alpm_errno(config->handle) == ALPM_ERR_PKG_IGNORED) {
 			pm_printf(ALPM_LOG_WARNING, _("skipping target: %s\n"), targname);
-			/* TODO how to do this, we shouldn't be fucking with it from the frontend */
-			/* pm_errno = 0; */
 			return 0;
 	}
 
@@ -693,7 +691,7 @@ static int process_target(const char *target)
 	int ret = 0;
 	alpm_list_t *dblist = NULL;
 
-	if(targname) {
+	if(targname && targname != targstring) {
 		alpm_db_t *db = NULL;
 
 		*targname = '\0';
@@ -716,6 +714,11 @@ static int process_target(const char *target)
 	}
 cleanup:
 	free(targstring);
+	if(ret && access(target, R_OK) == 0) {
+		pm_fprintf(stderr, ALPM_LOG_WARNING,
+				_("'%s' is a file, did you mean %s instead of %s?"),
+				target, "-U/--upgrade", "-S/--sync");
+	}
 	return ret;
 }
 
-- 
1.7.6



More information about the pacman-dev mailing list