diff options
author | Allan McRae <allan@archlinux.org> | 2015-06-17 17:57:38 +0200 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2015-07-15 02:57:30 +0200 |
commit | 488ca2426568163721153822af8269447e481c7d (patch) | |
tree | b46d22a3fbd8744300c6cac8ccbffb249875df1c /src | |
parent | 5782b8356c9b9d2c5e21694de22b1441277574b7 (diff) | |
download | pacman-488ca2426568163721153822af8269447e481c7d.tar.gz pacman-488ca2426568163721153822af8269447e481c7d.tar.xz |
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 <allan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/pacman/files.c | 54 |
1 files changed, 53 insertions, 1 deletions
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; } |