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
12 * - soft locks file handling
13 * - multi version handling
25 #include <sys/utsname.h>
26 #include <sys/types.h>
35 #include "solverdebug.h"
37 #include "repo_solv.h"
39 #include "repo_write.h"
40 #include "repo_rpmdb.h"
41 #include "repo_products.h"
42 #include "repo_rpmmd.h"
43 #include "repo_susetags.h"
44 #include "repo_repomdxml.h"
45 #include "repo_updateinfoxml.h"
46 #include "repo_deltainfoxml.h"
47 #include "repo_content.h"
48 #include "pool_fileconflicts.h"
52 # define REPOINFO_PATH "/etc/yum.repos.d"
54 # define REPOINFO_PATH "/etc/zypp/repos.d"
55 # define PRODUCTS_PATH "/etc/products.d"
58 #define SOLVCACHE_PATH "/var/cache/solv"
76 #define TYPE_UNKNOWN 0
77 #define TYPE_SUSETAGS 1
79 #define TYPE_PLAINDIR 3
82 read_repoinfos_sort(const void *ap, const void *bp)
84 const struct repoinfo *a = ap;
85 const struct repoinfo *b = bp;
86 return strcmp(a->alias, b->alias);
90 read_repoinfos(Pool *pool, const char *reposdir, int *nrepoinfosp)
93 char buf2[4096], *kp, *vp, *kpe;
98 struct repoinfo *repoinfos = 0, *cinfo;
101 rdlen = strlen(reposdir);
102 dir = opendir(reposdir);
108 while ((ent = readdir(dir)) != 0)
110 l = strlen(ent->d_name);
111 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
113 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
114 if ((fp = fopen(buf, "r")) == 0)
120 while(fgets(buf2, sizeof(buf2), fp))
125 while (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t')
128 while (*kp == ' ' || *kp == '\t')
130 if (!*kp || *kp == '#')
136 vp = strrchr(kp, ']');
140 repoinfos = sat_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
141 cinfo = repoinfos + nrepoinfos++;
142 memset(cinfo, 0, sizeof(*cinfo));
143 cinfo->alias = strdup(kp + 1);
145 cinfo->type = TYPE_RPMMD;
148 vp = strchr(kp, '=');
151 for (kpe = vp - 1; kpe >= kp; kpe--)
152 if (*kpe != ' ' && *kpe != '\t')
157 while (*vp == ' ' || *vp == '\t')
160 if (!strcmp(kp, "name"))
161 cinfo->name = strdup(vp);
162 else if (!strcmp(kp, "enabled"))
163 cinfo->enabled = *vp == '0' ? 0 : 1;
164 else if (!strcmp(kp, "autorefresh"))
165 cinfo->autorefresh = *vp == '0' ? 0 : 1;
166 else if (!strcmp(kp, "gpgcheck"))
167 cinfo->gpgcheck = *vp == '0' ? 0 : 1;
168 else if (!strcmp(kp, "baseurl"))
169 cinfo->baseurl = strdup(vp);
170 else if (!strcmp(kp, "path"))
172 if (vp && strcmp(vp, "/") != 0)
173 cinfo->path = strdup(vp);
175 else if (!strcmp(kp, "type"))
177 if (!strcmp(vp, "yast2"))
178 cinfo->type = TYPE_SUSETAGS;
179 else if (!strcmp(vp, "rpm-md"))
180 cinfo->type = TYPE_RPMMD;
181 else if (!strcmp(vp, "plaindir"))
182 cinfo->type = TYPE_PLAINDIR;
184 cinfo->type = TYPE_UNKNOWN;
186 else if (!strcmp(kp, "priority"))
187 cinfo->priority = atoi(vp);
188 else if (!strcmp(kp, "keeppackages"))
189 cinfo->keeppackages = *vp == '0' ? 0 : 1;
195 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
196 *nrepoinfosp = nrepoinfos;
201 cookie_gzread(void *cookie, char *buf, size_t nbytes)
203 return gzread((gzFile *)cookie, buf, nbytes);
207 cookie_gzclose(void *cookie)
209 return gzclose((gzFile *)cookie);
218 strcpy(tmpl, "/var/tmp/solvXXXXXX");
230 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
237 h = sat_chksum_create(chksumtype);
240 printf("%s: unknown checksum type\n", file);
243 while ((l = read(fd, buf, sizeof(buf))) > 0)
244 sat_chksum_add(h, buf, l);
245 lseek(fd, 0, SEEK_SET);
247 sum = sat_chksum_get(h, &l);
248 if (memcmp(sum, chksum, l))
250 printf("%s: checksum mismatch\n", file);
257 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype)
263 const char *baseurl = cinfo->baseurl;
266 if (l && baseurl[l - 1] == '/')
267 snprintf(url, sizeof(url), "%s%s", baseurl, file);
269 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
271 if ((pid = fork()) == (pid_t)-1)
283 execlp("curl", "curl", "-s", "-L", url, (char *)0);
287 while (waitpid(pid, &status, 0) != pid)
289 if (lseek(fd, 0, SEEK_END) == 0)
295 lseek(fd, 0, SEEK_SET);
296 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
304 cookie_io_functions_t cio;
307 sprintf(tmpl, "/dev/fd/%d", fd);
308 gzf = gzopen(tmpl, "r");
312 memset(&cio, 0, sizeof(cio));
313 cio.read = cookie_gzread;
314 cio.close = cookie_gzclose;
315 return fopencookie(gzf, "r", cio);
317 fcntl(fd, F_SETFD, FD_CLOEXEC);
318 return fdopen(fd, "r");
322 cleanupgpg(char *gpgdir)
325 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
327 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
329 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
331 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
333 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
339 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
348 off_t posfp, possigfp;
351 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
354 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
355 if (!(kfp = fopen(keysfile, "w")) )
360 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
364 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
365 if (!pubkey || !*pubkey)
367 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
369 if (fputc('\n', kfp) == EOF) /* Just in case... */
377 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --import %s", gpgdir, keysfile);
380 fprintf(stderr, "key import error\n");
385 posfp = lseek(fileno(fp), 0, SEEK_CUR);
386 lseek(fileno(fp), 0, SEEK_SET);
387 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
388 lseek(fileno(sigfp), 0, SEEK_SET);
389 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
390 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
391 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
393 lseek(fileno(sigfp), possigfp, SEEK_SET);
394 lseek(fileno(fp), posfp, SEEK_SET);
395 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
396 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
398 return r == 0 ? 1 : 0;
401 #define CHKSUM_IDENT "1.1"
404 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
407 void *h = sat_chksum_create(chktype);
410 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
411 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
412 sat_chksum_add(h, buf, l);
414 sat_chksum_free(h, out);
418 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *out)
420 void *h = sat_chksum_create(chktype);
421 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
422 sat_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
423 sat_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
424 sat_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
425 sat_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
426 sat_chksum_free(h, out);
438 pool_setarch(pool, un.machine);
441 char *calccachepath(Repo *repo)
443 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
444 p = pool_tmpjoin(repo->pool, p, ".solv", 0);
445 q = p + strlen(SOLVCACHE_PATH) + 1;
455 usecachedrepo(Repo *repo, unsigned char *cookie)
458 unsigned char mycookie[32];
460 if (!(fp = fopen(calccachepath(repo), "r")))
462 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
467 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
473 if (repo_add_solv(repo, fp))
483 writecachedrepo(Repo *repo, unsigned char *cookie)
485 Id *addedfileprovides = 0;
491 mkdir(SOLVCACHE_PATH, 0755);
492 tmpl = sat_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
500 if (!(fp = fdopen(fd, "w")))
507 info = repo_add_repodata(repo, 0);
508 pool_addfileprovides_ids(repo->pool, 0, &addedfileprovides);
509 if (addedfileprovides && *addedfileprovides)
511 for (i = 0; addedfileprovides[i]; i++)
512 repodata_add_idarray(info, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, addedfileprovides[i]);
514 sat_free(addedfileprovides);
515 repodata_internalize(info);
516 repo_write(repo, fp, 0, 0, 0);
518 if (fwrite(cookie, 32, 1, fp) != 1)
531 if (!rename(tmpl, calccachepath(repo)))
539 Pool *sigpool = pool_create();
540 Repo *repo = repo_create(sigpool, "rpmdbkeys");
541 repo_add_rpmdb_pubkeys(repo, 0, 0);
546 iscompressed(const char *name)
548 int l = strlen(name);
549 return l > 3 && !strcmp(name + l - 3, ".gz") ? 1 : 0;
552 static inline const char *
553 findinrepomd(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
555 Pool *pool = repo->pool;
557 const char *filename;
562 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
563 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
564 if (dataiterator_step(&di))
566 dataiterator_setpos_parent(&di);
567 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
568 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
570 dataiterator_free(&di);
571 if (filename && !*chksumtypep)
573 printf("no %s file checksum!\n", what);
580 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
583 struct repoinfo *cinfo;
587 const char *filename;
588 const unsigned char *filechksum;
590 const char *descrdir;
593 unsigned char cookie[32];
596 repo = repo_create(pool, "@System");
597 printf("rpm database:");
598 if (stat("/var/lib/rpm/Packages", &stb))
599 memset(&stb, 0, sizeof(&stb));
600 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cookie);
601 if (usecachedrepo(repo, cookie))
606 printf(" reading\n");
610 repo_add_products(repo, PRODUCTS_PATH, 0, REPO_NO_INTERNALIZE);
612 if ((ofp = fopen(calccachepath(repo), "r")) != 0)
614 Repo *ref = repo_create(pool, "@System.old");
615 if (!repo_add_solv(ref, ofp))
617 repo_add_rpmdb(repo, ref, 0, REPO_REUSE_REPODATA);
624 repo_add_rpmdb(repo, 0, 0, REPO_REUSE_REPODATA);
625 writecachedrepo(repo, cookie);
627 pool_set_installed(pool, repo);
629 for (i = 0; i < nrepoinfos; i++)
631 cinfo = repoinfos + i;
635 repo = repo_create(pool, cinfo->alias);
637 repo->appdata = cinfo;
638 repo->priority = 99 - cinfo->priority;
640 if (!cinfo->autorefresh && usecachedrepo(repo, 0))
642 printf("repo '%s':", cinfo->alias);
649 printf("rpmmd repo '%s':", cinfo->alias);
651 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0)) == 0)
653 printf(" no repomd.xml file, skipped\n");
658 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cookie);
659 if (usecachedrepo(repo, cookie))
668 if ((sigfp = curlfopen(cinfo, "repodata/repomd.xml.asc", 0, 0, 0)) == 0)
670 printf(" unsigned, skipped\n");
675 sigpool = read_sigs();
676 if (!checksig(sigpool, fp, sigfp))
678 printf(" checksig failed, skipped\n");
685 repo_add_repomdxml(repo, fp, 0);
687 printf(" reading\n");
688 filename = findinrepomd(repo, "primary", &filechksum, &filechksumtype);
689 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype)) != 0)
691 repo_add_rpmmd(repo, fp, 0, 0);
695 filename = findinrepomd(repo, "updateinfo", &filechksum, &filechksumtype);
696 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype)) != 0)
698 repo_add_updateinfoxml(repo, fp, 0);
702 filename = findinrepomd(repo, "deltainfo", &filechksum, &filechksumtype);
703 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype)) != 0)
705 repo_add_deltainfoxml(repo, fp, 0);
709 writecachedrepo(repo, cookie);
713 printf("susetags repo '%s':", cinfo->alias);
715 repo = repo_create(pool, cinfo->alias);
717 repo->appdata = cinfo;
718 repo->priority = 99 - cinfo->priority;
721 if ((fp = curlfopen(cinfo, "content", 0, 0, 0)) == 0)
723 printf(" no content file, skipped\n");
728 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cookie);
729 if (usecachedrepo(repo, cookie))
738 if ((sigfp = curlfopen(cinfo, "content.asc", 0, 0, 0)) == 0)
740 printf(" unsigned, skipped\n");
745 sigpool = read_sigs();
746 if (!checksig(sigpool, fp, sigfp))
748 printf(" checksig failed, skipped\n");
754 repo_add_content(repo, fp, 0);
756 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
757 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
759 descrdir = "suse/setup/descr";
761 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, "packages.gz", SEARCH_STRING);
762 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
763 if (dataiterator_step(&di))
765 dataiterator_setpos_parent(&di);
766 filechksum = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
767 filename = "packages.gz";
769 dataiterator_free(&di);
772 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, "packages", SEARCH_STRING);
773 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
774 if (dataiterator_step(&di))
776 dataiterator_setpos_parent(&di);
777 filechksum = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
778 filename = "packages";
780 dataiterator_free(&di);
784 printf(" no packages file entry, skipped\n");
789 printf(" no packages file checksum, skipped\n");
792 printf(" reading\n");
793 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype)) == 0)
795 repo_add_susetags(repo, fp, defvendor, 0, 0);
797 writecachedrepo(repo, cookie);
800 printf("unsupported repo '%s': skipped\n", cinfo->alias);
811 mkselect(Pool *pool, const char *arg, int flags, Queue *out)
817 id = str2id(pool, arg, 0);
820 FOR_PROVIDES(p, pp, id)
822 Solvable *s = pool_id2solvable(pool, p);
825 type = SOLVER_SOLVABLE_NAME;
828 type = SOLVER_SOLVABLE_PROVIDES;
833 /* did not find a solvable, see if it's a relation */
834 if ((r = strpbrk(arg, "<=>")) != 0)
838 for (r2 = r; r2 > arg && (r2[-1] == ' ' || r2[-1] == '\t'); )
840 rname = r2 > arg ? strn2id(pool, arg, r2 - arg, 1) : 0;
852 while (*r == ' ' || *r == '\t')
854 revr = *r ? str2id(pool, r, 1) : 0;
855 rid = rname && revr ? rel2id(pool, rname, revr, rflags, 1) : 0;
858 FOR_PROVIDES(p, pp, rid)
860 Solvable *s = pool_id2solvable(pool, p);
861 if (pool_match_nevr(pool, s, rid))
863 type = SOLVER_SOLVABLE_NAME;
866 type = SOLVER_SOLVABLE_PROVIDES;
875 queue_push(out, type);
881 yesno(const char *str)
883 char inbuf[128], *ip;
890 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
895 while (*ip == ' ' || *ip == '\t')
902 if (*ip == 'y' || *ip == 'n')
903 return *ip == 'y' ? 1 : 0;
915 fc_cb(Pool *pool, Id p, void *cbdata)
917 struct fcstate *fcstate = cbdata;
925 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
928 s = pool_id2solvable(pool, p);
929 if (pool->installed && s->repo == pool->installed)
931 if (!s->repo->rpmdbid)
933 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
936 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
938 for (i = 0; i < fcstate->newpkgscnt; i++)
939 if (fcstate->checkq->elements[i] == p)
941 if (i == fcstate->newpkgscnt)
943 fp = fcstate->newpkgsfps[i];
947 return rpm_byfp(fp, solvable2str(pool, s), &fcstate->rpmdbstate);
951 runrpm(const char *arg, const char *name, int dupfd3)
956 if ((pid = fork()) == (pid_t)-1)
963 if (dupfd3 != -1 && dupfd3 != 3)
969 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
970 if (strcmp(arg, "-e") == 0)
971 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
973 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
977 while (waitpid(pid, &status, 0) != pid)
981 printf("rpm failed\n");
987 nscallback(Pool *pool, void *data, Id name, Id evr)
989 if (name == NAMESPACE_PRODUCTBUDDY)
991 /* SUSE specific hack: each product has an associated rpm */
992 Solvable *s = pool->solvables + evr;
995 cap = str2id(pool, pool_tmpjoin(pool, "product(", id2str(pool, s->name) + 8, ")"), 0);
998 cap = rel2id(pool, cap, s->evr, REL_EQ, 0);
1001 FOR_PROVIDES(p, pp, cap)
1003 Solvable *ps = pool->solvables + p;
1004 if (ps->repo == s->repo && ps->arch == s->arch)
1014 main(int argc, char **argv)
1018 struct repoinfo *repoinfos;
1020 int i, mode, newpkgs;
1024 char inbuf[128], *ip;
1026 int distupgrade = 0;
1029 struct fcstate fcstate;
1035 fprintf(stderr, "Usage: solv install|erase|update|show <select>\n");
1038 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
1039 mode = SOLVER_INSTALL;
1040 else if (!strcmp(argv[0], "patch"))
1042 mode = SOLVER_UPDATE;
1045 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
1046 mode = SOLVER_ERASE;
1047 else if (!strcmp(argv[0], "show"))
1049 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
1050 mode = SOLVER_UPDATE;
1051 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
1053 mode = SOLVER_UPDATE;
1058 fprintf(stderr, "Usage: solv install|erase|update|show <select>\n");
1062 pool = pool_create();
1063 pool->nscallback = nscallback;
1064 // pool_setdebuglevel(pool, 2);
1066 repoinfos = read_repoinfos(pool, REPOINFO_PATH, &nrepoinfos);
1067 read_repos(pool, repoinfos, nrepoinfos);
1068 // FOR_REPOS(i, repo)
1069 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
1070 pool_addfileprovides(pool);
1071 pool_createwhatprovides(pool);
1074 for (i = 1; i < argc; i++)
1075 mkselect(pool, argv[i], 0, &job);
1076 if (!job.count && mode == SOLVER_UPDATE)
1078 else if (!job.count)
1080 printf("no package matched\n");
1086 /* show mode, no solver needed */
1087 for (i = 0; i < job.count; i += 2)
1089 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
1091 Solvable *s = pool_id2solvable(pool, p);
1092 printf(" - %s [%s]\n", solvable2str(pool, s), s->repo->name);
1098 if (updateall && patchmode)
1104 map_init(&installedmap, pool->nsolvables);
1105 if (pool->installed)
1106 FOR_REPO_SOLVABLES(pool->installed, p, s)
1107 MAPSET(&installedmap, p);
1109 /* install all patches */
1111 mode = SOLVER_INSTALL;
1112 for (p = 1; p < pool->nsolvables; p++)
1118 s = pool->solvables + p;
1119 if (strncmp(id2str(pool, s->name), "patch:", 6) != 0)
1121 FOR_PROVIDES(p2, pp, s->name)
1123 Solvable *s2 = pool->solvables + p2;
1124 if (s2->name != s->name)
1126 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
1127 if (r < 0 || (r == 0 && p > p2))
1132 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
1133 if (type && !strcmp(type, "optional"))
1135 r = solvable_trivial_installable_map(s, &installedmap, 0);
1138 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
1145 queue_push2(&job, SOLVER_SOLVABLE, p);
1147 map_free(&installedmap);
1151 for (i = 0; i < job.count; i += 2)
1152 job.elements[i] |= mode;
1154 // multiversion test
1155 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae", 1));
1156 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-base", 1));
1157 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-extra", 1));
1162 Id problem, solution;
1165 solv = solver_create(pool);
1166 solv->ignorealreadyrecommended = 1;
1167 solv->updatesystem = updateall;
1168 solv->dosplitprovides = updateall;
1169 if (updateall && distupgrade)
1171 solv->distupgrade = 1;
1172 solv->allowdowngrade = 1;
1173 solv->allowarchchange = 1;
1174 solv->allowvendorchange = 1;
1176 // queue_push2(&job, SOLVER_DISTUPGRADE, 3);
1177 solver_solve(solv, &job);
1178 if (!solv->problems.count)
1180 pcnt = solver_problem_count(solv);
1181 printf("Found %d problems:\n", pcnt);
1182 for (problem = 1; problem <= pcnt; problem++)
1185 printf("Problem %d:\n", problem);
1186 solver_printprobleminfo(solv, problem);
1188 scnt = solver_solution_count(solv, problem);
1189 for (solution = 1; solution <= scnt; solution++)
1191 printf("Solution %d:\n", solution);
1192 solver_printsolution(solv, problem, solution);
1197 printf("Please choose a solution: ");
1200 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
1205 while (*ip == ' ' || *ip == '\t')
1207 if (*ip >= '0' && *ip <= '9')
1210 if (take >= 1 && take <= scnt)
1226 solver_take_solution(solv, problem, take, &job);
1231 if (!solv->trans.steps.count)
1233 printf("Nothing to do.\n");
1237 printf("Transaction summary:\n\n");
1238 solver_printtransaction(solv);
1239 if (!yesno("OK to continue (y/n)? "))
1245 trans = &solv->trans;
1246 queue_init(&checkq);
1247 newpkgs = transaction_installedresult(trans, &checkq);
1252 printf("Downloading %d packages\n", newpkgs);
1253 newpkgsfps = sat_calloc(newpkgs, sizeof(*newpkgsfps));
1254 for (i = 0; i < newpkgs; i++)
1256 unsigned int medianr;
1259 struct repoinfo *cinfo;
1260 const unsigned char *chksum;
1264 p = checkq.elements[i];
1265 s = pool_id2solvable(pool, p);
1266 cinfo = s->repo->appdata;
1269 printf("%s: no repository information\n", s->repo->name);
1272 loc = solvable_get_location(s, &medianr);
1276 if (pool->installed && pool->installed->nsolvables)
1278 /* try a delta first */
1279 dataiterator_init(&di, pool, 0, SOLVID_META, DELTA_PACKAGE_NAME, id2str(pool, s->name), SEARCH_STRING);
1280 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
1281 while (dataiterator_step(&di))
1285 dataiterator_setpos_parent(&di);
1286 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
1287 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
1289 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
1290 FOR_PROVIDES(op, pp, s->name)
1292 Solvable *os = pool->solvables + op;
1293 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
1298 /* base is installed, run sequence check */
1299 const char *seqname;
1308 seqname = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME);
1309 seqevr = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR);
1310 seqnum = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM);
1311 seq = pool_tmpjoin(pool, seqname, "-", seqevr);
1312 seq = pool_tmpjoin(pool, seq, "-", seqnum);
1313 if (system(pool_tmpjoin(pool, "applydeltarpm -c -s ", seq, 0)) != 0)
1314 continue; /* didn't match */
1315 /* looks good, download delta */
1317 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
1319 continue; /* no way! */
1320 dloc = pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_DIR);
1321 dloc = pool_tmpjoin(pool, dloc, "/", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_NAME));
1322 dloc = pool_tmpjoin(pool, dloc, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_EVR));
1323 dloc = pool_tmpjoin(pool, dloc, ".", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_SUFFIX));
1324 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype)) == 0)
1326 /* got it, now reconstruct */
1327 newfd = opentmpfile();
1328 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
1329 fcntl(fileno(fp), F_SETFD, 0);
1336 lseek(newfd, 0, SEEK_SET);
1338 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
1339 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
1345 newpkgsfps[i] = fdopen(newfd, "r");
1350 dataiterator_free(&di);
1357 continue; /* delta worked! */
1359 if (cinfo->type == TYPE_SUSETAGS)
1361 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
1362 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
1365 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
1366 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype)) == 0)
1368 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
1381 printf("Searching for file conflicts\n");
1382 queue_init(&conflicts);
1383 fcstate.rpmdbstate = 0;
1384 fcstate.newpkgscnt = newpkgs;
1385 fcstate.checkq = &checkq;
1386 fcstate.newpkgsfps = newpkgsfps;
1387 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fc_cb, &fcstate);
1388 if (conflicts.count)
1391 for (i = 0; i < conflicts.count; i += 5)
1392 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]));
1394 if (yesno("Re-run solver (y/n/q)? "))
1396 for (i = 0; i < newpkgs; i++)
1398 fclose(newpkgsfps[i]);
1399 newpkgsfps = sat_free(newpkgsfps);
1401 pool_add_fileconflicts_deps(pool, &conflicts);
1402 pool_createwhatprovides(pool); /* Hmm... */
1406 queue_free(&conflicts);
1409 printf("Committing transaction:\n\n");
1410 transaction_order(trans, 0);
1411 for (i = 0; i < trans->steps.count; i++)
1413 const char *evr, *evrp, *nvra;
1418 p = trans->steps.elements[i];
1419 s = pool_id2solvable(pool, p);
1420 Id type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
1423 case SOLVER_TRANSACTION_ERASE:
1424 printf("erase %s\n", solvid2str(pool, p));
1425 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
1427 /* strip epoch from evr */
1428 evr = evrp = id2str(pool, s->evr);
1429 while (*evrp >= '0' && *evrp <= '9')
1431 if (evrp > evr && evrp[0] == ':' && evrp[1])
1433 nvra = pool_tmpjoin(pool, id2str(pool, s->name), "-", evr);
1434 nvra = pool_tmpjoin(pool, nvra, ".", id2str(pool, s->arch));
1435 runrpm("-e", nvra, -1); /* to bad that --querybynumber doesn't work */
1437 case SOLVER_TRANSACTION_INSTALL:
1438 case SOLVER_TRANSACTION_MULTIINSTALL:
1439 printf("install %s\n", solvid2str(pool, p));
1440 for (j = 0; j < newpkgs; j++)
1441 if (checkq.elements[j] == p)
1443 fp = j < newpkgs ? newpkgsfps[j] : 0;
1447 lseek(fileno(fp), 0, SEEK_SET);
1448 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp));
1457 for (i = 0; i < newpkgs; i++)
1459 fclose(newpkgsfps[i]);
1460 sat_free(newpkgsfps);
1461 queue_free(&checkq);