summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2015-06-18 10:28:13 +0200
committerAllan McRae <allan@archlinux.org>2015-07-15 02:57:31 +0200
commitacf95f6b3b6e2bef174da51e799bd07ce9f4cfd0 (patch)
tree3fdf5782a4f2590145a8fbdcb78a1e1c20971da6
parent137a4086de310e2d31cb719806e01cd9eb414ec0 (diff)
downloadpacman-acf95f6b3b6e2bef174da51e799bd07ce9f4cfd0.tar.gz
pacman-acf95f6b3b6e2bef174da51e799bd07ce9f4cfd0.tar.xz
Implement searching for a file in the sync databases
Locates all packages that contain the listed file e.g. pacman -Fs libpng.so Signed-off-by: Allan McRae <allan@archlinux.org>
-rw-r--r--src/pacman/files.c64
1 files changed, 63 insertions, 1 deletions
diff --git a/src/pacman/files.c b/src/pacman/files.c
index 695f13d8..fc06ae7d 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -83,7 +83,69 @@ notfound:
return 0;
}
-static int files_search(alpm_list_t __attribute__((unused)) *syncs, alpm_list_t __attribute__((unused)) *targets) {
+static int files_search(alpm_list_t *syncs, alpm_list_t *targets) {
+ int ret = 0;
+ alpm_list_t *t;
+ const colstr_t *colstr = &config->colstr;
+
+ for(t = targets; t; t = alpm_list_next(t)) {
+ char *filename = NULL;
+ alpm_list_t *s;
+ int found = 0;
+
+ if((filename = strdup(t->data)) == NULL) {
+ goto notfound;
+ }
+
+ 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)) {
+ size_t f = 0;
+ char* c;
+ alpm_pkg_t *pkg = p->data;
+ alpm_filelist_t *files = alpm_pkg_get_files(pkg);
+ alpm_list_t *match = NULL;
+
+ while(f < files->count) {
+ c = strrchr(files->files[f].name, '/');
+ if(c && *(c + 1)) {
+ if(strcmp(c + 1, filename) == 0) {
+ match = alpm_list_add(match, strdup(files->files[f].name));
+ found = 1;
+ }
+ }
+ f++;
+ }
+
+ if(match != NULL) {
+ if(config->quiet) {
+ printf("%s/%s\n", alpm_db_get_name(repo), alpm_pkg_get_name(pkg));
+ } else {
+ alpm_list_t *ml;
+ printf("%s%s/%s%s %s%s%s\n", colstr->repo, alpm_db_get_name(repo),
+ colstr->title, alpm_pkg_get_name(pkg),
+ colstr->version, alpm_pkg_get_version(pkg), colstr->nocolor);
+
+ for(ml = match; ml; ml = alpm_list_next(ml)) {
+ c = ml->data;
+ printf(" %s\n", c);
+ }
+ FREELIST(match);
+ }
+ }
+ }
+ }
+ free(filename);
+
+notfound:
+ if(!found) {
+ ret++;
+ }
+ }
+
return 0;
}