[pacman-dev] [PATCH v2 2/2] src/pacman/query.c: do not exit -Qo with error if file does not exist

iff at escondida.tk iff at escondida.tk
Wed Jan 24 22:30:41 UTC 2018


From: Ivy Foster <iff at escondida.tk>

Query operations act on the local db, not the filesystem. Also, a
valid use case for -Qo is to discover what package owns a deleted file
so it can be reinstalled.

Closes FS#55856.

Signed-off-by: Ivy Foster <iff at escondida.tk>
---
This version of the patch handles both missing directories and the
missing file's parent directory *also* being missing.

 src/pacman/query.c | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/src/pacman/query.c b/src/pacman/query.c
index 91ca78a7..e4104171 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -160,7 +160,7 @@ static int query_fileowner(alpm_list_t *targets)
 		alpm_list_t *i;
 		size_t len;
 		unsigned int found = 0;
-		int is_dir;
+		int is_dir, is_missing = 0;
 
 		if((filename = strdup(t->data)) == NULL) {
 			goto targcleanup;
@@ -177,25 +177,14 @@ static int query_fileowner(alpm_list_t *targets)
 			filename[len--] = '\0';
 		}
 
-		if(lstat(filename, &buf) == -1) {
-			/* if it is not a path but a program name, then check in PATH */
-			if(strchr(filename, '/') == NULL) {
-				if(search_path(&filename, &buf) == -1) {
-					pm_printf(ALPM_LOG_ERROR, _("failed to find '%s' in PATH: %s\n"),
-							filename, strerror(errno));
-					goto targcleanup;
-				}
-			} else {
-				pm_printf(ALPM_LOG_ERROR, _("failed to read file '%s': %s\n"),
-						filename, strerror(errno));
-				goto targcleanup;
-			}
+		/* if it is not a path but a program name, then check in PATH */
+		if((lstat(filename, &buf) == -1) && (strchr(filename, '/') == NULL)) {
+			search_path(&filename, &buf);
 		}
 
 		if(!lrealpath(filename, rpath)) {
-			pm_printf(ALPM_LOG_ERROR, _("cannot determine real path for '%s': %s\n"),
-					filename, strerror(errno));
-			goto targcleanup;
+			strncpy(rpath, filename, PATH_MAX);
+			is_missing = 1;
 		}
 
 		if(strncmp(rpath, root, rootlen) != 0) {
@@ -215,7 +204,7 @@ static int query_fileowner(alpm_list_t *targets)
 			strcat(rpath + rlen, "/");
 		}
 
-		for(i = packages; i && (!found || is_dir); i = alpm_list_next(i)) {
+		for(i = packages; i && (!found || is_dir || is_missing); i = alpm_list_next(i)) {
 			if(alpm_filelist_contains(alpm_pkg_get_files(i->data), rel_path)) {
 				print_query_fileowner(rpath, i->data);
 				found = 1;
-- 
2.16.1


More information about the pacman-dev mailing list