From 488ca2426568163721153822af8269447e481c7d Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Thu, 18 Jun 2015 01:57:38 +1000 Subject: Implement locating file owner in sync files database Equivalent to -Qo but for packages in the sync database e.g. pacman -Fo /usr/bin/pacman Signed-off-by: Allan McRae --- src/pacman/files.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/pacman/files.c b/src/pacman/files.c index 18d4c914..667e8cc7 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; } -- cgit v1.2.3-70-g09d2