2 * Copyright (c) 2012, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
21 #include "selection.h"
33 str2archid(Pool *pool, const char *arch)
38 id = pool_str2id(pool, arch, 0);
39 if (!id || id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH)
41 if (pool->id2arch && pool_arch2score(pool, id) == 0)
46 /* remove empty jobs from the selection */
48 selection_prune(Pool *pool, Queue *selection)
52 for (i = j = 0; i < selection->count; i += 2)
54 Id select = selection->elements[i] & SOLVER_SELECTMASK;
56 if (select == SOLVER_SOLVABLE_ALL)
58 else if (select == SOLVER_SOLVABLE_REPO)
61 Repo *repo = pool_id2repo(pool, selection->elements[i + 1]);
64 FOR_REPO_SOLVABLES(repo, p, s)
70 FOR_JOB_SELECT(p, pp, select, selection->elements[i + 1])
75 selection->elements[j] = selection->elements[i];
76 selection->elements[j + 1] = selection->elements[i + 1];
79 queue_truncate(selection, j);
84 selection_solvables_sortcmp(const void *ap, const void *bp, void *dp)
86 return *(const Id *)ap - *(const Id *)bp;
90 selection_solvables(Pool *pool, Queue *selection, Queue *pkgs)
95 for (i = 0; i < selection->count; i += 2)
97 Id select = selection->elements[i] & SOLVER_SELECTMASK;
98 Id id = selection->elements[i + 1];
99 if (select == SOLVER_SOLVABLE_ALL)
101 FOR_POOL_SOLVABLES(p)
104 if (select == SOLVER_SOLVABLE_REPO)
107 Repo *repo = pool_id2repo(pool, id);
110 FOR_REPO_SOLVABLES(repo, p, s)
114 else if (select == SOLVER_SOLVABLE)
115 queue_push(pkgs, id);
118 FOR_JOB_SELECT(p, pp, select, id)
125 solv_sort(pkgs->elements, pkgs->count, sizeof(Id), selection_solvables_sortcmp, NULL);
126 lastid = pkgs->elements[0];
127 for (i = j = 1; i < pkgs->count; i++)
128 if (pkgs->elements[i] != lastid)
129 pkgs->elements[j++] = lastid = pkgs->elements[i];
130 queue_truncate(pkgs, j);
134 selection_flatten(Pool *pool, Queue *selection)
138 if (selection->count <= 2)
140 for (i = 0; i < selection->count; i += 2)
141 if ((selection->elements[i] & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_ALL)
143 selection->elements[0] = selection->elements[i];
144 selection->elements[1] = selection->elements[i + 1];
145 queue_truncate(selection, 2);
149 selection_solvables(pool, selection, &q);
152 queue_empty(selection);
156 queue_truncate(selection, 2);
159 selection->elements[0] = SOLVER_SOLVABLE_ONE_OF;
160 selection->elements[1] = pool_queuetowhatprovides(pool, &q);
164 selection->elements[0] = SOLVER_SOLVABLE | SOLVER_NOAUTOSET;
165 selection->elements[1] = q.elements[0];
170 /* only supports simple rels plus REL_ARCH */
172 match_nevr_rel(Pool *pool, Solvable *s, Id rflags, Id revr)
174 if (rflags == REL_ARCH)
178 if (revr != ARCH_SRC || s->arch != ARCH_NOSRC)
185 return pool_intersect_evrs(pool, REL_EQ, s->evr, rflags, revr);
188 /* only supports simple rels plus REL_ARCH */
190 selection_filter_rel_noprune(Pool *pool, Queue *selection, Id relflags, Id relevr)
194 if (!selection->count)
197 for (i = 0; i < selection->count; i += 2)
199 Id select = selection->elements[i] & SOLVER_SELECTMASK;
200 Id id = selection->elements[i + 1];
201 if (select == SOLVER_SOLVABLE || select == SOLVER_SOLVABLE_ONE_OF)
203 /* done by selection_addextra, currently implies SELECTION_NAME */
209 FOR_JOB_SELECT(p, pp, select, id)
211 Solvable *s = pool->solvables + p;
212 if (match_nevr_rel(pool, s, relflags, relevr))
221 selection->elements[i] = SOLVER_SOLVABLE | SOLVER_NOAUTOSET;
222 selection->elements[i + 1] = q.elements[0];
226 selection->elements[i] = SOLVER_SOLVABLE_ONE_OF;
227 selection->elements[i + 1] = pool_queuetowhatprovides(pool, &q);
232 else if (select == SOLVER_SOLVABLE_NAME || select == SOLVER_SOLVABLE_PROVIDES)
234 /* don't stack src reldeps */
235 if (relflags == REL_ARCH && (relevr == ARCH_SRC || relevr == ARCH_NOSRC) && ISRELDEP(id))
237 Reldep *rd = GETRELDEP(pool, id);
238 if (rd->flags == REL_ARCH && rd->evr == ARCH_SRC)
241 selection->elements[i + 1] = pool_rel2id(pool, id, relevr, relflags, 1);
244 continue; /* actually cannot happen */
246 /* now add the setflags we gained */
247 if (relflags == REL_ARCH)
248 selection->elements[i] |= SOLVER_SETARCH;
249 if (relflags == REL_EQ && select != SOLVER_SOLVABLE_PROVIDES)
251 if (pool->disttype == DISTTYPE_DEB)
252 selection->elements[i] |= SOLVER_SETEVR; /* debian can't match version only like rpm */
255 const char *rel = strrchr(pool_id2str(pool, relevr), '-');
256 selection->elements[i] |= rel ? SOLVER_SETEVR : SOLVER_SETEV;
262 /* only supports simple rels plus REL_ARCH */
263 /* prunes empty jobs */
265 selection_filter_rel(Pool *pool, Queue *selection, Id relflags, Id relevr)
267 selection_filter_rel_noprune(pool, selection, relflags, relevr);
268 selection_prune(pool, selection);
271 /* limit a selection to to repository */
272 /* prunes empty jobs */
274 selection_filter_repo(Pool *pool, Queue *selection, Repo *repo, int setflags)
279 if (!selection->count)
283 queue_empty(selection);
287 for (i = j = 0; i < selection->count; i += 2)
289 Id select = selection->elements[i] & SOLVER_SELECTMASK;
290 Id id = selection->elements[i + 1];
291 if (select == SOLVER_SOLVABLE_ALL)
293 select = SOLVER_SOLVABLE_REPO;
296 else if (select == SOLVER_SOLVABLE_REPO)
298 if (id != repo->repoid)
301 else if (select == SOLVER_SOLVABLE)
303 if (pool->solvables[id].repo != repo)
311 FOR_JOB_SELECT(p, pp, select, id)
313 if (pool->solvables[p].repo != repo)
324 select = SOLVER_SOLVABLE | SOLVER_NOAUTOSET;
329 select = SOLVER_SOLVABLE_ONE_OF;
330 id = pool_queuetowhatprovides(pool, &q);
334 if (select == SOLVER_SOLVABLE_REPO)
338 FOR_REPO_SOLVABLES(repo, p, s)
341 continue; /* repo is empty */
343 selection->elements[j++] = select | (selection->elements[i] & ~SOLVER_SELECTMASK) | setflags;
344 selection->elements[j++] = id;
346 queue_truncate(selection, j);
352 matchprovides(Pool *pool, Solvable *s, Id dep)
355 idp = s->repo->idarraydata + s->provides;
356 while ((id = *idp++) != 0)
357 if (pool_match_dep(pool, id, dep))
362 /* change a SOLVER_SOLVABLE_NAME/PROVIDES selection to something that also includes
364 * extra packages are: src, badarch, disabled
367 selection_addextra(Pool *pool, Queue *selection, int flags)
371 int i, isextra, haveextra, doprovides;
373 if ((flags & SELECTION_INSTALLED_ONLY) != 0)
374 flags &= ~SELECTION_WITH_SOURCE;
376 if (!(flags & (SELECTION_WITH_SOURCE | SELECTION_WITH_DISABLED | SELECTION_WITH_BADARCH)))
377 return; /* nothing to add */
380 for (i = 0; i < selection->count; i += 2)
382 if (selection->elements[i] == SOLVER_SOLVABLE_NAME)
384 else if (selection->elements[i] == SOLVER_SOLVABLE_PROVIDES)
388 dep = selection->elements[i + 1];
393 /* first put all non-extra packages on the queue */
394 FOR_PROVIDES(p, pp, dep)
396 if ((flags & SELECTION_INSTALLED_ONLY) != 0 && pool->solvables[p].repo != pool->installed)
401 FOR_POOL_SOLVABLES(p)
403 Solvable *s = pool->solvables + p;
404 if (!doprovides && !pool_match_nevr(pool, s, dep))
406 if ((flags & SELECTION_INSTALLED_ONLY) != 0 && s->repo != pool->installed)
409 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
411 if (!(flags & SELECTION_WITH_SOURCE) && !(flags & SELECTION_SOURCE_ONLY))
413 if (!(flags & SELECTION_SOURCE_ONLY))
415 if (pool_disabled_solvable(pool, s))
417 if (!(flags & SELECTION_WITH_DISABLED))
424 if ((flags & SELECTION_SOURCE_ONLY) != 0)
426 if (s->repo != pool->installed)
428 if (pool_disabled_solvable(pool, s))
430 if (!(flags & SELECTION_WITH_DISABLED))
434 if (pool_badarch_solvable(pool, s))
436 if (!(flags & SELECTION_WITH_BADARCH))
445 continue; /* already done above in FOR_PROVIDES */
446 if (!s->provides || !matchprovides(pool, s, dep))
449 haveextra |= isextra;
452 if (!haveextra || !q.count)
456 selection->elements[i] = (selection->elements[i] & ~SOLVER_SELECTMASK) | SOLVER_SOLVABLE | SOLVER_NOAUTOSET;
457 selection->elements[i + 1] = q.elements[0];
462 solv_sort(q.elements, q.count, sizeof(Id), selection_solvables_sortcmp, NULL);
463 selection->elements[i] = (selection->elements[i] & ~SOLVER_SELECTMASK) | SOLVER_SOLVABLE_ONE_OF;
464 selection->elements[i + 1] = pool_queuetowhatprovides(pool, &q);
470 static inline const char *
471 skipkind(const char *n)
474 for (s = n; *s >= 'a' && *s <= 'z'; s++)
476 if (*s == ':' && s != n)
482 queue_pushunique2(Queue *q, Id id1, Id id2)
485 for (i = 0; i < q->count; i += 2)
486 if (q->elements[i] == id1 && q->elements[i + 1] == id2)
488 queue_push2(q, id1, id2);
492 /***** provides matching *****/
495 selection_addextra_provides(Pool *pool, Queue *selection, const char *name, int flags)
499 int doglob, nocase, globflags;
501 if ((flags & SELECTION_INSTALLED_ONLY) != 0)
502 return 0; /* neither disabled nor badarch nor src */
504 nocase = flags & SELECTION_NOCASE;
505 doglob = (flags & SELECTION_GLOB) != 0 && strpbrk(name, "[*?") != 0;
506 globflags = doglob && nocase ? FNM_CASEFOLD : 0;
508 FOR_POOL_SOLVABLES(p)
511 Solvable *s = pool->solvables + p;
514 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC) /* no provides */
516 if (s->repo == pool->installed)
518 if (pool_disabled_solvable(pool, s))
520 if (!(flags & SELECTION_WITH_DISABLED))
522 if (!(flags & SELECTION_WITH_BADARCH) && pool_badarch_solvable(pool, s))
525 else if (pool_badarch_solvable(pool, s))
527 if (!(flags & SELECTION_WITH_BADARCH))
532 /* here is an extra solvable we need to consider */
533 idp = s->repo->idarraydata + s->provides;
534 while ((id = *idp++) != 0)
538 Reldep *rd = GETRELDEP(pool, id);
541 if (pool->whatprovides[id] > 1)
542 continue; /* we already did that one in the normal code path */
543 n = pool_id2str(pool, id);
544 if ((doglob ? fnmatch(name, n, globflags) : nocase ? strcasecmp(name, n) : strcmp(name, n)) == 0)
546 queue_pushunique2(selection, SOLVER_SOLVABLE_PROVIDES, id);
554 /* this is the fast path of selection_provides: the id for the name
555 * is known and thus we can use the whatprovides data to quickly
556 * check the existance of a package with that provides */
558 selection_provides_id(Pool *pool, Queue *selection, Id id, int flags)
562 FOR_PROVIDES(p, pp, id)
564 Solvable *s = pool->solvables + p;
565 if ((flags & SELECTION_INSTALLED_ONLY) != 0 && s->repo != pool->installed)
567 queue_push2(selection, SOLVER_SOLVABLE_PROVIDES, id);
568 return SELECTION_PROVIDES;
571 if ((flags & (SELECTION_WITH_BADARCH | SELECTION_WITH_DISABLED)) != 0)
573 /* misuse selection_addextra to test if there is an extra package
574 * that provides the id */
575 queue_push2(selection, SOLVER_SOLVABLE_PROVIDES, id);
576 selection_addextra(pool, selection, flags);
577 if (selection->elements[0] == SOLVER_SOLVABLE_PROVIDES)
578 queue_empty(selection); /* no extra package found */
581 selection->elements[0] = SOLVER_SOLVABLE_PROVIDES;
582 selection->elements[1] = id;
584 return selection->count ? SELECTION_PROVIDES : 0;
590 /* match the provides of a package */
591 /* note that we only return raw SOLVER_SOLVABLE_PROVIDES jobs
592 * so that the selection can be modified later. */
594 selection_provides(Pool *pool, Queue *selection, const char *name, int flags)
603 if ((flags & SELECTION_SOURCE_ONLY) != 0)
604 return 0; /* sources do not have provides */
606 nocase = flags & SELECTION_NOCASE;
609 /* try the fast path first */
610 id = pool_str2id(pool, name, 0);
613 /* the id is known, do the fast id matching */
614 int ret = selection_provides_id(pool, selection, id, flags);
620 doglob = (flags & SELECTION_GLOB) != 0 && strpbrk(name, "[*?") != 0;
621 if (!nocase && !doglob)
623 /* all done above in selection_provides_id */
627 /* looks like a glob or nocase match. really hard work. */
629 globflags = doglob && nocase ? FNM_CASEFOLD : 0;
630 for (id = 1; id < pool->ss.nstrings; id++)
632 /* do we habe packages providing this id? */
633 if ((!pool->whatprovides[id] && pool->addedfileprovides == 2) || pool->whatprovides[id] == 1)
635 n = pool_id2str(pool, id);
636 if ((doglob ? fnmatch(name, n, globflags) : nocase ? strcasecmp(name, n) : strcmp(name, n)) == 0)
638 if ((flags & SELECTION_INSTALLED_ONLY) != 0)
640 FOR_PROVIDES(p, pp, id)
641 if (pool->solvables[p].repo == pool->installed)
646 else if (!pool->whatprovides[id])
648 FOR_PROVIDES(p, pp, id)
653 queue_push2(selection, SOLVER_SOLVABLE_PROVIDES, id);
658 if (flags & (SELECTION_WITH_BADARCH | SELECTION_WITH_DISABLED))
659 match |= selection_addextra_provides(pool, selection, name, flags);
661 return match ? SELECTION_PROVIDES : 0;
664 /***** name matching *****/
666 /* this is the fast path of selection_name: the id for the name
667 * is known and thus we can quickly check the existance of a
668 * package with that name */
670 selection_name_id(Pool *pool, Queue *selection, Id id, int flags)
675 if ((flags & SELECTION_SOURCE_ONLY) != 0)
677 /* sources cannot be installed */
678 if ((flags & SELECTION_INSTALLED_ONLY) != 0)
680 /* add ARCH_SRC to match only sources */
681 matchid = pool_rel2id(pool, id, ARCH_SRC, REL_ARCH, 1);
682 flags &= ~SELECTION_WITH_SOURCE;
685 FOR_PROVIDES(p, pp, matchid)
687 Solvable *s = pool->solvables + p;
690 if ((flags & SELECTION_INSTALLED_ONLY) != 0 && s->repo != pool->installed)
692 /* one match is all we need */
693 queue_push2(selection, SOLVER_SOLVABLE_NAME, matchid);
694 /* add the requested extra packages */
695 if ((flags & (SELECTION_WITH_SOURCE | SELECTION_WITH_BADARCH | SELECTION_WITH_DISABLED)) != 0)
696 selection_addextra(pool, selection, flags);
697 return SELECTION_NAME;
700 if ((flags & (SELECTION_WITH_BADARCH | SELECTION_WITH_DISABLED)) != 0)
702 queue_push2(selection, SOLVER_SOLVABLE_NAME, matchid);
703 selection_addextra(pool, selection, flags);
704 if (selection->elements[0] == SOLVER_SOLVABLE_NAME)
705 queue_empty(selection);
706 return selection->count ? SELECTION_NAME : 0;
709 if ((flags & SELECTION_WITH_SOURCE) != 0 && (flags & SELECTION_INSTALLED_ONLY) == 0)
711 /* WITH_SOURCE case, but we had no match. try SOURCE_ONLY instead */
712 matchid = pool_rel2id(pool, id, ARCH_SRC, REL_ARCH, 1);
713 FOR_PROVIDES(p, pp, matchid)
715 Solvable *s = pool->solvables + p;
718 queue_push2(selection, SOLVER_SOLVABLE_NAME, matchid);
719 return SELECTION_NAME;
725 /* does not check SELECTION_INSTALLED_ONLY, as it is normally done
728 solvable_matches_selection_flags(Pool *pool, Solvable *s, int flags)
730 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
732 if (!(flags & SELECTION_SOURCE_ONLY) && !(flags & SELECTION_WITH_SOURCE))
734 /* source package are never installed and never have a bad arch */
735 if (!(flags & SELECTION_WITH_DISABLED) && pool_disabled_solvable(pool, s))
740 if ((flags & SELECTION_SOURCE_ONLY) != 0)
742 if (s->repo != pool->installed)
744 if (!(flags & SELECTION_WITH_DISABLED) && pool_disabled_solvable(pool, s))
746 if (!(flags & SELECTION_WITH_BADARCH) && pool_badarch_solvable(pool, s))
753 /* match the name of a package */
754 /* note that for SELECTION_INSTALLED_ONLY the result is not trimmed */
756 selection_name(Pool *pool, Queue *selection, const char *name, int flags)
764 if ((flags & SELECTION_SOURCE_ONLY) != 0)
765 flags &= ~SELECTION_WITH_SOURCE;
767 nocase = flags & SELECTION_NOCASE;
768 if (!nocase && !(flags & SELECTION_SKIP_KIND))
770 /* try the fast path first */
771 id = pool_str2id(pool, name, 0);
774 int ret = selection_name_id(pool, selection, id, flags);
780 doglob = (flags & SELECTION_GLOB) != 0 && strpbrk(name, "[*?") != 0;
781 if (!nocase && !(flags & SELECTION_SKIP_KIND) && !doglob)
782 return 0; /* all done above in selection_name_id */
784 /* do a name match over all packages. hard work. */
786 globflags = doglob && nocase ? FNM_CASEFOLD : 0;
787 FOR_POOL_SOLVABLES(p)
789 Solvable *s = pool->solvables + p;
790 if ((flags & SELECTION_INSTALLED_ONLY) != 0 && s->repo != pool->installed)
792 if (!solvable_matches_selection_flags(pool, s, flags))
795 n = pool_id2str(pool, id);
796 if (flags & SELECTION_SKIP_KIND)
798 if ((doglob ? fnmatch(name, n, globflags) : nocase ? strcasecmp(name, n) : strcmp(name, n)) == 0)
800 if ((flags & SELECTION_SOURCE_ONLY) != 0)
802 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
804 id = pool_rel2id(pool, id, ARCH_SRC, REL_ARCH, 1);
806 queue_pushunique2(selection, SOLVER_SOLVABLE_NAME, id);
812 /* if there was a match widen the selector to include all extra packages */
813 if ((flags & (SELECTION_WITH_SOURCE | SELECTION_WITH_BADARCH | SELECTION_WITH_DISABLED)) != 0)
814 selection_addextra(pool, selection, flags);
815 return SELECTION_NAME;
821 /***** SELECTION_DOTARCH and SELECTION_REL handling *****/
823 /* like selection_name, but check for a .arch suffix if the match did
824 not work and SELECTION_DOTARCH is used */
826 selection_name_arch(Pool *pool, Queue *selection, const char *name, int flags, int doprovides, int noprune)
833 ret = selection_provides(pool, selection, name, flags);
835 ret = selection_name(pool, selection, name, flags);
838 if (!(flags & SELECTION_DOTARCH))
840 /* check if there is an .arch suffix */
841 if ((r = strrchr(name, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
843 char *rname = solv_strdup(name);
845 if (archid == ARCH_SRC || archid == ARCH_NOSRC)
846 flags |= SELECTION_SOURCE_ONLY;
848 ret = selection_provides(pool, selection, rname, flags);
850 ret = selection_name(pool, selection, rname, flags);
853 selection_filter_rel_noprune(pool, selection, REL_ARCH, archid);
855 selection_prune(pool, selection);
858 return ret && selection->count ? ret | SELECTION_DOTARCH : 0;
864 splitrel(char *rname, char *r, int *rflagsp)
866 int nend = r - rname;
868 if (nend && *r == '=' && r[-1] == '!')
872 rflags = REL_LT|REL_GT;
885 while (*r && (*r == ' ' || *r == '\t'))
887 while (nend && (rname[nend - 1] == ' ' || rname[nend - 1] == '\t'))
889 if (nend <= 0 || !*r || !rflags)
896 /* match name/provides, support DOTARCH and REL modifiers
899 selection_name_arch_rel(Pool *pool, Queue *selection, const char *name, int flags, int doprovides)
901 int ret, rflags = 0, noprune;
902 char *r = 0, *rname = 0;
904 /* try to split off an relation part */
905 if ((flags & SELECTION_REL) != 0)
907 if ((r = strpbrk(name, "<=>")) != 0)
909 rname = solv_strdup(name);
910 r = rname + (r - name);
911 if ((r = splitrel(rname, r, &rflags)) == 0)
912 rname = solv_free(rname);
916 /* check if we need to call selection_addextra */
917 noprune = doprovides && (flags & (SELECTION_WITH_DISABLED | SELECTION_WITH_BADARCH));
921 /* could not split off relation */
922 ret = selection_name_arch(pool, selection, name, flags, doprovides, noprune);
925 selection_addextra(pool, selection, flags);
926 selection_prune(pool, selection);
928 return ret && selection->count ? ret : 0;
931 /* we could split of a relation. prune name and then filter rel */
932 ret = selection_name_arch(pool, selection, rname, flags, doprovides, noprune);
935 selection_filter_rel_noprune(pool, selection, rflags, pool_str2id(pool, r, 1));
937 selection_addextra(pool, selection, flags);
938 selection_prune(pool, selection);
941 return ret && selection->count ? ret | SELECTION_REL : 0;
944 /***** filelist matching *****/
947 selection_filelist_sortcmp(const void *ap, const void *bp, void *dp)
950 const Id *a = ap, *b = bp;
952 return strcmp(pool_id2str(pool, a[0]), pool_id2str(pool, b[0]));
957 selection_filelist(Pool *pool, Queue *selection, const char *name, int flags)
965 /* all files in the file list start with a '/' */
968 if (!(flags & SELECTION_GLOB))
970 if (*name != '*' && *name != '[' && *name != '?')
973 type = !(flags & SELECTION_GLOB) || strpbrk(name, "[*?") == 0 ? SEARCH_STRING : SEARCH_GLOB;
974 if ((flags & SELECTION_NOCASE) != 0)
975 type |= SEARCH_NOCASE;
977 dataiterator_init(&di, pool, flags & SELECTION_INSTALLED_ONLY ? pool->installed : 0, 0, SOLVABLE_FILELIST, name, type|SEARCH_FILES);
978 while (dataiterator_step(&di))
980 Solvable *s = pool->solvables + di.solvid;
983 if (!solvable_matches_selection_flags(pool, s, flags))
985 if ((flags & SELECTION_FLAT) != 0)
987 /* don't bother with the complex stuff */
988 queue_push2(selection, SOLVER_SOLVABLE | SOLVER_NOAUTOSET, di.solvid);
989 dataiterator_skip_solvable(&di);
992 id = pool_str2id(pool, di.kv.str, 1);
993 queue_push2(&q, id, di.solvid);
995 dataiterator_free(&di);
996 if ((flags & SELECTION_FLAT) != 0)
999 return selection->count ? SELECTION_FILELIST : 0;
1006 solv_sort(q.elements, q.count / 2, 2 * sizeof(Id), selection_filelist_sortcmp, pool);
1008 queue_push2(&q, 0, 0);
1009 for (i = j = 0; i < q.count; i += 2)
1011 if (q.elements[i] != lastid)
1014 queue_pushunique2(selection, SOLVER_SOLVABLE | SOLVER_NOAUTOSET, q.elements[0]);
1019 /* check if we already have it */
1020 for (k = 0; k < selection->count; k += 2)
1022 if (selection->elements[k] != SOLVER_SOLVABLE_ONE_OF)
1024 idp = pool->whatprovidesdata + selection->elements[k + 1];
1025 if (!memcmp(idp, q.elements, j * sizeof(Id)) && !idp[j])
1028 if (k == selection->count)
1029 queue_push2(selection, SOLVER_SOLVABLE_ONE_OF, pool_ids2whatprovides(pool, q.elements, j));
1031 lastid = q.elements[i];
1034 if (!j || q.elements[j - 1] != q.elements[i])
1035 q.elements[j++] = q.elements[i + 1];
1038 return SELECTION_FILELIST;
1042 /***** canon name matching *****/
1044 #if defined(MULTI_SEMANTICS)
1045 # define EVRCMP_DEPCMP (pool->disttype == DISTTYPE_DEB ? EVRCMP_COMPARE : EVRCMP_MATCH_RELEASE)
1046 #elif defined(DEBIAN)
1047 # define EVRCMP_DEPCMP EVRCMP_COMPARE
1049 # define EVRCMP_DEPCMP EVRCMP_MATCH_RELEASE
1052 /* magic epoch promotion code, works only for SELECTION_NAME selections */
1054 selection_filter_evr(Pool *pool, Queue *selection, const char *evr)
1061 /* do we already have an epoch? */
1062 for (sp = evr; *sp >= '0' && *sp <= '9'; sp++)
1064 if (*sp == ':' && sp != evr)
1066 /* yes, just add the rel filter */
1067 selection_filter_rel(pool, selection, REL_EQ, pool_str2id(pool, evr, 1));
1072 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
1073 for (i = j = 0; i < selection->count; i += 2)
1075 Id select = selection->elements[i] & SOLVER_SELECTMASK;
1076 Id id = selection->elements[i + 1];
1078 const char *lastepoch = 0;
1079 int lastepochlen = 0;
1082 FOR_JOB_SELECT(p, pp, select, id)
1084 Solvable *s = pool->solvables + p;
1085 const char *sevr = pool_id2str(pool, s->evr);
1086 for (sp = sevr; *sp >= '0' && *sp <= '9'; sp++)
1090 /* compare vr part */
1091 if (strcmp(evr, sp != sevr ? sp + 1 : sevr) != 0)
1093 int r = pool_evrcmp_str(pool, sp != sevr ? sp + 1 : sevr, evr, EVRCMP_DEPCMP);
1094 if (r == -1 || r == 1)
1095 continue; /* solvable does not match vr */
1100 while (sevr < sp && *sevr == '0') /* normalize epoch */
1106 lastepochlen = sp - sevr;
1108 else if (lastepochlen != sp - sevr || strncmp(lastepoch, sevr, lastepochlen) != 0)
1109 lastepochlen = -1; /* multiple different epochs */
1111 if (!lastepoch || lastepochlen == 0)
1112 id = pool_str2id(pool, evr, 1); /* no match at all or zero epoch */
1113 else if (lastepochlen >= 0)
1115 /* found exactly one epoch, simply prepend */
1116 char *evrx = solv_malloc(strlen(evr) + lastepochlen + 2);
1117 strncpy(evrx, lastepoch, lastepochlen + 1);
1118 strcpy(evrx + lastepochlen + 1, evr);
1119 id = pool_str2id(pool, evrx, 1);
1124 /* multiple epochs in multiple solvables, convert to list of solvables */
1125 selection->elements[j] = (selection->elements[i] & ~SOLVER_SELECTMASK) | SOLVER_SOLVABLE_ONE_OF;
1126 selection->elements[j + 1] = pool_queuetowhatprovides(pool, &q);
1131 queue_push2(&q, selection->elements[i], selection->elements[i + 1]);
1132 selection_filter_rel(pool, &q, REL_EQ, id);
1134 continue; /* oops, no match */
1135 selection->elements[j] = q.elements[0];
1136 selection->elements[j + 1] = q.elements[1];
1139 queue_truncate(selection, j);
1143 /* match the "canonical" name of the package */
1145 selection_canon(Pool *pool, Queue *selection, const char *name, int flags)
1147 char *rname, *r, *r2;
1153 * nameglob-version.arch
1154 * nameglob-version-release
1155 * nameglob-version-release.arch
1157 flags |= SELECTION_NAME;
1158 flags &= ~SELECTION_PROVIDES;
1161 if (pool->disttype == DISTTYPE_CONDA)
1163 Id *wp, id = pool_conda_matchspec(pool, name);
1166 wp = pool_whatprovides_ptr(pool, id); /* check if there is a match */
1169 queue_push2(selection, SOLVER_SOLVABLE_PROVIDES, id);
1170 return SELECTION_CANON;
1173 if (pool->disttype == DISTTYPE_DEB)
1175 if ((r = strchr(name, '_')) == 0)
1177 rname = solv_strdup(name); /* so we can modify it */
1178 r = rname + (r - name);
1180 if ((ret = selection_name(pool, selection, rname, flags)) == 0)
1185 /* is there a vaild arch? */
1186 if ((r2 = strrchr(r, '_')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
1188 *r2 = 0; /* split off */
1189 selection_filter_rel(pool, selection, REL_ARCH, archid);
1191 selection_filter_rel(pool, selection, REL_EQ, pool_str2id(pool, r, 1));
1193 return selection->count ? ret | SELECTION_CANON : 0;
1196 if (pool->disttype == DISTTYPE_HAIKU)
1198 if ((r = strchr(name, '-')) == 0)
1200 rname = solv_strdup(name); /* so we can modify it */
1201 r = rname + (r - name);
1203 if ((ret = selection_name(pool, selection, rname, flags)) == 0)
1208 /* is there a vaild arch? */
1209 if ((r2 = strrchr(r, '-')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
1211 *r2 = 0; /* split off */
1212 selection_filter_rel(pool, selection, REL_ARCH, archid);
1214 selection_filter_rel(pool, selection, REL_EQ, pool_str2id(pool, r, 1));
1216 return selection->count ? ret | SELECTION_CANON : 0;
1219 if ((r = strrchr(name, '-')) == 0)
1221 rname = solv_strdup(name); /* so we can modify it */
1222 r = rname + (r - name);
1225 /* split off potential arch part from version */
1226 if ((r2 = strrchr(r + 1, '.')) != 0 && r2[1] && (archid = str2archid(pool, r2 + 1)) != 0)
1227 *r2 = 0; /* found valid arch, split it off */
1228 if (archid == ARCH_SRC || archid == ARCH_NOSRC)
1229 flags |= SELECTION_SOURCE_ONLY;
1231 /* try with just the version */
1232 if ((ret = selection_name(pool, selection, rname, flags)) == 0)
1234 /* no luck, try with version-release */
1235 if ((r2 = strrchr(rname, '-')) == 0)
1243 if ((ret = selection_name(pool, selection, rname, flags)) == 0)
1250 selection_filter_rel(pool, selection, REL_ARCH, archid);
1251 selection_filter_evr(pool, selection, r + 1); /* magic epoch promotion */
1253 return selection->count ? ret | SELECTION_CANON : 0;
1256 /* return the needed withbits to match the provided selection */
1258 selection_extrabits(Pool *pool, Queue *selection, int flags)
1260 int i, needflags, isextra;
1266 allflags = flags & (SELECTION_WITH_SOURCE | SELECTION_WITH_DISABLED | SELECTION_WITH_BADARCH);
1267 if (!selection->count)
1269 if (selection->count == 2 && selection->elements[0] == SOLVER_SOLVABLE_ALL)
1270 return allflags; /* don't bother */
1271 queue_init(&qlimit);
1272 selection_solvables(pool, selection, &qlimit);
1274 for (i = 0; i < qlimit.count; i++)
1276 p = qlimit.elements[i];
1277 s = pool->solvables + p;
1278 if ((flags & SELECTION_INSTALLED_ONLY) != 0 && s->repo != pool->installed)
1281 if (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
1283 if (!(flags & SELECTION_WITH_SOURCE))
1285 isextra |= SELECTION_WITH_SOURCE;
1286 if (pool_disabled_solvable(pool, s))
1288 if (!(flags & SELECTION_WITH_DISABLED))
1290 isextra |= SELECTION_WITH_DISABLED;
1295 if ((flags & SELECTION_SOURCE_ONLY) != 0)
1297 if (s->repo != pool->installed)
1299 if (pool_disabled_solvable(pool, s))
1301 if (!(flags & SELECTION_WITH_DISABLED))
1303 isextra |= SELECTION_WITH_DISABLED;
1305 if (pool_badarch_solvable(pool, s))
1307 if (!(flags & SELECTION_WITH_BADARCH))
1309 isextra |= SELECTION_WITH_BADARCH;
1315 needflags |= isextra;
1316 if (needflags == allflags)
1320 queue_free(&qlimit);
1325 selection_combine(Pool *pool, Queue *sel1, Queue *sel2, int flags, int ret)
1327 if ((flags & SELECTION_MODEBITS) == SELECTION_ADD)
1328 selection_add(pool, sel1, sel2);
1329 else if ((flags & SELECTION_MODEBITS) == SELECTION_SUBTRACT)
1330 selection_subtract(pool, sel1, sel2);
1331 else if ((flags & SELECTION_MODEBITS) == SELECTION_FILTER)
1333 if (ret || !(flags & SELECTION_FILTER_KEEP_IFEMPTY))
1335 if ((flags & SELECTION_FILTER_SWAPPED) != 0)
1337 selection_filter(pool, sel2, sel1);
1339 queue_init_clone(sel1, sel2);
1342 selection_filter(pool, sel1, sel2);
1345 else /* SELECTION_REPLACE */
1348 queue_init_clone(sel1, sel2);
1355 selection_make(Pool *pool, Queue *selection, const char *name, int flags)
1358 if ((flags & SELECTION_MODEBITS) != SELECTION_REPLACE)
1362 if ((flags & SELECTION_MODEBITS) == SELECTION_SUBTRACT || (flags & SELECTION_MODEBITS) == SELECTION_FILTER)
1364 if (!selection->count)
1366 if ((flags & (SELECTION_WITH_DISABLED | SELECTION_WITH_BADARCH | SELECTION_WITH_SOURCE)) != 0)
1368 /* try to drop expensive extra bits */
1369 flags = (flags & ~(SELECTION_WITH_DISABLED | SELECTION_WITH_BADARCH | SELECTION_WITH_SOURCE)) | selection_extrabits(pool, selection, flags);
1373 ret = selection_make(pool, &q, name, flags & ~SELECTION_MODEBITS);
1374 return selection_combine(pool, selection, &q, flags, ret);
1376 queue_empty(selection);
1377 if ((flags & SELECTION_INSTALLED_ONLY) != 0 && !pool->installed)
1380 /* here come our four selection modes */
1381 if ((flags & SELECTION_FILELIST) != 0)
1382 ret = selection_filelist(pool, selection, name, flags);
1383 if (!ret && (flags & SELECTION_NAME) != 0)
1384 ret = selection_name_arch_rel(pool, selection, name, flags, 0);
1385 if (!ret && (flags & SELECTION_PROVIDES) != 0)
1386 ret = selection_name_arch_rel(pool, selection, name, flags, 1);
1387 if (!ret && (flags & SELECTION_CANON) != 0)
1388 ret = selection_canon(pool, selection, name, flags);
1390 /* now do result filtering */
1391 if (ret && (flags & SELECTION_INSTALLED_ONLY) != 0)
1392 selection_filter_repo(pool, selection, pool->installed, SOLVER_SETREPO);
1394 /* flatten if requested */
1395 if (ret && (flags & SELECTION_FLAT) != 0)
1396 selection_flatten(pool, selection);
1397 return selection->count ? ret : 0;
1401 matchdep_str(const char *pattern, const char *string, int flags)
1403 if (!pattern || !string)
1405 if (flags & SELECTION_GLOB)
1407 int globflags = (flags & SELECTION_NOCASE) != 0 ? FNM_CASEFOLD : 0;
1408 return fnmatch(pattern, string, globflags) == 0 ? 1 : 0;
1410 if (flags & SELECTION_NOCASE)
1411 return strcasecmp(pattern, string) == 0 ? 1 : 0;
1412 return strcmp(pattern, string) == 0 ? 1 : 0;
1415 /* like pool_match_dep but uses matchdep_str to match the name for glob and nocase matching */
1417 matchdep(Pool *pool, Id id, char *rname, int rflags, Id revr, int flags)
1421 Reldep *rd = GETRELDEP(pool, id);
1424 if (rd->flags == REL_AND || rd->flags == REL_OR || rd->flags == REL_WITH || rd->flags == REL_WITHOUT || rd->flags == REL_COND || rd->flags == REL_UNLESS)
1426 if (matchdep(pool, rd->name, rname, rflags, revr, flags))
1428 if ((rd->flags == REL_COND || rd->flags == REL_UNLESS) && ISRELDEP(rd->evr))
1430 rd = GETRELDEP(pool, rd->evr);
1431 if (rd->flags != REL_ELSE)
1434 if (rd->flags != REL_COND && rd->flags != REL_UNLESS && rd->flags != REL_WITHOUT && matchdep(pool, rd->evr, rname, rflags, revr, flags))
1438 if (rd->flags == REL_ARCH)
1439 return matchdep(pool, rd->name, rname, rflags, revr, flags);
1441 if (!matchdep(pool, rd->name, rname, rflags, revr, flags))
1443 if (rflags && !pool_intersect_evrs(pool, rd->flags, rd->evr, rflags, revr))
1447 return matchdep_str(rname, pool_id2str(pool, id), flags);
1451 int start; /* either 2 or repofilter->start */
1452 int end; /* either nsolvables or repofilter->end */
1460 selection_make_matchsolvable_common(Pool *pool, Queue *selection, Queue *solvidq, Id solvid, int flags, int keyname, int marker, struct limiter *limiter)
1468 if ((flags & SELECTION_MODEBITS) != SELECTION_REPLACE)
1473 ret = selection_make_matchsolvable_common(pool, &q, solvidq, solvid, flags & ~SELECTION_MODEBITS, keyname, marker, limiter);
1474 return selection_combine(pool, selection, &q, flags, ret);
1477 queue_empty(selection);
1480 if (!solvidq && !solvid)
1482 if (solvidq && solvid)
1487 map_init(&m, pool->nsolvables);
1488 for (i = 0; i < solvidq->count; i++)
1489 MAPSET(&m, solvidq->elements[i]);
1492 reloff = pool->ss.nstrings;
1493 map_init(&missc, reloff + pool->nrels);
1494 for (li = limiter->start; li < limiter->end; li++)
1497 p = limiter->mapper ? limiter->mapper[li] : li;
1498 if (solvidq && MAPTST(&m, p))
1500 if (!solvidq && p == solvid)
1502 s = pool->solvables + p;
1503 if (!s->repo || (limiter->repofilter && s->repo != limiter->repofilter))
1505 if (!solvable_matches_selection_flags(pool, s, flags))
1507 if (solvable_matchessolvable_int(s, keyname, marker, solvid, solvidq ? &m : 0, &q, &missc, reloff, 0))
1508 queue_push(selection, p);
1515 /* convert package list to selection */
1516 if (!selection->count)
1518 j = selection->count;
1519 queue_insertn(selection, 0, selection->count, 0);
1520 for (i = 0; i < selection->count; i += 2)
1522 selection->elements[i] = SOLVER_SOLVABLE | SOLVER_NOAUTOSET;
1523 selection->elements[i + 1] = selection->elements[j++];
1525 if ((flags & SELECTION_FLAT) != 0)
1526 selection_flatten(pool, selection);
1527 return SELECTION_PROVIDES;
1531 selection_make_matchdeps_common(Pool *pool, Queue *selection, const char *name, Id dep, int flags, int keyname, int marker, struct limiter *limiter)
1535 char *rname = 0, *r = 0;
1541 if ((flags & SELECTION_MODEBITS) != SELECTION_REPLACE)
1545 ret = selection_make_matchdeps_common(pool, &q, name, dep, flags & ~SELECTION_MODEBITS, keyname, marker, limiter);
1546 return selection_combine(pool, selection, &q, flags, ret);
1549 queue_empty(selection);
1557 if ((flags & SELECTION_MATCH_DEPSTR) != 0)
1558 flags &= ~SELECTION_REL;
1562 rname = solv_strdup(name);
1563 if ((flags & SELECTION_REL) != 0)
1565 if ((r = strpbrk(rname, "<=>")) != 0)
1567 if ((r = splitrel(rname, r, &rflags)) == 0)
1573 revr = pool_str2id(pool, r, 1);
1574 ret |= SELECTION_REL;
1576 if ((flags & SELECTION_GLOB) != 0 && strpbrk(rname, "[*?") == 0)
1577 flags &= ~SELECTION_GLOB;
1579 if ((flags & SELECTION_GLOB) == 0 && (flags & SELECTION_NOCASE) == 0 && (flags & SELECTION_MATCH_DEPSTR) == 0)
1581 /* we can use the faster selection_make_matchdepid */
1582 dep = pool_str2id(pool, rname, 1);
1584 dep = pool_rel2id(pool, dep, revr, rflags, 1);
1585 rname = solv_free(rname);
1591 if (keyname == SOLVABLE_NAME && (flags & SELECTION_MATCH_DEPSTR) != 0)
1596 rd = GETRELDEP(pool, dep);
1597 if (!rd->name || rd->flags != REL_EQ)
1606 for (li = limiter->start; li < limiter->end; li++)
1609 p = limiter->mapper ? limiter->mapper[li] : li;
1610 s = pool->solvables + p;
1611 if (!s->repo || (limiter->repofilter && s->repo != limiter->repofilter))
1613 if (!solvable_matches_selection_flags(pool, s, flags))
1615 if (keyname == SOLVABLE_NAME) /* nevr match hack */
1619 if ((flags & SELECTION_MATCH_DEPSTR) != 0)
1621 if (s->name != dep || s->evr != revr)
1626 if (!pool_match_nevr(pool, s, dep))
1632 if ((flags & SELECTION_MATCH_DEPSTR) != 0) /* mis-use */
1634 char *tmp = pool_tmpjoin(pool, pool_id2str(pool, s->name), " = ", pool_id2str(pool, s->evr));
1635 if (!matchdep_str(rname, tmp, flags))
1640 if (!matchdep(pool, s->name, rname, rflags, revr, flags))
1642 if (rflags && !pool_intersect_evrs(pool, rflags, revr, REL_EQ, s->evr))
1646 queue_push(selection, p);
1651 repo_lookup_deparray(s->repo, p, keyname, &q, marker);
1656 if ((flags & SELECTION_MATCH_DEPSTR) != 0) /* mis-use */
1658 for (i = 0; i < q.count; i++)
1659 if (q.elements[i] == dep)
1664 for (i = 0; i < q.count; i++)
1665 if (pool_match_dep(pool, q.elements[i], dep))
1671 if ((flags & SELECTION_MATCH_DEPSTR) != 0)
1673 for (i = 0; i < q.count; i++)
1674 if (matchdep_str(rname, pool_dep2str(pool, q.elements[i]), flags))
1679 for (i = 0; i < q.count; i++)
1680 if (matchdep(pool, q.elements[i], rname, rflags, revr, flags))
1685 queue_push(selection, p);
1690 /* convert package list to selection */
1691 if (!selection->count)
1693 j = selection->count;
1694 queue_insertn(selection, 0, selection->count, 0);
1695 for (i = 0; i < selection->count; i += 2)
1697 selection->elements[i] = SOLVER_SOLVABLE | SOLVER_NOAUTOSET;
1698 selection->elements[i + 1] = selection->elements[j++];
1701 if ((flags & SELECTION_FLAT) != 0)
1702 selection_flatten(pool, selection);
1703 return ret | (keyname == SOLVABLE_NAME ? SELECTION_NAME : SELECTION_PROVIDES);
1707 setup_limiter(Pool *pool, Queue *selection, int flags, struct limiter *limiter)
1710 limiter->end = pool->nsolvables;
1711 limiter->mapper = 0;
1712 limiter->repofilter = 0;
1713 if ((flags & SELECTION_INSTALLED_ONLY) != 0)
1715 Repo *repo = pool->installed;
1716 limiter->repofilter = repo;
1717 limiter->start = repo ? repo->start : 0;
1718 limiter->end = repo ? repo->end : 0;
1720 if ((flags & SELECTION_MODEBITS) != SELECTION_SUBTRACT && (flags & SELECTION_MODEBITS) != SELECTION_FILTER)
1722 /* the result will be limited to the first selection */
1723 if (!selection->count)
1724 limiter->start = limiter->end = 0;
1727 /* check for special cases where we do not need to call selection_solvables() */
1728 if (selection->count == 2 && (selection->elements[0] & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_ALL)
1730 if (selection->count == 2 && (selection->elements[0] & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_REPO)
1732 Repo *repo = pool_id2repo(pool, selection->elements[1]);
1733 if (limiter->repofilter && repo != limiter->repofilter)
1735 limiter->repofilter = repo;
1736 limiter->start = repo ? repo->start : 0;
1737 limiter->end = repo ? repo->end : 0;
1740 /* convert selection into a package list and use it in the limiter */
1741 queue_init(&limiter->qlimit);
1742 selection_solvables(pool, selection, &limiter->qlimit);
1744 limiter->end = limiter->qlimit.count;
1745 if (!limiter->qlimit.count)
1746 queue_free(&limiter->qlimit);
1748 limiter->mapper = limiter->qlimit.elements;
1752 free_limiter(struct limiter *limiter)
1754 if (limiter->mapper)
1755 queue_free(&limiter->qlimit);
1759 * select against the dependencies in keyname
1760 * like SELECTION_PROVIDES, but with the deps in keyname instead of provides.
1761 * supported match modifiers:
1767 selection_make_matchdeps(Pool *pool, Queue *selection, const char *name, int flags, int keyname, int marker)
1769 struct limiter limiter;
1771 setup_limiter(pool, selection, flags, &limiter);
1772 ret = selection_make_matchdeps_common(pool, selection, name, 0, flags, keyname, marker, &limiter);
1773 free_limiter(&limiter);
1778 * select against the dependency id in keyname
1781 selection_make_matchdepid(Pool *pool, Queue *selection, Id dep, int flags, int keyname, int marker)
1783 struct limiter limiter;
1785 setup_limiter(pool, selection, flags, &limiter);
1786 ret = selection_make_matchdeps_common(pool, selection, 0, dep, flags, keyname, marker, &limiter);
1787 free_limiter(&limiter);
1792 selection_make_matchsolvable(Pool *pool, Queue *selection, Id solvid, int flags, int keyname, int marker)
1794 struct limiter limiter;
1796 setup_limiter(pool, selection, flags, &limiter);
1797 ret = selection_make_matchsolvable_common(pool, selection, 0, solvid, flags, keyname, marker, &limiter);
1798 free_limiter(&limiter);
1803 selection_make_matchsolvablelist(Pool *pool, Queue *selection, Queue *solvidq, int flags, int keyname, int marker)
1805 struct limiter limiter;
1807 setup_limiter(pool, selection, flags, &limiter);
1808 ret = selection_make_matchsolvable_common(pool, selection, solvidq, 0, flags, keyname, marker, &limiter);
1809 free_limiter(&limiter);
1814 pool_is_kind(Pool *pool, Id name, Id kind)
1819 n = pool_id2str(pool, name);
1822 const char *kn = pool_id2str(pool, kind);
1823 int knl = strlen(kn);
1824 return !strncmp(n, kn, knl) && n[knl] == ':' ? 1 : 0;
1830 while(*n >= 'a' && *n <= 'z')
1832 return *n == ':' ? 0 : 1;
1837 selection_filter_map(Pool *pool, Queue *sel, Map *m, int setflags)
1844 for (i = j = 0; i < sel->count; i += 2)
1846 Id select = sel->elements[i] & SOLVER_SELECTMASK;
1847 Id id = sel->elements[i + 1];
1851 if (select == SOLVER_SOLVABLE_ALL)
1853 FOR_POOL_SOLVABLES(p)
1861 else if (select == SOLVER_SOLVABLE_REPO)
1864 Repo *repo = pool_id2repo(pool, id);
1867 FOR_REPO_SOLVABLES(repo, p, s)
1876 else if (select == SOLVER_SOLVABLE)
1878 if (!map_tst(m, id))
1880 sel->elements[j] = sel->elements[i] | setflags;
1881 sel->elements[j + 1] = id;
1887 FOR_JOB_SELECT(p, pp, select, id)
1890 queue_pushunique(&q, p);
1899 sel->elements[j] = sel->elements[i] | setflags;
1900 sel->elements[j + 1] = id;
1902 else if (q.count > 1)
1904 sel->elements[j] = (sel->elements[i] & ~SOLVER_SELECTMASK) | SOLVER_SOLVABLE_ONE_OF | setflags;
1905 sel->elements[j + 1] = pool_queuetowhatprovides(pool, &q);
1909 sel->elements[j] = (sel->elements[i] & ~SOLVER_SELECTMASK) | SOLVER_SOLVABLE | SOLVER_NOAUTOSET | setflags;
1910 sel->elements[j + 1] = q.elements[0];
1914 queue_truncate(sel, j);
1919 selection_filter_int(Pool *pool, Queue *sel1, Queue *sel2, int invert)
1922 Id p, pp, q1filled = 0;
1927 /* handle special cases */
1928 if (!sel1->count || !sel2->count)
1930 if (invert && !sel2->count)
1935 if (sel1->count == 2 && (sel1->elements[0] & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_ALL && !invert)
1937 /* XXX: not 100% correct, but very useful */
1938 setflags = sel1->elements[0] & ~(SOLVER_SELECTMASK | SOLVER_SETMASK); /* job & jobflags */
1940 queue_init_clone(sel1, sel2);
1941 for (i = 0; i < sel1->count; i += 2)
1942 sel1->elements[i] = (sel1->elements[i] & (SOLVER_SELECTMASK | SOLVER_SETMASK)) | setflags;
1945 if (sel1->count == 2 && (sel1->elements[0] & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_REPO && !invert)
1947 Repo *repo = pool_id2repo(pool, sel1->elements[1]);
1948 setflags = sel1->elements[0] & ~(SOLVER_SELECTMASK | SOLVER_NOAUTOSET); /* job, jobflags, setflags */
1950 queue_init_clone(sel1, sel2);
1951 for (i = 0; i < sel1->count; i += 2)
1952 sel1->elements[i] &= SOLVER_SELECTMASK | SOLVER_SETMASK; /* remove job and jobflags */
1953 selection_filter_repo(pool, sel1, repo, setflags);
1956 if (sel2->count == 2 && (sel2->elements[0] & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_ALL)
1962 if (sel2->count == 2 && (sel2->elements[0] & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_REPO && !invert)
1964 Repo *repo = pool_id2repo(pool, sel2->elements[1]);
1965 setflags = sel2->elements[0] & (SOLVER_SETMASK & ~SOLVER_NOAUTOSET);
1966 selection_filter_repo(pool, sel1, repo, setflags);
1970 /* convert sel2 into a map */
1972 map_init(&m2, pool->nsolvables);
1973 for (i = 0; i < sel2->count; i += 2)
1975 Id select = sel2->elements[i] & SOLVER_SELECTMASK;
1976 if (select == SOLVER_SOLVABLE_ALL)
1984 if (select == SOLVER_SOLVABLE_REPO)
1987 Repo *repo = pool_id2repo(pool, sel2->elements[i + 1]);
1990 FOR_REPO_SOLVABLES(repo, p, s)
1996 if ((select == SOLVER_SOLVABLE_NAME || select == SOLVER_SOLVABLE_PROVIDES) && ISRELDEP(sel2->elements[i + 1]))
1998 Reldep *rd = GETRELDEP(pool, sel2->elements[i + 1]);
1999 if (rd->flags == REL_ARCH && rd->name == 0)
2001 /* special arch filter */
2003 selection_solvables(pool, sel1, &q1);
2004 for (j = 0; j < q1.count; j++)
2006 Id p = q1.elements[j];
2007 Solvable *s = pool->solvables + p;
2008 if (s->arch == rd->evr || (rd->evr == ARCH_SRC && s->arch == ARCH_NOSRC))
2013 else if (rd->flags == REL_KIND && rd->name == 0)
2015 /* special kind filter */
2017 selection_solvables(pool, sel1, &q1);
2018 for (j = 0; j < q1.count; j++)
2020 Id p = q1.elements[j];
2021 Solvable *s = pool->solvables + p;
2022 if (pool_is_kind(pool, s->name, rd->evr))
2028 FOR_JOB_SELECT(p, pp, select, sel2->elements[i + 1])
2034 /* now filter sel1 with the map */
2037 if (sel2->count == 2)
2038 setflags = sel2->elements[0] & (SOLVER_SETMASK & ~SOLVER_NOAUTOSET);
2039 selection_filter_map(pool, sel1, &m2, setflags);
2044 selection_filter(Pool *pool, Queue *sel1, Queue *sel2)
2046 selection_filter_int(pool, sel1, sel2, 0);
2050 selection_add(Pool *pool, Queue *sel1, Queue *sel2)
2053 queue_insertn(sel1, sel1->count, sel2->count, sel2->elements);
2057 selection_subtract(Pool *pool, Queue *sel1, Queue *sel2)
2059 selection_filter_int(pool, sel1, sel2, 1);
2063 pool_selection2str(Pool *pool, Queue *selection, Id flagmask)
2068 s = pool_tmpjoin(pool, 0, 0, 0);
2069 for (i = 0; i < selection->count; i += 2)
2071 Id how = selection->elements[i];
2073 s = pool_tmpappend(pool, s, " + ", 0);
2074 s2 = solver_select2str(pool, how & SOLVER_SELECTMASK, selection->elements[i + 1]);
2075 s = pool_tmpappend(pool, s, s2, 0);
2076 pool_freetmpspace(pool, s2);
2077 how &= flagmask & SOLVER_SETMASK;
2081 s = pool_tmpappend(pool, s, " ", 0);
2082 if (how & SOLVER_SETEV)
2083 s = pool_tmpappend(pool, s, ",setev", 0);
2084 if (how & SOLVER_SETEVR)
2085 s = pool_tmpappend(pool, s, ",setevr", 0);
2086 if (how & SOLVER_SETARCH)
2087 s = pool_tmpappend(pool, s, ",setarch", 0);
2088 if (how & SOLVER_SETVENDOR)
2089 s = pool_tmpappend(pool, s, ",setvendor", 0);
2090 if (how & SOLVER_SETREPO)
2091 s = pool_tmpappend(pool, s, ",setrepo", 0);
2092 if (how & SOLVER_NOAUTOSET)
2093 s = pool_tmpappend(pool, s, ",noautoset", 0);
2094 if (s[o + 1] != ',')
2095 s = pool_tmpappend(pool, s, ",?", 0);
2097 s = pool_tmpappend(pool, s, "]", 0);