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 == '#')
134 vp = strrchr(kp, ']');
138 repoinfos = sat_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
139 cinfo = repoinfos + nrepoinfos++;
140 memset(cinfo, 0, sizeof(*cinfo));
141 cinfo->alias = strdup(kp + 1);
142 cinfo->type = TYPE_RPMMD;
147 vp = strchr(kp, '=');
150 for (kpe = vp - 1; kpe >= kp; kpe--)
151 if (*kpe != ' ' && *kpe != '\t')
156 while (*vp == ' ' || *vp == '\t')
159 if (!strcmp(kp, "name"))
160 cinfo->name = strdup(vp);
161 else if (!strcmp(kp, "enabled"))
162 cinfo->enabled = *vp == '0' ? 0 : 1;
163 else if (!strcmp(kp, "autorefresh"))
164 cinfo->autorefresh = *vp == '0' ? 0 : 1;
165 else if (!strcmp(kp, "gpgcheck"))
166 cinfo->gpgcheck = *vp == '0' ? 0 : 1;
167 else if (!strcmp(kp, "baseurl"))
168 cinfo->baseurl = strdup(vp);
169 else if (!strcmp(kp, "path"))
171 if (vp && strcmp(vp, "/") != 0)
172 cinfo->path = strdup(vp);
174 else if (!strcmp(kp, "type"))
176 if (!strcmp(vp, "yast2"))
177 cinfo->type = TYPE_SUSETAGS;
178 else if (!strcmp(vp, "rpm-md"))
179 cinfo->type = TYPE_RPMMD;
180 else if (!strcmp(vp, "plaindir"))
181 cinfo->type = TYPE_PLAINDIR;
183 cinfo->type = TYPE_UNKNOWN;
185 else if (!strcmp(kp, "priority"))
186 cinfo->priority = atoi(vp);
187 else if (!strcmp(kp, "keeppackages"))
188 cinfo->keeppackages = *vp == '0' ? 0 : 1;
194 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
195 *nrepoinfosp = nrepoinfos;
200 cookie_gzread(void *cookie, char *buf, size_t nbytes)
202 return gzread((gzFile *)cookie, buf, nbytes);
206 cookie_gzclose(void *cookie)
208 return gzclose((gzFile *)cookie);
217 strcpy(tmpl, "/var/tmp/solvXXXXXX");
229 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
236 h = sat_chksum_create(chksumtype);
239 printf("%s: unknown checksum type\n", file);
242 while ((l = read(fd, buf, sizeof(buf))) > 0)
243 sat_chksum_add(h, buf, l);
244 lseek(fd, 0, SEEK_SET);
246 sum = sat_chksum_get(h, &l);
247 if (memcmp(sum, chksum, l))
249 printf("%s: checksum mismatch\n", file);
256 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype)
262 const char *baseurl = cinfo->baseurl;
267 if (l && baseurl[l - 1] == '/')
268 snprintf(url, sizeof(url), "%s%s", baseurl, file);
270 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
272 if ((pid = fork()) == (pid_t)-1)
284 execlp("curl", "curl", "-s", "-L", url, (char *)0);
288 while (waitpid(pid, &status, 0) != pid)
290 if (lseek(fd, 0, SEEK_END) == 0)
296 lseek(fd, 0, SEEK_SET);
297 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
305 cookie_io_functions_t cio;
308 sprintf(tmpl, "/dev/fd/%d", fd);
309 gzf = gzopen(tmpl, "r");
313 memset(&cio, 0, sizeof(cio));
314 cio.read = cookie_gzread;
315 cio.close = cookie_gzclose;
316 return fopencookie(gzf, "r", cio);
318 fcntl(fd, F_SETFD, FD_CLOEXEC);
319 return fdopen(fd, "r");
323 cleanupgpg(char *gpgdir)
326 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
328 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
330 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
332 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
334 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
340 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
349 off_t posfp, possigfp;
352 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
355 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
356 if (!(kfp = fopen(keysfile, "w")) )
362 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
366 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
367 if (!pubkey || !*pubkey)
369 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
371 if (fputc('\n', kfp) == EOF) /* Just in case... */
375 if (fclose(kfp) || !nkeys)
380 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --import %s", gpgdir, keysfile);
383 fprintf(stderr, "key import error\n");
388 posfp = lseek(fileno(fp), 0, SEEK_CUR);
389 lseek(fileno(fp), 0, SEEK_SET);
390 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
391 lseek(fileno(sigfp), 0, SEEK_SET);
392 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
393 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
394 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
396 lseek(fileno(sigfp), possigfp, SEEK_SET);
397 lseek(fileno(fp), posfp, SEEK_SET);
398 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
399 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
401 return r == 0 ? 1 : 0;
404 #define CHKSUM_IDENT "1.1"
407 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
410 void *h = sat_chksum_create(chktype);
413 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
414 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
415 sat_chksum_add(h, buf, l);
417 sat_chksum_free(h, out);
421 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *out)
423 void *h = sat_chksum_create(chktype);
424 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
425 sat_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
426 sat_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
427 sat_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
428 sat_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
429 sat_chksum_free(h, out);
441 pool_setarch(pool, un.machine);
444 char *calccachepath(Repo *repo)
446 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
447 p = pool_tmpjoin(repo->pool, p, ".solv", 0);
448 q = p + strlen(SOLVCACHE_PATH) + 1;
458 usecachedrepo(Repo *repo, unsigned char *cookie)
461 unsigned char mycookie[32];
463 if (!(fp = fopen(calccachepath(repo), "r")))
465 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
470 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
476 if (repo_add_solv(repo, fp))
486 writecachedrepo(Repo *repo, unsigned char *cookie)
488 Id *addedfileprovides = 0;
494 mkdir(SOLVCACHE_PATH, 0755);
495 tmpl = sat_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
503 if (!(fp = fdopen(fd, "w")))
510 info = repo_add_repodata(repo, 0);
511 pool_addfileprovides_ids(repo->pool, 0, &addedfileprovides);
512 if (addedfileprovides && *addedfileprovides)
514 for (i = 0; addedfileprovides[i]; i++)
515 repodata_add_idarray(info, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, addedfileprovides[i]);
517 sat_free(addedfileprovides);
518 repodata_internalize(info);
519 repo_write(repo, fp, 0, 0, 0);
520 repo_free_repodata(repo, info);
521 if (fwrite(cookie, 32, 1, fp) != 1)
534 if (!rename(tmpl, calccachepath(repo)))
542 Pool *sigpool = pool_create();
543 Repo *repo = repo_create(sigpool, "rpmdbkeys");
544 repo_add_rpmdb_pubkeys(repo, 0, 0);
549 iscompressed(const char *name)
551 int l = strlen(name);
552 return l > 3 && !strcmp(name + l - 3, ".gz") ? 1 : 0;
555 static inline const char *
556 findinrepomd(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
558 Pool *pool = repo->pool;
560 const char *filename;
565 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
566 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
567 if (dataiterator_step(&di))
569 dataiterator_setpos_parent(&di);
570 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
571 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
573 dataiterator_free(&di);
574 if (filename && !*chksumtypep)
576 printf("no %s file checksum!\n", what);
583 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
586 struct repoinfo *cinfo;
591 const char *filename;
592 const unsigned char *filechksum;
594 const char *descrdir;
597 unsigned char cookie[32];
600 repo = repo_create(pool, "@System");
601 printf("rpm database:");
602 if (stat("/var/lib/rpm/Packages", &stb))
603 memset(&stb, 0, sizeof(&stb));
604 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cookie);
605 if (usecachedrepo(repo, cookie))
610 printf(" reading\n");
614 repo_add_products(repo, PRODUCTS_PATH, 0, REPO_NO_INTERNALIZE);
616 if ((ofp = fopen(calccachepath(repo), "r")) != 0)
618 Repo *ref = repo_create(pool, "@System.old");
619 if (!repo_add_solv(ref, ofp))
621 repo_add_rpmdb(repo, ref, 0, REPO_REUSE_REPODATA);
628 repo_add_rpmdb(repo, 0, 0, REPO_REUSE_REPODATA);
629 writecachedrepo(repo, cookie);
631 pool_set_installed(pool, repo);
633 for (i = 0; i < nrepoinfos; i++)
635 cinfo = repoinfos + i;
639 repo = repo_create(pool, cinfo->alias);
641 repo->appdata = cinfo;
642 repo->priority = 99 - cinfo->priority;
644 if (!cinfo->autorefresh && usecachedrepo(repo, 0))
646 printf("repo '%s':", cinfo->alias);
653 printf("rpmmd repo '%s':", cinfo->alias);
655 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0)) == 0)
657 printf(" no repomd.xml file, skipped\n");
662 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cookie);
663 if (usecachedrepo(repo, cookie))
669 sigfp = curlfopen(cinfo, "repodata/repomd.xml.asc", 0, 0, 0);
673 printf(" unsigned, skipped\n");
681 sigpool = read_sigs();
682 if (!checksig(sigpool, fp, sigfp))
684 printf(" checksig failed, skipped\n");
691 repo_add_repomdxml(repo, fp, 0);
693 printf(" reading\n");
694 filename = findinrepomd(repo, "primary", &filechksum, &filechksumtype);
695 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype)) != 0)
697 repo_add_rpmmd(repo, fp, 0, 0);
701 filename = findinrepomd(repo, "updateinfo", &filechksum, &filechksumtype);
702 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype)) != 0)
704 repo_add_updateinfoxml(repo, fp, 0);
708 filename = findinrepomd(repo, "deltainfo", &filechksum, &filechksumtype);
710 filename = findinrepomd(repo, "prestodelta", &filechksum, &filechksumtype);
711 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype)) != 0)
713 repo_add_deltainfoxml(repo, fp, 0);
717 writecachedrepo(repo, cookie);
721 printf("susetags repo '%s':", cinfo->alias);
723 repo = repo_create(pool, cinfo->alias);
725 repo->appdata = cinfo;
726 repo->priority = 99 - cinfo->priority;
729 if ((fp = curlfopen(cinfo, "content", 0, 0, 0)) == 0)
731 printf(" no content file, skipped\n");
736 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cookie);
737 if (usecachedrepo(repo, cookie))
743 sigfp = curlfopen(cinfo, "content.asc", 0, 0, 0);
746 printf(" unsigned, skipped\n");
753 sigpool = read_sigs();
754 if (!checksig(sigpool, fp, sigfp))
756 printf(" checksig failed, skipped\n");
763 repo_add_content(repo, fp, 0);
765 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
766 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
768 descrdir = "suse/setup/descr";
770 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, "packages.gz", SEARCH_STRING);
771 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
772 if (dataiterator_step(&di))
774 dataiterator_setpos_parent(&di);
775 filechksum = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
776 filename = "packages.gz";
778 dataiterator_free(&di);
781 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, "packages", SEARCH_STRING);
782 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
783 if (dataiterator_step(&di))
785 dataiterator_setpos_parent(&di);
786 filechksum = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
787 filename = "packages";
789 dataiterator_free(&di);
793 printf(" no packages file entry, skipped\n");
798 printf(" no packages file checksum, skipped\n");
801 printf(" reading\n");
802 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype)) == 0)
804 repo_add_susetags(repo, fp, defvendor, 0, 0);
806 writecachedrepo(repo, cookie);
809 printf("unsupported repo '%s': skipped\n", cinfo->alias);
820 mkselect(Pool *pool, const char *arg, int flags, Queue *out)
826 id = str2id(pool, arg, 0);
829 FOR_PROVIDES(p, pp, id)
831 Solvable *s = pool_id2solvable(pool, p);
834 type = SOLVER_SOLVABLE_NAME;
837 type = SOLVER_SOLVABLE_PROVIDES;
842 /* did not find a solvable, see if it's a relation */
843 if ((r = strpbrk(arg, "<=>")) != 0)
847 for (r2 = r; r2 > arg && (r2[-1] == ' ' || r2[-1] == '\t'); )
849 rname = r2 > arg ? strn2id(pool, arg, r2 - arg, 1) : 0;
861 while (*r == ' ' || *r == '\t')
863 revr = *r ? str2id(pool, r, 1) : 0;
864 rid = rname && revr ? rel2id(pool, rname, revr, rflags, 1) : 0;
867 FOR_PROVIDES(p, pp, rid)
869 Solvable *s = pool_id2solvable(pool, p);
870 if (pool_match_nevr(pool, s, rid))
872 type = SOLVER_SOLVABLE_NAME;
875 type = SOLVER_SOLVABLE_PROVIDES;
884 queue_push(out, type);
890 yesno(const char *str)
892 char inbuf[128], *ip;
899 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
904 while (*ip == ' ' || *ip == '\t')
911 if (*ip == 'y' || *ip == 'n')
912 return *ip == 'y' ? 1 : 0;
924 fc_cb(Pool *pool, Id p, void *cbdata)
926 struct fcstate *fcstate = cbdata;
934 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
937 s = pool_id2solvable(pool, p);
938 if (pool->installed && s->repo == pool->installed)
940 if (!s->repo->rpmdbid)
942 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
945 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
947 for (i = 0; i < fcstate->newpkgscnt; i++)
948 if (fcstate->checkq->elements[i] == p)
950 if (i == fcstate->newpkgscnt)
952 fp = fcstate->newpkgsfps[i];
956 return rpm_byfp(fp, solvable2str(pool, s), &fcstate->rpmdbstate);
960 runrpm(const char *arg, const char *name, int dupfd3)
965 if ((pid = fork()) == (pid_t)-1)
972 if (dupfd3 != -1 && dupfd3 != 3)
978 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
979 if (strcmp(arg, "-e") == 0)
980 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
982 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
986 while (waitpid(pid, &status, 0) != pid)
990 printf("rpm failed\n");
996 nscallback(Pool *pool, void *data, Id name, Id evr)
998 if (name == NAMESPACE_PRODUCTBUDDY)
1000 /* SUSE specific hack: each product has an associated rpm */
1001 Solvable *s = pool->solvables + evr;
1004 cap = str2id(pool, pool_tmpjoin(pool, "product(", id2str(pool, s->name) + 8, ")"), 0);
1007 cap = rel2id(pool, cap, s->evr, REL_EQ, 0);
1010 FOR_PROVIDES(p, pp, cap)
1012 Solvable *ps = pool->solvables + p;
1013 if (ps->repo == s->repo && ps->arch == s->arch)
1023 main(int argc, char **argv)
1027 struct repoinfo *repoinfos;
1029 int i, mode, newpkgs;
1033 char inbuf[128], *ip;
1035 int distupgrade = 0;
1038 struct fcstate fcstate;
1044 fprintf(stderr, "Usage: solv install|erase|update|show <select>\n");
1047 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
1048 mode = SOLVER_INSTALL;
1049 else if (!strcmp(argv[0], "patch"))
1051 mode = SOLVER_UPDATE;
1054 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
1055 mode = SOLVER_ERASE;
1056 else if (!strcmp(argv[0], "show"))
1058 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
1059 mode = SOLVER_UPDATE;
1060 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
1062 mode = SOLVER_UPDATE;
1067 fprintf(stderr, "Usage: solv install|erase|update|show <select>\n");
1071 pool = pool_create();
1072 pool->nscallback = nscallback;
1073 // pool_setdebuglevel(pool, 2);
1075 repoinfos = read_repoinfos(pool, REPOINFO_PATH, &nrepoinfos);
1076 read_repos(pool, repoinfos, nrepoinfos);
1077 // FOR_REPOS(i, repo)
1078 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
1079 pool_addfileprovides(pool);
1080 pool_createwhatprovides(pool);
1083 for (i = 1; i < argc; i++)
1084 mkselect(pool, argv[i], 0, &job);
1085 if (!job.count && mode == SOLVER_UPDATE)
1087 else if (!job.count)
1089 printf("no package matched\n");
1095 /* show mode, no solver needed */
1096 for (i = 0; i < job.count; i += 2)
1098 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
1100 Solvable *s = pool_id2solvable(pool, p);
1101 printf(" - %s [%s]\n", solvable2str(pool, s), s->repo->name);
1107 if (updateall && patchmode)
1113 map_init(&installedmap, pool->nsolvables);
1114 if (pool->installed)
1115 FOR_REPO_SOLVABLES(pool->installed, p, s)
1116 MAPSET(&installedmap, p);
1118 /* install all patches */
1120 mode = SOLVER_INSTALL;
1121 for (p = 1; p < pool->nsolvables; p++)
1127 s = pool->solvables + p;
1128 if (strncmp(id2str(pool, s->name), "patch:", 6) != 0)
1130 FOR_PROVIDES(p2, pp, s->name)
1132 Solvable *s2 = pool->solvables + p2;
1133 if (s2->name != s->name)
1135 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
1136 if (r < 0 || (r == 0 && p > p2))
1141 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
1142 if (type && !strcmp(type, "optional"))
1144 r = solvable_trivial_installable_map(s, &installedmap, 0);
1147 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
1154 queue_push2(&job, SOLVER_SOLVABLE, p);
1156 map_free(&installedmap);
1160 for (i = 0; i < job.count; i += 2)
1161 job.elements[i] |= mode;
1163 // multiversion test
1164 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae", 1));
1165 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-base", 1));
1166 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-extra", 1));
1171 Id problem, solution;
1174 solv = solver_create(pool);
1175 solv->ignorealreadyrecommended = 1;
1176 solv->updatesystem = updateall;
1177 solv->dosplitprovides = updateall;
1178 if (updateall && distupgrade)
1180 solv->distupgrade = 1;
1181 solv->allowdowngrade = 1;
1182 solv->allowarchchange = 1;
1183 solv->allowvendorchange = 1;
1185 // queue_push2(&job, SOLVER_DISTUPGRADE, 3);
1186 solver_solve(solv, &job);
1187 if (!solv->problems.count)
1189 pcnt = solver_problem_count(solv);
1190 printf("Found %d problems:\n", pcnt);
1191 for (problem = 1; problem <= pcnt; problem++)
1194 printf("Problem %d:\n", problem);
1195 solver_printprobleminfo(solv, problem);
1197 scnt = solver_solution_count(solv, problem);
1198 for (solution = 1; solution <= scnt; solution++)
1200 printf("Solution %d:\n", solution);
1201 solver_printsolution(solv, problem, solution);
1206 printf("Please choose a solution: ");
1209 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
1214 while (*ip == ' ' || *ip == '\t')
1216 if (*ip >= '0' && *ip <= '9')
1219 if (take >= 1 && take <= scnt)
1235 solver_take_solution(solv, problem, take, &job);
1240 if (!solv->trans.steps.count)
1242 printf("Nothing to do.\n");
1246 printf("Transaction summary:\n\n");
1247 solver_printtransaction(solv);
1248 if (!yesno("OK to continue (y/n)? "))
1254 trans = &solv->trans;
1255 queue_init(&checkq);
1256 newpkgs = transaction_installedresult(trans, &checkq);
1261 printf("Downloading %d packages\n", newpkgs);
1262 newpkgsfps = sat_calloc(newpkgs, sizeof(*newpkgsfps));
1263 for (i = 0; i < newpkgs; i++)
1265 unsigned int medianr;
1268 struct repoinfo *cinfo;
1269 const unsigned char *chksum;
1273 p = checkq.elements[i];
1274 s = pool_id2solvable(pool, p);
1275 cinfo = s->repo->appdata;
1278 printf("%s: no repository information\n", s->repo->name);
1281 loc = solvable_get_location(s, &medianr);
1285 if (pool->installed && pool->installed->nsolvables)
1287 /* try a delta first */
1288 dataiterator_init(&di, pool, 0, SOLVID_META, DELTA_PACKAGE_NAME, id2str(pool, s->name), SEARCH_STRING);
1289 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
1290 while (dataiterator_step(&di))
1294 dataiterator_setpos_parent(&di);
1295 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
1296 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
1298 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
1299 FOR_PROVIDES(op, pp, s->name)
1301 Solvable *os = pool->solvables + op;
1302 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
1307 /* base is installed, run sequence check */
1308 const char *seqname;
1317 seqname = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME);
1318 seqevr = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR);
1319 seqnum = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM);
1320 seq = pool_tmpjoin(pool, seqname, "-", seqevr);
1321 seq = pool_tmpjoin(pool, seq, "-", seqnum);
1322 if (system(pool_tmpjoin(pool, "applydeltarpm -c -s ", seq, 0)) != 0)
1323 continue; /* didn't match */
1324 /* looks good, download delta */
1326 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
1328 continue; /* no way! */
1329 dloc = pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_DIR);
1330 dloc = pool_tmpjoin(pool, dloc, "/", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_NAME));
1331 dloc = pool_tmpjoin(pool, dloc, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_EVR));
1332 dloc = pool_tmpjoin(pool, dloc, ".", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_SUFFIX));
1333 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype)) == 0)
1335 /* got it, now reconstruct */
1336 newfd = opentmpfile();
1337 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
1338 fcntl(fileno(fp), F_SETFD, 0);
1345 lseek(newfd, 0, SEEK_SET);
1347 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
1348 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
1354 newpkgsfps[i] = fdopen(newfd, "r");
1359 dataiterator_free(&di);
1366 continue; /* delta worked! */
1368 if (cinfo->type == TYPE_SUSETAGS)
1370 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
1371 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
1374 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
1375 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype)) == 0)
1377 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
1390 printf("Searching for file conflicts\n");
1391 queue_init(&conflicts);
1392 fcstate.rpmdbstate = 0;
1393 fcstate.newpkgscnt = newpkgs;
1394 fcstate.checkq = &checkq;
1395 fcstate.newpkgsfps = newpkgsfps;
1396 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fc_cb, &fcstate);
1397 if (conflicts.count)
1400 for (i = 0; i < conflicts.count; i += 5)
1401 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]));
1403 if (yesno("Re-run solver (y/n/q)? "))
1405 for (i = 0; i < newpkgs; i++)
1407 fclose(newpkgsfps[i]);
1408 newpkgsfps = sat_free(newpkgsfps);
1410 pool_add_fileconflicts_deps(pool, &conflicts);
1411 pool_createwhatprovides(pool); /* Hmm... */
1415 queue_free(&conflicts);
1418 printf("Committing transaction:\n\n");
1419 transaction_order(trans, 0);
1420 for (i = 0; i < trans->steps.count; i++)
1422 const char *evr, *evrp, *nvra;
1427 p = trans->steps.elements[i];
1428 s = pool_id2solvable(pool, p);
1429 Id type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
1432 case SOLVER_TRANSACTION_ERASE:
1433 printf("erase %s\n", solvid2str(pool, p));
1434 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
1436 /* strip epoch from evr */
1437 evr = evrp = id2str(pool, s->evr);
1438 while (*evrp >= '0' && *evrp <= '9')
1440 if (evrp > evr && evrp[0] == ':' && evrp[1])
1442 nvra = pool_tmpjoin(pool, id2str(pool, s->name), "-", evr);
1443 nvra = pool_tmpjoin(pool, nvra, ".", id2str(pool, s->arch));
1444 runrpm("-e", nvra, -1); /* to bad that --querybynumber doesn't work */
1446 case SOLVER_TRANSACTION_INSTALL:
1447 case SOLVER_TRANSACTION_MULTIINSTALL:
1448 printf("install %s\n", solvid2str(pool, p));
1449 for (j = 0; j < newpkgs; j++)
1450 if (checkq.elements[j] == p)
1452 fp = j < newpkgs ? newpkgsfps[j] : 0;
1456 lseek(fileno(fp), 0, SEEK_SET);
1457 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp));
1466 for (i = 0; i < newpkgs; i++)
1468 fclose(newpkgsfps[i]);
1469 sat_free(newpkgsfps);
1470 queue_free(&checkq);