2 * Copyright (c) 2012, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
19 #include "poolvendor.h"
21 #include "repo_susetags.h"
23 #include "solverdebug.h"
26 #include "solv_xfopen.h"
28 #ifndef ENABLE_SUSEREPO
29 # define DISABLE_JOIN2
30 # include "tools_util.h"
32 # include "repo_susetags.h"
35 static struct job2str {
39 { SOLVER_NOOP, "noop" },
40 { SOLVER_INSTALL, "install" },
41 { SOLVER_ERASE, "erase" },
42 { SOLVER_UPDATE, "update" },
43 { SOLVER_WEAKENDEPS, "weakendeps" },
44 { SOLVER_NOOBSOLETES, "noobsoletes" },
45 { SOLVER_LOCK, "lock" },
46 { SOLVER_DISTUPGRADE, "distupgrade" },
47 { SOLVER_VERIFY, "verify" },
48 { SOLVER_DROP_ORPHANED, "droporphaned" },
49 { SOLVER_USERINSTALLED, "userinstalled" },
53 static struct jobflags2str {
57 { SOLVER_WEAK, "weak" },
58 { SOLVER_ESSENTIAL, "essential" },
59 { SOLVER_CLEANDEPS, "cleandeps" },
60 { SOLVER_SETEV, "setev" },
61 { SOLVER_SETEVR, "setevr" },
62 { SOLVER_SETARCH, "setarch" },
63 { SOLVER_SETVENDOR, "setvendor" },
64 { SOLVER_SETREPO, "setrepo" },
65 { SOLVER_NOAUTOSET, "noautoset" },
69 static struct resultflags2str {
72 } resultflags2str[] = {
73 { TESTCASE_RESULT_TRANSACTION, "transaction" },
74 { TESTCASE_RESULT_PROBLEMS, "problems" },
75 { TESTCASE_RESULT_ORPHANED, "orphaned" },
76 { TESTCASE_RESULT_RECOMMENDED, "recommended" },
77 { TESTCASE_RESULT_UNNEEDED, "unneeded" },
81 static struct solverflags2str {
85 } solverflags2str[] = {
86 { SOLVER_FLAG_ALLOW_DOWNGRADE, "allowdowngrade", 0 },
87 { SOLVER_FLAG_ALLOW_ARCHCHANGE, "allowarchchange", 0 },
88 { SOLVER_FLAG_ALLOW_VENDORCHANGE, "allowvendorchange", 0 },
89 { SOLVER_FLAG_ALLOW_UNINSTALL, "allowuninstall", 0 },
90 { SOLVER_FLAG_NO_UPDATEPROVIDE, "noupdateprovide", 0 },
91 { SOLVER_FLAG_SPLITPROVIDES, "splitprovides", 0 },
92 { SOLVER_FLAG_IGNORE_RECOMMENDED, "ignorerecommended", 0 },
93 { SOLVER_FLAG_IGNORE_ALREADY_RECOMMENDED, "ignorealreadyrecommended", 0 },
94 { SOLVER_FLAG_NO_INFARCHCHECK, "noinfarchcheck", 0 },
99 typedef struct strqueue {
104 #define STRQUEUE_BLOCK 63
107 strqueue_init(Strqueue *q)
114 strqueue_free(Strqueue *q)
117 for (i = 0; i < q->nstr; i++)
118 solv_free(q->str[i]);
119 q->str = solv_free(q->str);
124 strqueue_push(Strqueue *q, const char *s)
126 q->str = solv_extend(q->str, q->nstr, 1, sizeof(*q->str), STRQUEUE_BLOCK);
127 q->str[q->nstr++] = solv_strdup(s);
131 strqueue_pushjoin(Strqueue *q, const char *s1, const char *s2, const char *s3)
133 q->str = solv_extend(q->str, q->nstr, 1, sizeof(*q->str), STRQUEUE_BLOCK);
134 q->str[q->nstr++] = solv_dupjoin(s1, s2, s3);
138 strqueue_sort_cmp(const void *ap, const void *bp, void *dp)
140 const char *a = *(const char **)ap;
141 const char *b = *(const char **)bp;
142 return strcmp(a ? a : "", b ? b : "");
146 strqueue_sort(Strqueue *q)
149 solv_sort(q->str, q->nstr, sizeof(*q->str), strqueue_sort_cmp, 0);
153 strqueue_sort_u(Strqueue *q)
157 for (i = j = 0; i < q->nstr; i++)
158 if (!j || strqueue_sort_cmp(q->str + i, q->str + j - 1, 0) != 0)
159 q->str[j++] = q->str[i];
164 strqueue_join(Strqueue *q)
168 for (i = 0; i < q->nstr; i++)
170 l += strlen(q->str[i]) + 1;
171 l++; /* trailing \0 */
174 for (i = 0; i < q->nstr; i++)
177 strcpy(rp, q->str[i]);
186 strqueue_split(Strqueue *q, const char *s)
189 while ((p = strchr(s, '\n')) != 0)
191 q->str = solv_extend(q->str, q->nstr, 1, sizeof(*q->str), STRQUEUE_BLOCK);
192 q->str[q->nstr] = solv_malloc(p - s + 1);
194 memcpy(q->str[q->nstr], s, p - s);
195 q->str[q->nstr][p - s] = 0;
204 strqueue_diff(Strqueue *sq1, Strqueue *sq2, Strqueue *osq)
207 while (i < sq1->nstr && j < sq2->nstr)
209 int r = strqueue_sort_cmp(sq1->str + i, sq2->str + j, 0);
213 strqueue_pushjoin(osq, "-", sq1->str[i++], 0);
215 strqueue_pushjoin(osq, "+", sq2->str[j++], 0);
217 while (i < sq1->nstr)
218 strqueue_pushjoin(osq, "-", sq1->str[i++], 0);
219 while (j < sq2->nstr)
220 strqueue_pushjoin(osq, "+", sq2->str[j++], 0);
224 pool_isknownarch(Pool *pool, Id id)
226 if (!id || id == ID_EMPTY)
228 if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH)
230 if (!pool->id2arch || (id > pool->lastarch || !pool->id2arch[id]))
236 testcase_str2dep(Pool *pool, char *s)
242 if ((n = strchr(s, '|')) != 0)
244 id = testcase_str2dep(pool, n + 1);
246 id = pool_rel2id(pool, testcase_str2dep(pool, s), id, REL_OR, 1);
250 while (*s == ' ' || *s == '\t')
253 while (*s && *s != ' ' && *s != '\t' && *s != '<' && *s != '=' && *s != '>')
257 while (*s && *s != ')')
263 if ((a = strchr(n, '.')) != 0 && a + 1 < s && s[-1] != ')')
265 Id archid = pool_strn2id(pool, a + 1, s - (a + 1), 0);
266 if (pool_isknownarch(pool, archid))
268 id = pool_strn2id(pool, n, a - n, 1);
269 id = pool_rel2id(pool, id, archid, REL_ARCH, 1);
272 id = pool_strn2id(pool, n, s - n, 1);
275 id = pool_strn2id(pool, n, s - n, 1);
278 while (*s == ' ' || *s == '\t')
294 while (*s == ' ' || *s == '\t')
297 while (*s && *s != ' ' && *s != '\t')
299 return pool_rel2id(pool, id, pool_strn2id(pool, n, s - n, 1), flags, 1);
303 testcase_repoid2str(Pool *pool, Id repoid)
305 Repo *repo = pool_id2repo(pool, repoid);
308 char *r = pool_tmpjoin(pool, repo->name, 0, 0);
310 for (rp = r; *rp; rp++)
311 if (*rp == ' ' || *rp == '\t')
318 sprintf(buf, "@#%d", repoid);
319 return pool_tmpjoin(pool, buf, 0, 0);
324 testcase_solvid2str(Pool *pool, Id p)
326 Solvable *s = pool->solvables + p;
330 if (p == SYSTEMSOLVABLE)
332 str = pool_solvid2str(pool, p);
334 return pool_tmpappend(pool, str, "@", 0);
338 char *str2 = pool_tmpappend(pool, str, "@", s->repo->name);
340 if (str2[l] == ' ' || str2[l] == '\t')
344 sprintf(buf, "@#%d", s->repo->repoid);
345 return pool_tmpappend(pool, str, buf, 0);
349 testcase_str2repo(Pool *pool, const char *str)
353 if (str[0] == '#' && (str[1] >= '0' && str[1] <= '9'))
357 for (j = 1; str[j] >= '0' && str[j] <= '9'; j++)
358 repoid = repoid * 10 + (str[j] - '0');
359 if (!str[j] && repoid > 0 && repoid < pool->nrepos)
360 repo = pool_id2repo(pool, repoid);
364 FOR_REPOS(repoid, repo)
369 l = strlen(repo->name);
370 for (i = 0; i < l; i++)
372 int c = repo->name[i];
373 if (c == ' ' || c == '\t')
378 if (i == l && !str[l])
381 if (repoid >= pool->nrepos)
388 testcase_str2solvid(Pool *pool, const char *str)
390 int i, l = strlen(str);
397 if (*str == '@' && !strcmp(str, "@SYSTEM"))
398 return SYSTEMSOLVABLE;
400 for (i = l - 1; i >= 0; i--)
401 if (str[i] == '@' && (repo = testcase_str2repo(pool, str + i + 1)) != 0)
406 /* now find the arch (if present) */
408 for (i = repostart - 1; i > 0; i--)
411 arch = pool_strn2id(pool, str + i + 1, repostart - (i + 1), 0);
416 /* now find the name */
417 for (i = repostart - 1; i > 0; i--)
421 Id nid, evrid, p, pp;
422 nid = pool_strn2id(pool, str, i, 0);
425 evrid = pool_strn2id(pool, str + i + 1, repostart - (i + 1), 0);
428 FOR_PROVIDES(p, pp, nid)
430 Solvable *s = pool->solvables + p;
431 if (s->name != nid || s->evr != evrid)
433 if (repo && s->repo != repo)
435 if (arch && s->arch != arch)
445 testcase_job2str(Pool *pool, Id how, Id what)
452 Id select = how & SOLVER_SELECTMASK;
454 for (i = 0; job2str[i].str; i++)
455 if ((how & SOLVER_JOBMASK) == job2str[i].job)
457 jobstr = job2str[i].str ? job2str[i].str : "unknown";
458 if (select == SOLVER_SOLVABLE)
461 pkgstr = testcase_solvid2str(pool, what);
463 else if (select == SOLVER_SOLVABLE_NAME)
466 pkgstr = pool_dep2str(pool, what);
468 else if (select == SOLVER_SOLVABLE_PROVIDES)
470 selstr = " provides ";
471 pkgstr = pool_dep2str(pool, what);
473 else if (select == SOLVER_SOLVABLE_ONE_OF)
478 while ((p = pool->whatprovidesdata[what++]) != 0)
480 const char *s = testcase_solvid2str(pool, p);
483 pkgstr = pool_tmpappend(pool, pkgstr, " ", s);
484 pool_freetmpspace(pool, s);
492 else if (select == SOLVER_SOLVABLE_REPO)
494 Repo *repo = pool_id2repo(pool, what);
499 sprintf(buf, "#%d", repo->repoid);
500 pkgstr = pool_tmpjoin(pool, buf, 0, 0);
503 pkgstr = pool_tmpjoin(pool, repo->name, 0, 0);
505 else if (select == SOLVER_SOLVABLE_ALL)
512 selstr = " unknown ";
515 ret = pool_tmpjoin(pool, jobstr, selstr, pkgstr);
517 ret = pool_tmpappend(pool, ret, " ", 0);
518 for (i = 0; jobflags2str[i].str; i++)
519 if ((how & jobflags2str[i].flag) != 0)
520 ret = pool_tmpappend(pool, ret, ",", jobflags2str[i].str);
526 ret = pool_tmpappend(pool, ret, "]", 0);
532 testcase_str2job(Pool *pool, const char *str, Id *whatp)
542 /* so we can patch it */
543 s = pool_tmpjoin(pool, str, 0, 0);
544 /* split it in pieces */
547 while (*s == ' ' || *s == '\t')
551 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
552 pieces[npieces++] = s;
553 while (*s && *s != ' ' && *s != '\t')
560 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
564 for (i = 0; job2str[i].str; i++)
565 if (!strcmp(pieces[0], job2str[i].str))
569 pool_debug(pool, SOLV_ERROR, "str2job: unknown job '%s'\n", str);
572 job = job2str[i].job;
575 char *flags = pieces[npieces - 1];
577 if (*flags == '[' && flags[strlen(flags) - 1] == ']')
581 flags[strlen(flags) - 1] = ',';
584 for (nf = flags; *nf != ','; nf++)
587 for (i = 0; jobflags2str[i].str; i++)
588 if (!strcmp(flags, jobflags2str[i].str))
590 if (!jobflags2str[i].str)
592 pool_debug(pool, SOLV_ERROR, "str2job: unknown jobflags in '%s'\n", str);
595 job |= jobflags2str[i].flag;
600 if (!strcmp(pieces[1], "pkg"))
604 pool_debug(pool, SOLV_ERROR, "str2job: bad pkg selector in '%s'\n", str);
607 job |= SOLVER_SOLVABLE;
608 what = testcase_str2solvid(pool, pieces[2]);
611 pool_debug(pool, SOLV_ERROR, "str2job: unknown package '%s'\n", pieces[2]);
615 else if (!strcmp(pieces[1], "name") || !strcmp(pieces[1], "provides"))
617 /* join em again for dep2str... */
619 for (sp = pieces[2]; sp < pieces[npieces - 1]; sp++)
622 what = testcase_str2dep(pool, pieces[2]);
623 if (pieces[1][0] == 'n')
624 job |= SOLVER_SOLVABLE_NAME;
626 job |= SOLVER_SOLVABLE_PROVIDES;
628 else if (!strcmp(pieces[1], "oneof"))
631 job |= SOLVER_SOLVABLE_ONE_OF;
633 if (npieces > 3 && strcmp(pieces[2], "nothing") != 0)
635 for (i = 2; i < npieces; i++)
637 Id p = testcase_str2solvid(pool, pieces[i]);
640 pool_debug(pool, SOLV_ERROR, "str2job: unknown package '%s'\n", pieces[i]);
647 what = pool_queuetowhatprovides(pool, &q);
650 else if (!strcmp(pieces[1], "repo"))
655 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
658 repo = testcase_str2repo(pool, pieces[2]);
661 pool_debug(pool, SOLV_ERROR, "str2job: unknown repo '%s'\n", pieces[2]);
664 job |= SOLVER_SOLVABLE_REPO;
667 else if (!strcmp(pieces[1], "all"))
669 if (npieces != 3 && strcmp(pieces[2], "packages") != 0)
671 pool_debug(pool, SOLV_ERROR, "str2job: bad line '%s'\n", str);
674 job |= SOLVER_SOLVABLE_ALL;
679 pool_debug(pool, SOLV_ERROR, "str2job: unknown selection in '%s'\n", str);
687 writedeps(Repo *repo, FILE *fp, const char *tag, Id key, Solvable *s, Offset off)
689 Pool *pool = repo->pool;
696 dp = repo->idarraydata + off;
698 while ((id = *dp++) != 0)
700 if (key == SOLVABLE_REQUIRES && id == SOLVABLE_PREREQMARKER)
703 fprintf(fp, "-%s\n", tag);
708 if (key == SOLVABLE_PROVIDES && id == SOLVABLE_FILEMARKER)
713 idstr = pool_dep2str(pool, id);
716 Reldep *rd = GETRELDEP(pool, id);
717 if (key == SOLVABLE_CONFLICTS && rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
719 if (!strncmp(idstr, "namespace:", 10))
722 if (key == SOLVABLE_SUPPLEMENTS)
724 if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_FILESYSTEM)
726 if (!strncmp(idstr, "namespace:", 10))
729 else if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_MODALIAS)
731 if (!strncmp(idstr, "namespace:", 10))
734 else if (rd->flags == REL_AND)
736 /* either packageand chain or modalias */
738 if (ISRELDEP(rd->evr))
740 Reldep *mrd = GETRELDEP(pool, rd->evr);
741 if (mrd->flags == REL_NAMESPACE && mrd->name == NAMESPACE_MODALIAS)
743 idstr = pool_tmpjoin(pool, "modalias(", pool_dep2str(pool, rd->name), ":");
744 idstr = pool_tmpappend(pool, idstr, pool_dep2str(pool, mrd->evr), ")");
746 else if (mrd->flags >= 8)
751 /* must be and chain */
752 idstr = pool_dep2str(pool, rd->evr);
758 rd = GETRELDEP(pool, id);
759 if (rd->flags != REL_AND)
761 idstr = pool_tmpjoin(pool, pool_dep2str(pool, rd->evr), ":", idstr);
763 idstr = pool_tmpjoin(pool, pool_dep2str(pool, id), ":", idstr);
764 idstr = pool_tmpjoin(pool, "packageand(", idstr, ")");
767 else if (rd->flags >= 8)
773 fprintf(fp, "+%s\n", tag);
776 fprintf(fp, "%s\n", idstr);
778 if (key == SOLVABLE_PROVIDES)
780 /* add the filelist */
782 dataiterator_init(&di, pool, repo, s - pool->solvables, SOLVABLE_FILELIST, 0, 0);
783 while (dataiterator_step(&di))
785 const char *s = repodata_dir2str(di.data, di.kv.id, di.kv.str);
788 Id id = pool_str2id(pool, s, 0);
791 for (dp = prvdp; *dp; dp++)
795 continue; /* already included */
800 fprintf(fp, "+%s", tag);
803 fprintf(fp, "%s\n", s);
807 fprintf(fp, "-%s\n", tag);
811 testcase_write_susetags(Repo *repo, FILE *fp)
813 Pool *pool = repo->pool;
823 fprintf(fp, "=Ver: 2.0\n");
824 FOR_REPO_SOLVABLES(repo, p, s)
826 name = pool_id2str(pool, s->name);
827 evr = pool_id2str(pool, s->evr);
828 arch = pool_id2str(pool, s->arch);
829 release = strrchr(evr, '-');
831 release = evr + strlen(evr);
832 fprintf(fp, "=Pkg: %s %.*s %s %s\n", name, release - evr, evr, *release && release[1] ? release + 1 : "-", arch);
833 tmp = solvable_lookup_str(s, SOLVABLE_SUMMARY);
835 fprintf(fp, "=Sum: %s\n", tmp);
836 writedeps(repo, fp, "Req:", SOLVABLE_REQUIRES, s, s->requires);
837 writedeps(repo, fp, "Prv:", SOLVABLE_PROVIDES, s, s->provides);
838 writedeps(repo, fp, "Obs:", SOLVABLE_OBSOLETES, s, s->obsoletes);
839 writedeps(repo, fp, "Con:", SOLVABLE_CONFLICTS, s, s->conflicts);
840 writedeps(repo, fp, "Rec:", SOLVABLE_RECOMMENDS, s, s->recommends);
841 writedeps(repo, fp, "Sup:", SOLVABLE_SUPPLEMENTS, s, s->supplements);
842 writedeps(repo, fp, "Sug:", SOLVABLE_SUGGESTS, s, s->suggests);
843 writedeps(repo, fp, "Enh:", SOLVABLE_ENHANCES, s, s->enhances);
845 fprintf(fp, "=Vnd: %s\n", pool_id2str(pool, s->vendor));
846 ti = solvable_lookup_num(s, SOLVABLE_BUILDTIME, 0);
848 fprintf(fp, "=Tim: %u\n", ti);
853 #ifndef ENABLE_SUSEREPO
856 adddep(Repo *repo, Offset olddeps, char *str, Id marker)
858 Id id = *str == '/' ? pool_str2id(repo->pool, str, 1) : testcase_str2dep(repo->pool, str);
859 return repo_addid_dep(repo, olddeps, id, marker);
863 finish_solvable(Pool *pool, Repodata *data, Solvable *s, char *filelist, int nfilelist)
869 for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1)
871 char *p = strrchr(filelist + l, '/');
875 did = repodata_str2dir(data, filelist + l, 1);
878 did = repodata_str2dir(data, "/", 1);
879 repodata_add_dirstr(data, handle, SOLVABLE_FILELIST, did, p);
882 if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
883 s->provides = repo_addid_dep(s->repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
884 s->supplements = repo_fix_supplements(s->repo, s->provides, s->supplements, 0);
885 s->conflicts = repo_fix_conflicts(s->repo, s->conflicts);
888 /* stripped down version of susetags parser used for testcases */
890 testcase_add_susetags(Repo *repo, FILE *fp, int flags)
892 Pool *pool = repo->pool;
905 data = repo_add_repodata(repo, flags);
910 line = solv_malloc(aline);
914 if (linep - line + 16 > aline)
916 aline = linep - line;
917 line = solv_realloc(line, aline + 512);
918 linep = line + aline;
921 if (!fgets(linep, aline - (linep - line), fp))
923 linep += strlen(linep);
924 if (linep == line || linep[-1] != '\n')
927 linep = line + intag;
930 if (line[intag] == '-' && !strncmp(line + 1, line + intag + 1, intag - 2))
937 else if (line[0] == '+' && line[1] && line[1] != ':')
939 char *tagend = strchr(line, ':');
944 intag = tagend + 2 - line;
945 linep = line + intag;
948 if (*line != '=' || !line[1] || !line[2] || !line[3] || line[4] != ':')
950 tag = line[1] << 16 | line[2] << 8 | line[3];
953 case 'P' << 16 | 'k' << 8 | 'g':
955 finish_solvable(pool, data, s, filelist, nfilelist);
957 if (split(line + 5, sp, 5) != 4)
959 s = pool_id2solvable(pool, repo_add_solvable(repo));
960 s->name = pool_str2id(pool, sp[0], 1);
961 /* join back version and release */
962 if (sp[2] && !(sp[2][0] == '-' && !sp[2][1]))
964 s->evr = makeevr(pool, sp[1]);
965 s->arch = pool_str2id(pool, sp[3], 1);
967 case 'S' << 16 | 'u' << 8 | 'm':
968 repodata_set_str(data, s - pool->solvables, SOLVABLE_SUMMARY, line + 6);
970 case 'V' << 16 | 'n' << 8 | 'd':
971 s->vendor = pool_str2id(pool, line + 6, 1);
973 case 'T' << 16 | 'i' << 8 | 'm':
976 repodata_set_num(data, s - pool->solvables, SOLVABLE_BUILDTIME, t);
978 case 'R' << 16 | 'e' << 8 | 'q':
979 s->requires = adddep(repo, s->requires, line + 6, -SOLVABLE_PREREQMARKER);
981 case 'P' << 16 | 'r' << 8 | 'q':
982 s->requires = adddep(repo, s->requires, line + 6, SOLVABLE_PREREQMARKER);
984 case 'P' << 16 | 'r' << 8 | 'v':
987 int l = strlen(line + 6) + 1;
988 if (nfilelist + l > afilelist)
990 afilelist = nfilelist + l + 512;
991 filelist = solv_realloc(filelist, afilelist);
993 memcpy(filelist + nfilelist, line + 6, l);
1000 for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1)
1001 s->provides = repo_addid_dep(repo, s->provides, pool_str2id(pool, filelist + l, 1), 0);
1004 s->provides = adddep(repo, s->provides, line + 6, 0);
1006 case 'O' << 16 | 'b' << 8 | 's':
1007 s->obsoletes = adddep(repo, s->obsoletes, line + 6, 0);
1009 case 'C' << 16 | 'o' << 8 | 'n':
1010 s->conflicts = adddep(repo, s->conflicts, line + 6, 0);
1012 case 'R' << 16 | 'e' << 8 | 'c':
1013 s->recommends = adddep(repo, s->recommends, line + 6, 0);
1015 case 'S' << 16 | 'u' << 8 | 'p':
1016 s->supplements = adddep(repo, s->supplements, line + 6, 0);
1018 case 'S' << 16 | 'u' << 8 | 'g':
1019 s->suggests = adddep(repo, s->suggests, line + 6, 0);
1021 case 'E' << 16 | 'n' << 8 | 'h':
1022 s->enhances = adddep(repo, s->enhances, line + 6, 0);
1029 finish_solvable(pool, data, s, filelist, nfilelist);
1031 solv_free(filelist);
1032 repodata_free_dircache(data);
1033 if (!(flags & REPO_NO_INTERNALIZE))
1034 repodata_internalize(data);
1041 testcase_add_susetags(Repo *repo, FILE *fp, int flags)
1043 return repo_add_susetags(repo, fp, 0, 0, flags);
1049 testcase_getsolverflags(Solver *solv)
1051 Pool *pool = solv->pool;
1052 const char *str = 0;
1054 for (i = 0; solverflags2str[i].str; i++)
1056 v = solver_get_flag(solv, solverflags2str[i].flag);
1057 if (v == solverflags2str[i].def)
1059 str = pool_tmpappend(pool, str, v ? " " : " !", solverflags2str[i].str);
1061 return str ? str + 1 : "";
1065 testcase_setsolverflags(Solver *solv, const char *str)
1067 const char *p = str, *s;
1071 while (*p == ' ' || *p == '\t' || *p == ',')
1082 while (*p && *p != ' ' && *p != '\t' && *p != ',')
1084 for (i = 0; solverflags2str[i].str; i++)
1085 if (!strncmp(solverflags2str[i].str, s, p - s) && solverflags2str[i].str[p - s] == 0)
1087 if (!solverflags2str[i].str)
1089 pool_debug(solv->pool, SOLV_ERROR, "setsolverflags: unknown flag '%.*s'\n", p - s, s);
1092 solver_set_flag(solv, solverflags2str[i].flag, v);
1098 testcase_resetsolverflags(Solver *solv)
1101 for (i = 0; solverflags2str[i].str; i++)
1102 solver_set_flag(solv, solverflags2str[i].flag, solverflags2str[i].def);
1106 testcase_ruleid(Solver *solv, Id rid)
1112 const unsigned char *md5;
1118 solver_ruleliterals(solv, rid, &q);
1119 for (i = 0; i < q.count; i++)
1121 Id p = q.elements[i];
1122 s = testcase_solvid2str(solv->pool, p > 0 ? p : -p);
1124 s = pool_tmpjoin(solv->pool, "!", s, 0);
1125 strqueue_push(&sq, s);
1128 strqueue_sort_u(&sq);
1129 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1130 for (i = 0; i < sq.nstr; i++)
1131 solv_chksum_add(chk, sq.str[i], strlen(sq.str[i]) + 1);
1132 md5 = solv_chksum_get(chk, &md5l);
1133 s = pool_bin2hex(solv->pool, md5, md5l);
1134 chk = solv_chksum_free(chk, 0);
1140 testcase_problemid(Solver *solv, Id problem)
1145 const unsigned char *md5;
1149 /* we build a hash of all rules that define the problem */
1152 solver_findallproblemrules(solv, problem, &q);
1153 for (i = 0; i < q.count; i++)
1154 strqueue_push(&sq, testcase_ruleid(solv, q.elements[i]));
1156 strqueue_sort_u(&sq);
1157 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1158 for (i = 0; i < sq.nstr; i++)
1159 solv_chksum_add(chk, sq.str[i], strlen(sq.str[i]) + 1);
1160 md5 = solv_chksum_get(chk, &md5l);
1161 s = pool_bin2hex(solv->pool, md5, 4);
1162 chk = solv_chksum_free(chk, 0);
1168 testcase_solutionid(Solver *solv, Id problem, Id solution)
1172 const unsigned char *md5;
1176 intid = solver_solutionelement_internalid(solv, problem, solution);
1177 /* internal stuff! handle with care! */
1181 s = testcase_job2str(solv->pool, solv->job.elements[-intid - 1], solv->job.elements[-intid]);
1186 s = testcase_ruleid(solv, intid);
1188 chk = solv_chksum_create(REPOKEY_TYPE_MD5);
1189 solv_chksum_add(chk, s, strlen(s) + 1);
1190 md5 = solv_chksum_get(chk, &md5l);
1191 s = pool_bin2hex(solv->pool, md5, 4);
1192 chk = solv_chksum_free(chk, 0);
1196 static struct class2str {
1200 { SOLVER_TRANSACTION_ERASE, "erase" },
1201 { SOLVER_TRANSACTION_INSTALL, "install" },
1202 { SOLVER_TRANSACTION_REINSTALLED, "reinstall" },
1203 { SOLVER_TRANSACTION_DOWNGRADED, "downgrade" },
1204 { SOLVER_TRANSACTION_CHANGED, "change" },
1205 { SOLVER_TRANSACTION_UPGRADED, "upgrade" },
1206 { SOLVER_TRANSACTION_OBSOLETED, "obsolete" },
1207 { SOLVER_TRANSACTION_MULTIINSTALL, "multiinstall" },
1208 { SOLVER_TRANSACTION_MULTIREINSTALL, "multireinstall" },
1213 testcase_solverresult(Solver *solv, int resultflags)
1215 Pool *pool = solv->pool;
1223 if ((resultflags & TESTCASE_RESULT_TRANSACTION) != 0)
1225 Transaction *trans = solver_create_transaction(solv);
1229 for (i = 0; class2str[i].str; i++)
1232 transaction_classify_pkgs(trans, 0, class2str[i].class, 0, 0, &q);
1233 for (j = 0; j < q.count; j++)
1237 if (pool->installed && pool->solvables[p].repo == pool->installed)
1238 op = transaction_obs_pkg(trans, p);
1239 s = pool_tmpjoin(pool, class2str[i].str, " ", testcase_solvid2str(pool, p));
1241 s = pool_tmpjoin(pool, s, " ", testcase_solvid2str(pool, op));
1242 strqueue_push(&sq, s);
1246 transaction_free(trans);
1248 if ((resultflags & TESTCASE_RESULT_PROBLEMS) != 0)
1250 char *probprefix, *solprefix;
1251 int problem, solution, element;
1254 pcnt = solver_problem_count(solv);
1255 for (problem = 1; problem <= pcnt; problem++)
1257 Id rid, from, to, dep;
1258 SolverRuleinfo rinfo;
1259 rid = solver_findproblemrule(solv, problem);
1260 s = testcase_problemid(solv, problem);
1261 probprefix = solv_dupjoin("problem ", s, 0);
1262 rinfo = solver_ruleinfo(solv, rid, &from, &to, &dep);
1263 s = pool_tmpjoin(pool, probprefix, " info ", solver_problemruleinfo2str(solv, rinfo, from, to, dep));
1264 strqueue_push(&sq, s);
1265 scnt = solver_solution_count(solv, problem);
1266 for (solution = 1; solution <= scnt; solution++)
1268 s = testcase_solutionid(solv, problem, solution);
1269 solprefix = solv_dupjoin(probprefix, " solution ", s);
1271 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &op)) != 0)
1273 if (p == SOLVER_SOLUTION_JOB)
1274 s = pool_tmpjoin(pool, solprefix, " deljob ", testcase_job2str(pool, solv->job.elements[op - 1], solv->job.elements[op]));
1275 else if (p > 0 && op == 0)
1276 s = pool_tmpjoin(pool, solprefix, " erase ", testcase_solvid2str(pool, p));
1277 else if (p > 0 && op > 0)
1279 s = pool_tmpjoin(pool, solprefix, " replace ", testcase_solvid2str(pool, p));
1280 s = pool_tmpappend(pool, s, " ", testcase_solvid2str(pool, op));
1282 else if (p < 0 && op > 0)
1283 s = pool_tmpjoin(pool, solprefix, " allow ", testcase_solvid2str(pool, op));
1285 s = pool_tmpjoin(pool, solprefix, " unknown", 0);
1286 strqueue_push(&sq, s);
1288 solv_free(solprefix);
1290 solv_free(probprefix);
1294 if ((resultflags & TESTCASE_RESULT_ORPHANED) != 0)
1299 solver_get_orphaned(solv, &q);
1300 for (i = 0; i < q.count; i++)
1302 s = pool_tmpjoin(pool, "orphaned ", testcase_solvid2str(pool, q.elements[i]), 0);
1303 strqueue_push(&sq, s);
1308 if ((resultflags & TESTCASE_RESULT_RECOMMENDED) != 0)
1314 solver_get_recommendations(solv, &qr, &qs, 0);
1315 for (i = 0; i < qr.count; i++)
1317 s = pool_tmpjoin(pool, "recommended ", testcase_solvid2str(pool, qr.elements[i]), 0);
1318 strqueue_push(&sq, s);
1320 for (i = 0; i < qs.count; i++)
1322 s = pool_tmpjoin(pool, "suggested ", testcase_solvid2str(pool, qs.elements[i]), 0);
1323 strqueue_push(&sq, s);
1330 result = strqueue_join(&sq);
1337 testcase_write(Solver *solv, char *dir, int resultflags)
1339 Pool *pool = solv->pool;
1349 if (mkdir(dir, 0777) && errno != EEXIST)
1351 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not create directory '%s'\n", dir);
1355 FOR_REPOS(repoid, repo)
1357 const char *name = testcase_repoid2str(pool, repoid);
1359 if (repo->subpriority)
1360 sprintf(priobuf, "%d.%d", repo->priority, repo->subpriority);
1362 sprintf(priobuf, "%d", repo->priority);
1363 out = pool_tmpjoin(pool, name, ".repo", ".gz");
1364 cmd = pool_tmpjoin(pool, "repo ", name, " ");
1365 cmd = pool_tmpappend(pool, cmd, priobuf, " ");
1366 cmd = pool_tmpappend(pool, cmd, "susetags ", out);
1367 strqueue_push(&sq, cmd);
1368 out = pool_tmpjoin(pool, dir, "/", out);
1369 if (!(fp = solv_xfopen(out, "w")))
1371 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
1375 testcase_write_susetags(repo, fp);
1378 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1383 /* hmm, this is not optimal... we currently search for the lowest score */
1386 for (i = 0; i < pool->lastarch; i++)
1388 if (pool->id2arch[i] == 1 && !lowscore)
1390 if (pool->id2arch[i] > 0x10000 && (!lowscore || pool->id2arch[i] < lowscore))
1393 lowscore = pool->id2arch[i];
1396 cmd = pool_tmpjoin(pool, "system ", pool_id2str(pool, arch), pool->disttype == DISTTYPE_DEB ? " deb" : " rpm");
1397 if (pool->installed)
1398 cmd = pool_tmpappend(pool, cmd, " ", testcase_repoid2str(pool, pool->installed->repoid));
1399 strqueue_push(&sq, cmd);
1401 if (pool->vendorclasses)
1404 for (i = 0; pool->vendorclasses[i]; i++)
1406 cmd = pool_tmpappend(pool, cmd ? cmd : "vendorclass", " ", pool->vendorclasses[i]);
1407 if (!pool->vendorclasses[i + 1])
1409 strqueue_push(&sq, cmd);
1416 s = testcase_getsolverflags(solv);
1419 cmd = pool_tmpjoin(pool, "solverflags ", s, 0);
1420 strqueue_push(&sq, cmd);
1423 /* now dump all the ns callback values we know */
1424 if (pool->nscallback)
1428 for (rid = 1; rid < pool->nrels; rid++)
1430 Reldep *rd = pool->rels + rid;
1431 if (rd->flags != REL_NAMESPACE || rd->name == NAMESPACE_OTHERPROVIDERS)
1433 /* check if we evaluated it, also skip empty results */
1434 if (!(d = pool->whatprovides_rel[rid]) || !pool->whatprovidesdata[d])
1436 cmd = pool_tmpjoin(pool, "namespace ", pool_id2str(pool, rd->name), "(");
1437 cmd = pool_tmpappend(pool, cmd, pool_id2str(pool, rd->evr), ")");
1438 for (; pool->whatprovidesdata[d]; d++)
1439 cmd = pool_tmpappend(pool, cmd, " ", testcase_solvid2str(pool, pool->whatprovidesdata[d]));
1440 strqueue_push(&sq, cmd);
1444 for (i = 0; i < solv->job.count; i += 2)
1446 cmd = (char *)testcase_job2str(pool, solv->job.elements[i], solv->job.elements[i + 1]);
1447 cmd = pool_tmpjoin(pool, "job ", cmd, 0);
1448 strqueue_push(&sq, cmd);
1454 out = pool_tmpjoin(pool, dir, "/", "solver.result");
1455 if (!(fp = fopen(out, "w")))
1457 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
1461 result = testcase_solverresult(solv, resultflags);
1462 if (fwrite(result, strlen(result), 1, fp) != 1)
1464 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1472 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1477 for (i = 0; resultflags2str[i].str; i++)
1478 if ((resultflags & resultflags2str[i].flag) != 0)
1479 cmd = pool_tmpappend(pool, cmd, cmd ? "," : 0, resultflags2str[i].str);
1480 cmd = pool_tmpjoin(pool, "result ", cmd ? cmd : "?", " solver.result");
1481 strqueue_push(&sq, cmd);
1484 cmd = strqueue_join(&sq);
1485 out = pool_tmpjoin(pool, dir, "/", "testcase.t");
1486 if (!(fp = fopen(out, "w")))
1488 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: could not open '%s' for writing\n", out);
1492 if (fwrite(cmd, strlen(cmd), 1, fp) != 1)
1494 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1500 pool_debug(solv->pool, SOLV_ERROR, "testcase_write: write error\n");
1510 testcase_read(Pool *pool, FILE *fp, char *testcase, Queue *job, char **resultp, int *resultflagsp)
1515 char *testcasedir, *s;
1522 if (!fp && !(fp = fopen(testcase, "r")))
1524 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", testcase);
1527 testcasedir = solv_strdup(testcase);
1528 if ((s = strchr(testcasedir, '/')) != 0)
1533 buf = solv_malloc(bufl);
1538 if (bufp - buf + 16 > bufl)
1541 buf = solv_realloc(buf, bufl + 512);
1545 if (!fgets(bufp, bufl - (bufp - buf), fp))
1549 if (!l || buf[l - 1] != '\n')
1556 while (*s && (*s == ' ' || *s == '\t'))
1558 if (!*s || *s == '#')
1561 /* split it in pieces */
1564 while (*s == ' ' || *s == '\t')
1568 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
1569 pieces[npieces++] = s;
1570 while (*s && *s != ' ' && *s != '\t')
1575 pieces = solv_extend(pieces, npieces, 1, sizeof(*pieces), 7);
1576 pieces[npieces] = 0;
1577 if (!strcmp(pieces[0], "repo") && npieces >= 4)
1579 Repo *repo = repo_create(pool, pieces[1]);
1585 if (sscanf(pieces[2], "%d.%d", &prio, &subprio) != 2)
1588 prio = atoi(pieces[2]);
1590 repo->priority = prio;
1591 repo->subpriority = subprio;
1592 rdata = pool_tmpjoin(pool, testcasedir, pieces[4], 0);
1593 if ((rfp = solv_xfopen(rdata, "r")) == 0)
1595 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", rdata);
1597 else if (!strcmp(pieces[3], "susetags"))
1599 testcase_add_susetags(repo, rfp, 0);
1605 pool_debug(pool, SOLV_ERROR, "testcase_read: unknown repo type for repo '%s'\n", repo->name);
1608 else if (!strcmp(pieces[0], "system") && npieces >= 3)
1611 pool_setarch(pool, pieces[1]);
1614 Repo *repo = testcase_str2repo(pool, pieces[3]);
1616 pool_debug(pool, SOLV_ERROR, "testcase_read: system: unknown repo '%s'\n", pieces[3]);
1618 pool_set_installed(pool, repo);
1621 else if (!strcmp(pieces[0], "job") && npieces > 1)
1627 pool_addfileprovides(pool);
1628 pool_createwhatprovides(pool);
1632 for (sp = pieces[1]; sp < pieces[npieces - 1]; sp++)
1635 how = testcase_str2job(pool, pieces[1], &what);
1636 if (how >= 0 && job)
1637 queue_push2(job, how, what);
1639 else if (!strcmp(pieces[0], "vendorclass") && npieces > 1)
1641 pool_addvendorclass(pool, (const char **)(pieces + 1));
1643 else if (!strcmp(pieces[0], "namespace") && npieces > 1)
1645 int i = strlen(pieces[1]);
1646 s = strchr(pieces[1], '(');
1647 if (!s && pieces[1][i - 1] != ')')
1649 pool_debug(pool, SOLV_ERROR, "testcase_read: bad namespace '%s'\n", pieces[1]);
1657 pieces[1][i - 1] = 0;
1658 name = pool_str2id(pool, pieces[1], 1);
1659 evr = pool_str2id(pool, s + 1, 1);
1661 pieces[1][i - 1] = ')';
1662 id = pool_rel2id(pool, name, evr, REL_NAMESPACE, 1);
1663 for (i = 2; i < npieces; i++)
1664 queue_push(&q, testcase_str2solvid(pool, pieces[i]));
1665 /* now do the callback */
1668 pool_addfileprovides(pool);
1669 pool_createwhatprovides(pool);
1672 pool->whatprovides_rel[GETRELID(id)] = pool_queuetowhatprovides(pool, &q);
1676 else if (!strcmp(pieces[0], "solverflags") && npieces > 1)
1681 solv = solver_create(pool);
1682 testcase_resetsolverflags(solv);
1684 for (i = 1; i < npieces; i++)
1685 testcase_setsolverflags(solv, pieces[i]);
1687 else if (!strcmp(pieces[0], "result") && npieces > 1)
1691 int resultflags = 0;
1692 char *s = pieces[1];
1696 char *se = strchr(s, ',');
1699 for (i = 0; resultflags2str[i].str; i++)
1700 if (!strcmp(s, resultflags2str[i].str))
1702 resultflags |= resultflags2str[i].flag;
1705 if (!resultflags2str[i].str)
1706 pool_debug(pool, SOLV_ERROR, "result: unknown flag '%s'\n", s);
1710 rdata = pool_tmpjoin(pool, testcasedir, pieces[2], 0);
1711 if (!strcmp(pieces[1], "<inline>"))
1714 rfp = fopen(rdata, "r");
1717 pool_debug(pool, SOLV_ERROR, "testcase_read: could not open '%s'\n", rdata);
1721 /* slurp it in... */
1722 char *result = solv_malloc(1024);
1728 if (rp - result + 256 >= resultl)
1730 resultl = rp - result;
1731 result = solv_realloc(result, resultl + 1024);
1732 rp = result + resultl;
1737 if (!fgets(rp, resultl - (rp - result), fp))
1742 if (rl && (rp == result || rp[-1] == '\n'))
1744 if (rl > 1 && rp[0] == '#' && rp[1] == '>')
1746 memmove(rp, rp + 2, rl - 2);
1751 while (rl + 16 > bufl)
1753 buf = solv_realloc(buf, bufl + 512);
1756 memmove(buf, rp, rl);
1757 if (buf[rl - 1] == '\n')
1769 rl = fread(rp, 1, resultl - (rp - result), rfp);
1784 *resultflagsp = resultflags;
1789 pool_debug(pool, SOLV_ERROR, "testcase_read: cannot parse command '%s'\n", pieces[0]);
1792 buf = solv_free(buf);
1793 pieces = solv_free(pieces);
1794 solv_free(testcasedir);
1797 pool_addfileprovides(pool);
1798 pool_createwhatprovides(pool);
1802 solv = solver_create(pool);
1803 testcase_resetsolverflags(solv);
1811 testcase_resultdiff(char *result1, char *result2)
1813 Strqueue sq1, sq2, osq;
1815 strqueue_init(&sq1);
1816 strqueue_init(&sq2);
1817 strqueue_init(&osq);
1818 strqueue_split(&sq1, result1);
1819 strqueue_split(&sq2, result2);
1820 strqueue_sort(&sq1);
1821 strqueue_sort(&sq2);
1822 strqueue_diff(&sq1, &sq2, &osq);
1823 r = osq.nstr ? strqueue_join(&osq) : 0;
1824 strqueue_free(&sq1);
1825 strqueue_free(&sq2);
1826 strqueue_free(&osq);