[pacman-dev] [PATCH 09/13] Implement locating file owner in sync files database

Allan McRae allan at archlinux.org
Sat Jun 20 07:42:22 UTC 2015


Equivalent to -Qo but for packages in the sync database
e.g.  pacman -Fo /usr/bin/pacman

Signed-off-by: Allan McRae <allan at archlinux.org>
---
 src/pacman/files.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 53 insertions(+), 1 deletion(-)

diff --git a/src/pacman/files.c b/src/pacman/files.c
index 18d4c91..667e8cc 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -26,7 +26,59 @@
 #include "conf.h"
 
 
-static int files_fileowner(alpm_list_t __attribute__((unused)) *syncs, alpm_list_t __attribute__((unused)) *targets) {
+static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) {
+	int ret = 0;
+	alpm_list_t *t;
+
+	for(t = targets; t; t = alpm_list_next(t)) {
+		char *filename = NULL, *f;
+		int found = 0;
+		alpm_list_t *s;
+		size_t len;
+
+		if((filename = strdup(t->data)) == NULL) {
+			goto notfound;
+		}
+
+		len = strlen(filename);
+		f = filename;
+		while(len > 1 && f[0] == '/') {
+			f = f + 1;
+			len--;
+		}
+
+		for(s = syncs; s; s = alpm_list_next(s)) {
+			alpm_list_t *p;
+			alpm_db_t *repo = s->data;
+			alpm_list_t *packages = alpm_db_get_pkgcache(repo);
+
+			for(p = packages; p; p = alpm_list_next(p)) {
+				alpm_pkg_t *pkg = p->data;
+				alpm_filelist_t *files = alpm_pkg_get_files(pkg);
+
+				if(alpm_filelist_contains(files, f)) {
+
+					if(!config->quiet) {
+						printf(_("%s is owned by %s/%s %s\n"), filename,
+								alpm_db_get_name(repo), alpm_pkg_get_name(pkg),
+								alpm_pkg_get_version(pkg));
+					} else {
+						printf("%s/%s\n", alpm_db_get_name(repo), alpm_pkg_get_name(pkg));
+					}
+
+					found = 1;
+				}
+			}
+		}
+
+		free(filename);
+
+notfound:
+		if(!found) {
+			ret++;
+		}
+	}
+
 	return 0;
 }
 
-- 
2.4.4


More information about the pacman-dev mailing list