2 * Copyright (c) 2009, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
8 /* solv, a little software installer demoing the sat solver library */
11 * - vendor policy loading
23 #include <sys/utsname.h>
24 #include <sys/types.h>
33 #include "solverdebug.h"
35 #include "repo_solv.h"
37 #include "repo_write.h"
38 #include "repo_rpmdb.h"
39 #include "repo_products.h"
40 #include "repo_rpmmd.h"
41 #include "repo_susetags.h"
42 #include "repo_repomdxml.h"
43 #include "repo_updateinfoxml.h"
44 #include "repo_content.h"
45 #include "pool_fileconflicts.h"
49 # define REPOINFO_PATH "/etc/yum.repos.d"
51 # define REPOINFO_PATH "/etc/zypp/repos.d"
52 # define PRODUCTS_PATH "/etc/products.d"
55 #define SOLVCACHE_PATH "/var/cache/solv"
73 #define TYPE_UNKNOWN 0
74 #define TYPE_SUSETAGS 1
76 #define TYPE_PLAINDIR 3
79 read_repoinfos_sort(const void *ap, const void *bp)
81 const struct repoinfo *a = ap;
82 const struct repoinfo *b = bp;
83 return strcmp(a->alias, b->alias);
87 read_repoinfos(Pool *pool, const char *reposdir, int *nrepoinfosp)
90 char buf2[4096], *kp, *vp, *kpe;
95 struct repoinfo *repoinfos = 0, *cinfo;
98 rdlen = strlen(reposdir);
99 dir = opendir(reposdir);
105 while ((ent = readdir(dir)) != 0)
107 l = strlen(ent->d_name);
108 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
110 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
111 if ((fp = fopen(buf, "r")) == 0)
117 while(fgets(buf2, sizeof(buf2), fp))
122 while (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t')
125 while (*kp == ' ' || *kp == '\t')
127 if (!*kp || *kp == '#')
133 vp = strrchr(kp, ']');
137 repoinfos = sat_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
138 cinfo = repoinfos + nrepoinfos++;
139 memset(cinfo, 0, sizeof(*cinfo));
140 cinfo->alias = strdup(kp + 1);
142 cinfo->type = TYPE_RPMMD;
145 vp = strchr(kp, '=');
148 for (kpe = vp - 1; kpe >= kp; kpe--)
149 if (*kpe != ' ' && *kpe != '\t')
154 while (*vp == ' ' || *vp == '\t')
157 if (!strcmp(kp, "name"))
158 cinfo->name = strdup(vp);
159 else if (!strcmp(kp, "enabled"))
160 cinfo->enabled = *vp == '0' ? 0 : 1;
161 else if (!strcmp(kp, "autorefresh"))
162 cinfo->autorefresh = *vp == '0' ? 0 : 1;
163 else if (!strcmp(kp, "gpgcheck"))
164 cinfo->gpgcheck = *vp == '0' ? 0 : 1;
165 else if (!strcmp(kp, "baseurl"))
166 cinfo->baseurl = strdup(vp);
167 else if (!strcmp(kp, "path"))
169 if (vp && strcmp(vp, "/") != 0)
170 cinfo->path = strdup(vp);
172 else if (!strcmp(kp, "type"))
174 if (!strcmp(vp, "yast2"))
175 cinfo->type = TYPE_SUSETAGS;
176 else if (!strcmp(vp, "rpm-md"))
177 cinfo->type = TYPE_RPMMD;
178 else if (!strcmp(vp, "plaindir"))
179 cinfo->type = TYPE_PLAINDIR;
181 cinfo->type = TYPE_UNKNOWN;
183 else if (!strcmp(kp, "priority"))
184 cinfo->priority = atoi(vp);
185 else if (!strcmp(kp, "keeppackages"))
186 cinfo->keeppackages = *vp == '0' ? 0 : 1;
192 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
193 *nrepoinfosp = nrepoinfos;
198 cookie_gzread(void *cookie, char *buf, size_t nbytes)
200 return gzread((gzFile *)cookie, buf, nbytes);
204 cookie_gzclose(void *cookie)
206 return gzclose((gzFile *)cookie);
210 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype)
217 const char *baseurl = cinfo->baseurl;
220 if (l && baseurl[l - 1] == '/')
221 snprintf(url, sizeof(url), "%s%s", baseurl, file);
223 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
224 strcpy(tmpl, "/var/tmp/solvXXXXXX");
232 if ((pid = fork()) == (pid_t)-1)
244 execlp("curl", "curl", "-s", "-L", url, (char *)0);
248 while (waitpid(pid, &status, 0) != pid)
250 if (lseek(fd, 0, SEEK_END) == 0)
256 lseek(fd, 0, SEEK_SET);
261 void *h = sat_chksum_create(chksumtype);
266 printf("%s: unknown checksum type\n", file);
270 while ((l = read(fd, buf, sizeof(buf))) > 0)
271 sat_chksum_add(h, buf, l);
272 lseek(fd, 0, SEEK_SET);
274 sum = sat_chksum_get(h, &l);
275 if (memcmp(sum, chksum, l))
277 printf("%s: checksum mismatch\n", file);
284 cookie_io_functions_t cio;
287 sprintf(tmpl, "/dev/fd/%d", fd);
288 gzf = gzopen(tmpl, "r");
292 memset(&cio, 0, sizeof(cio));
293 cio.read = cookie_gzread;
294 cio.close = cookie_gzclose;
295 return fopencookie(gzf, "r", cio);
297 fcntl(fd, F_SETFD, FD_CLOEXEC);
298 return fdopen(fd, "r");
302 cleanupgpg(char *gpgdir)
305 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
307 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
309 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
311 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
313 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
319 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
328 off_t posfp, possigfp;
331 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
334 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
335 if (!(kfp = fopen(keysfile, "w")) )
340 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
344 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
345 if (!pubkey || !*pubkey)
347 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
349 if (fputc('\n', kfp) == EOF) /* Just in case... */
357 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --import %s", gpgdir, keysfile);
360 fprintf(stderr, "key import error\n");
365 posfp = lseek(fileno(fp), 0, SEEK_CUR);
366 lseek(fileno(fp), 0, SEEK_SET);
367 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
368 lseek(fileno(sigfp), 0, SEEK_SET);
369 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
370 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
371 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
373 lseek(fileno(sigfp), possigfp, SEEK_SET);
374 lseek(fileno(fp), posfp, SEEK_SET);
375 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
376 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
378 return r == 0 ? 1 : 0;
381 #define CHKSUM_IDENT "1.0"
384 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
387 void *h = sat_chksum_create(chktype);
390 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
391 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
392 sat_chksum_add(h, buf, l);
394 sat_chksum_free(h, out);
398 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *out)
400 void *h = sat_chksum_create(chktype);
401 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
402 sat_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
403 sat_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
404 sat_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
405 sat_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
406 sat_chksum_free(h, out);
418 pool_setarch(pool, un.machine);
421 char *calccachepath(Repo *repo)
423 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
424 p = pool_tmpjoin(repo->pool, p, ".solv", 0);
425 q = p + strlen(SOLVCACHE_PATH) + 1;
435 usecachedrepo(Repo *repo, unsigned char *cookie)
438 unsigned char mycookie[32];
440 if (!(fp = fopen(calccachepath(repo), "r")))
442 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
447 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
453 if (repo_add_solv(repo, fp))
463 writecachedrepo(Repo *repo, unsigned char *cookie)
465 Id *addedfileprovides = 0;
471 mkdir(SOLVCACHE_PATH, 0755);
472 tmpl = sat_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
480 if (!(fp = fdopen(fd, "w")))
487 info = repo_add_repodata(repo, 0);
488 pool_addfileprovides_ids(repo->pool, 0, &addedfileprovides);
489 if (addedfileprovides && *addedfileprovides)
491 for (i = 0; addedfileprovides[i]; i++)
492 repodata_add_idarray(info, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, addedfileprovides[i]);
494 sat_free(addedfileprovides);
495 repodata_internalize(info);
496 repo_write(repo, fp, 0, 0, 0);
498 if (fwrite(cookie, 32, 1, fp) != 1)
511 if (!rename(tmpl, calccachepath(repo)))
519 Pool *sigpool = pool_create();
520 Repo *repo = repo_create(sigpool, "rpmdbkeys");
521 repo_add_rpmdb_pubkeys(repo, 0, 0);
526 iscompressed(const char *name)
528 int l = strlen(name);
529 return l > 3 && !strcmp(name + l - 3, ".gz") ? 1 : 0;
532 static inline const char *
533 findinrepomd(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
535 Pool *pool = repo->pool;
537 const char *filename;
542 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
543 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
544 if (dataiterator_step(&di))
546 dataiterator_setpos_parent(&di);
547 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
548 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
550 dataiterator_free(&di);
551 if (filename && !*chksumtypep)
553 printf("no %s file checksum!\n", what);
560 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
563 struct repoinfo *cinfo;
567 const char *filename;
568 const unsigned char *filechksum;
570 const char *descrdir;
573 unsigned char cookie[32];
576 repo = repo_create(pool, "@System");
577 printf("rpm database:");
578 if (stat("/var/lib/rpm/Packages", &stb))
579 memset(&stb, 0, sizeof(&stb));
580 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cookie);
581 if (usecachedrepo(repo, cookie))
586 printf(" reading\n");
590 repo_add_products(repo, PRODUCTS_PATH, 0, REPO_NO_INTERNALIZE);
592 if ((ofp = fopen(calccachepath(repo), "r")) != 0)
594 Repo *ref = repo_create(pool, "@System.old");
595 if (!repo_add_solv(ref, ofp))
597 repo_add_rpmdb(repo, ref, 0, REPO_REUSE_REPODATA);
604 repo_add_rpmdb(repo, 0, 0, REPO_REUSE_REPODATA);
605 writecachedrepo(repo, cookie);
607 pool_set_installed(pool, repo);
609 for (i = 0; i < nrepoinfos; i++)
611 cinfo = repoinfos + i;
615 repo = repo_create(pool, cinfo->alias);
617 repo->appdata = cinfo;
618 repo->priority = 99 - cinfo->priority;
620 if (!cinfo->autorefresh && usecachedrepo(repo, 0))
622 printf("repo '%s':", cinfo->alias);
629 printf("rpmmd repo '%s':", cinfo->alias);
631 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0)) == 0)
633 printf(" no repomd.xml file, skipped\n");
638 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cookie);
639 if (usecachedrepo(repo, cookie))
648 if ((sigfp = curlfopen(cinfo, "repodata/repomd.xml.asc", 0, 0, 0)) == 0)
650 printf(" unsigned, skipped\n");
655 sigpool = read_sigs();
656 if (!checksig(sigpool, fp, sigfp))
658 printf(" checksig failed, skipped\n");
665 repo_add_repomdxml(repo, fp, 0);
667 printf(" reading\n");
668 filename = findinrepomd(repo, "primary", &filechksum, &filechksumtype);
669 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype)) != 0)
671 repo_add_rpmmd(repo, fp, 0, 0);
675 filename = findinrepomd(repo, "updateinfo", &filechksum, &filechksumtype);
676 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype)) != 0)
678 repo_add_updateinfoxml(repo, fp, 0);
682 writecachedrepo(repo, cookie);
686 printf("susetags repo '%s':", cinfo->alias);
688 repo = repo_create(pool, cinfo->alias);
690 repo->appdata = cinfo;
691 repo->priority = 99 - cinfo->priority;
694 if ((fp = curlfopen(cinfo, "content", 0, 0, 0)) == 0)
696 printf(" no content file, skipped\n");
701 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cookie);
702 if (usecachedrepo(repo, cookie))
711 if ((sigfp = curlfopen(cinfo, "content.asc", 0, 0, 0)) == 0)
713 printf(" unsigned, skipped\n");
718 sigpool = read_sigs();
719 if (!checksig(sigpool, fp, sigfp))
721 printf(" checksig failed, skipped\n");
727 repo_add_content(repo, fp, 0);
729 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
730 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
732 descrdir = "suse/setup/descr";
734 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, "packages.gz", SEARCH_STRING);
735 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
736 if (dataiterator_step(&di))
738 dataiterator_setpos_parent(&di);
739 filechksum = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
740 filename = "packages.gz";
742 dataiterator_free(&di);
745 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, "packages", SEARCH_STRING);
746 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
747 if (dataiterator_step(&di))
749 dataiterator_setpos_parent(&di);
750 filechksum = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
751 filename = "packages";
753 dataiterator_free(&di);
757 printf(" no packages file entry, skipped\n");
762 printf(" no packages file checksum, skipped\n");
765 printf(" reading\n");
766 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype)) == 0)
768 repo_add_susetags(repo, fp, defvendor, 0, 0);
770 writecachedrepo(repo, cookie);
773 printf("unsupported repo '%s': skipped\n", cinfo->alias);
784 mkselect(Pool *pool, const char *arg, int flags, Queue *out)
790 id = str2id(pool, arg, 0);
793 FOR_PROVIDES(p, pp, id)
795 Solvable *s = pool_id2solvable(pool, p);
798 type = SOLVER_SOLVABLE_NAME;
801 type = SOLVER_SOLVABLE_PROVIDES;
806 /* did not find a solvable, see if it's a relation */
807 if ((r = strpbrk(arg, "<=>")) != 0)
811 for (r2 = r; r2 > arg && (r2[-1] == ' ' || r2[-1] == '\t'); )
813 rname = r2 > arg ? strn2id(pool, arg, r2 - arg, 1) : 0;
825 while (*r == ' ' || *r == '\t')
827 revr = *r ? str2id(pool, r, 1) : 0;
828 rid = rname && revr ? rel2id(pool, rname, revr, rflags, 1) : 0;
831 FOR_PROVIDES(p, pp, rid)
833 Solvable *s = pool_id2solvable(pool, p);
834 if (pool_match_nevr(pool, s, rid))
836 type = SOLVER_SOLVABLE_NAME;
839 type = SOLVER_SOLVABLE_PROVIDES;
848 queue_push(out, type);
854 yesno(const char *str)
856 char inbuf[128], *ip;
863 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
868 while (*ip == ' ' || *ip == '\t')
875 if (*ip == 'y' || *ip == 'n')
876 return *ip == 'y' ? 1 : 0;
888 fc_cb(Pool *pool, Id p, void *cbdata)
890 struct fcstate *fcstate = cbdata;
898 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
901 s = pool_id2solvable(pool, p);
902 if (pool->installed && s->repo == pool->installed)
904 if (!s->repo->rpmdbid)
906 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
909 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
911 for (i = 0; i < fcstate->newpkgscnt; i++)
912 if (fcstate->checkq->elements[i] == p)
914 if (i == fcstate->newpkgscnt)
916 fp = fcstate->newpkgsfps[i];
920 return rpm_byfp(fp, solvable2str(pool, s), &fcstate->rpmdbstate);
924 runrpm(const char *arg, const char *name, int dupfd3)
929 if ((pid = fork()) == (pid_t)-1)
936 if (dupfd3 != -1 && dupfd3 != 3)
942 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
943 if (strcmp(arg, "-e") == 0)
944 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
946 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
950 while (waitpid(pid, &status, 0) != pid)
954 printf("rpm failed\n");
960 nscallback(Pool *pool, void *data, Id name, Id evr)
962 if (name == NAMESPACE_PRODUCTBUDDY)
964 /* SUSE specific hack: each product has an associated rpm */
965 Solvable *s = pool->solvables + evr;
968 cap = str2id(pool, pool_tmpjoin(pool, "product(", id2str(pool, s->name) + 8, ")"), 0);
971 cap = rel2id(pool, cap, s->evr, REL_EQ, 0);
974 FOR_PROVIDES(p, pp, cap)
976 Solvable *ps = pool->solvables + p;
977 if (ps->repo == s->repo && ps->arch == s->arch)
987 main(int argc, char **argv)
991 struct repoinfo *repoinfos;
993 int i, mode, newpkgs;
997 char inbuf[128], *ip;
1002 struct fcstate fcstate;
1008 fprintf(stderr, "Usage: solv install|erase|update|show <select>\n");
1011 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
1012 mode = SOLVER_INSTALL;
1013 else if (!strcmp(argv[0], "patch"))
1015 mode = SOLVER_UPDATE;
1018 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
1019 mode = SOLVER_ERASE;
1020 else if (!strcmp(argv[0], "show"))
1022 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
1023 mode = SOLVER_UPDATE;
1024 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
1026 mode = SOLVER_UPDATE;
1031 fprintf(stderr, "Usage: solv install|erase|update|show <select>\n");
1035 pool = pool_create();
1036 pool->nscallback = nscallback;
1037 // pool_setdebuglevel(pool, 2);
1039 repoinfos = read_repoinfos(pool, REPOINFO_PATH, &nrepoinfos);
1040 read_repos(pool, repoinfos, nrepoinfos);
1041 // FOR_REPOS(i, repo)
1042 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
1043 pool_addfileprovides(pool);
1044 pool_createwhatprovides(pool);
1047 for (i = 1; i < argc; i++)
1048 mkselect(pool, argv[i], 0, &job);
1049 if (!job.count && mode == SOLVER_UPDATE)
1051 else if (!job.count)
1053 printf("no package matched\n");
1059 /* show mode, no solver needed */
1060 for (i = 0; i < job.count; i += 2)
1062 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
1064 Solvable *s = pool_id2solvable(pool, p);
1065 printf(" - %s [%s]\n", solvable2str(pool, s), s->repo->name);
1071 if (updateall && patchmode)
1077 map_init(&installedmap, pool->nsolvables);
1078 if (pool->installed)
1079 FOR_REPO_SOLVABLES(pool->installed, p, s)
1080 MAPSET(&installedmap, p);
1082 /* install all patches */
1084 mode = SOLVER_INSTALL;
1085 for (p = 1; p < pool->nsolvables; p++)
1091 s = pool->solvables + p;
1092 if (strncmp(id2str(pool, s->name), "patch:", 6) != 0)
1094 FOR_PROVIDES(p2, pp, s->name)
1096 Solvable *s2 = pool->solvables + p2;
1097 if (s2->name != s->name)
1099 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
1100 if (r < 0 || (r == 0 && p > p2))
1105 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
1106 if (type && !strcmp(type, "optional"))
1108 r = solvable_trivial_installable_map(s, &installedmap, 0);
1111 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
1118 queue_push2(&job, SOLVER_SOLVABLE, p);
1120 map_free(&installedmap);
1124 for (i = 0; i < job.count; i += 2)
1125 job.elements[i] |= mode;
1127 // multiversion test
1128 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae", 1));
1129 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-base", 1));
1130 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-extra", 1));
1135 Id problem, solution;
1138 solv = solver_create(pool);
1139 solv->ignorealreadyrecommended = 1;
1140 solv->updatesystem = updateall;
1141 solv->dosplitprovides = updateall;
1142 if (updateall && distupgrade)
1144 solv->distupgrade = 1;
1145 solv->allowdowngrade = 1;
1146 solv->allowarchchange = 1;
1147 solv->allowvendorchange = 1;
1149 // queue_push2(&job, SOLVER_DISTUPGRADE, 3);
1150 solver_solve(solv, &job);
1151 if (!solv->problems.count)
1153 pcnt = solver_problem_count(solv);
1154 printf("Found %d problems:\n", pcnt);
1155 for (problem = 1; problem <= pcnt; problem++)
1158 printf("Problem %d:\n", problem);
1159 solver_printprobleminfo(solv, problem);
1161 scnt = solver_solution_count(solv, problem);
1162 for (solution = 1; solution <= scnt; solution++)
1164 printf("Solution %d:\n", solution);
1165 solver_printsolution(solv, problem, solution);
1170 printf("Please choose a solution: ");
1173 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
1178 while (*ip == ' ' || *ip == '\t')
1180 if (*ip >= '0' && *ip <= '9')
1183 if (take >= 1 && take <= scnt)
1199 solver_take_solution(solv, problem, take, &job);
1204 if (!solv->trans.steps.count)
1206 printf("Nothing to do.\n");
1210 printf("Transaction summary:\n\n");
1211 solver_printtransaction(solv);
1212 if (!yesno("OK to continue (y/n)? "))
1218 trans = &solv->trans;
1219 queue_init(&checkq);
1220 newpkgs = transaction_installedresult(trans, &checkq);
1225 printf("Downloading %d packages\n", newpkgs);
1226 newpkgsfps = sat_calloc(newpkgs, sizeof(*newpkgsfps));
1227 for (i = 0; i < newpkgs; i++)
1229 unsigned int medianr;
1232 struct repoinfo *cinfo;
1233 const unsigned char *chksum;
1236 p = checkq.elements[i];
1237 s = pool_id2solvable(pool, p);
1238 cinfo = s->repo->appdata;
1241 printf("%s: no repository information\n", s->repo->name);
1244 loc = solvable_get_location(s, &medianr);
1247 if (cinfo->type == TYPE_SUSETAGS)
1249 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
1250 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
1253 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
1254 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype)) == 0)
1256 printf("%s: %s not found in repository\n", s->repo->name, loc);
1266 printf("Searching for file conflicts\n");
1267 queue_init(&conflicts);
1268 fcstate.rpmdbstate = 0;
1269 fcstate.newpkgscnt = newpkgs;
1270 fcstate.checkq = &checkq;
1271 fcstate.newpkgsfps = newpkgsfps;
1272 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fc_cb, &fcstate);
1273 if (conflicts.count)
1276 for (i = 0; i < conflicts.count; i += 5)
1277 printf("file %s of package %s conflicts with package %s\n", id2str(pool, conflicts.elements[i]), solvid2str(pool, conflicts.elements[i + 1]), solvid2str(pool, conflicts.elements[i + 3]));
1279 if (yesno("Re-run solver (y/n/q)? "))
1281 for (i = 0; i < newpkgs; i++)
1283 fclose(newpkgsfps[i]);
1284 newpkgsfps = sat_free(newpkgsfps);
1286 pool_add_fileconflicts_deps(pool, &conflicts);
1287 pool_createwhatprovides(pool); /* Hmm... */
1291 queue_free(&conflicts);
1294 printf("Committing transaction:\n\n");
1295 transaction_order(trans, 0);
1296 for (i = 0; i < trans->steps.count; i++)
1298 const char *evr, *evrp, *nvra;
1303 p = trans->steps.elements[i];
1304 s = pool_id2solvable(pool, p);
1305 Id type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
1308 case SOLVER_TRANSACTION_ERASE:
1309 printf("erase %s\n", solvid2str(pool, p));
1310 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
1312 /* strip epoch from evr */
1313 evr = evrp = id2str(pool, s->evr);
1314 while (*evrp >= '0' && *evrp <= '9')
1316 if (evrp > evr && evrp[0] == ':' && evrp[1])
1318 nvra = pool_tmpjoin(pool, id2str(pool, s->name), "-", evr);
1319 nvra = pool_tmpjoin(pool, nvra, ".", id2str(pool, s->arch));
1320 runrpm("-e", nvra, -1); /* to bad that --querybynumber doesn't work */
1322 case SOLVER_TRANSACTION_INSTALL:
1323 case SOLVER_TRANSACTION_MULTIINSTALL:
1324 printf("install %s\n", solvid2str(pool, p));
1325 for (j = 0; j < newpkgs; j++)
1326 if (checkq.elements[j] == p)
1328 fp = j < newpkgs ? newpkgsfps[j] : 0;
1332 lseek(fileno(fp), 0, SEEK_SET);
1333 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp));
1342 for (i = 0; i < newpkgs; i++)
1344 fclose(newpkgsfps[i]);
1345 sat_free(newpkgsfps);
1346 queue_free(&checkq);