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 * - understands globs for package names / dependencies
12 * - understands .arch suffix
13 * - installation of commandline packages
14 * - repository data caching
15 * - on demand loading of secondary repository data
16 * - gpg and checksum verification
19 * - fastestmirror implementation
21 * things available in the library but missing from solv:
22 * - vendor policy loading
23 * - soft locks file handling
24 * - multi version handling
37 #include <sys/utsname.h>
38 #include <sys/types.h>
43 #include <sys/socket.h>
55 #include "solverdebug.h"
57 #include "repo_solv.h"
59 #include "repo_write.h"
61 #include "repo_rpmdb.h"
65 #include "repo_products.h"
66 #include "repo_rpmmd.h"
67 #include "repo_susetags.h"
68 #include "repo_repomdxml.h"
69 #include "repo_updateinfoxml.h"
70 #include "repo_deltainfoxml.h"
71 #include "repo_content.h"
72 #include "pool_fileconflicts.h"
76 # define REPOINFO_PATH "/etc/yum.repos.d"
78 # define REPOINFO_PATH "/etc/zypp/repos.d"
79 # define PRODUCTS_PATH "/etc/products.d"
80 # define SOFTLOCKS_PATH "/var/lib/zypp/SoftLocks"
83 #define SOLVCACHE_PATH "/var/cache/solv"
85 #define METADATA_EXPIRE (60 * 90)
107 unsigned char cookie[32];
108 unsigned char extcookie[32];
113 yum_substitute(Pool *pool, char *line)
116 static char *releaseevr;
117 static char *basearch;
121 sat_free(releaseevr);
128 while ((p2 = strchr(p, '$')) != 0)
130 if (!strncmp(p2, "$releasever", 11))
137 rpm_installedrpmdbids(0, "Providename", "redhat-release", &q);
140 void *handle, *state = 0;
142 handle = rpm_byrpmdbid(q.elements[0], 0, &state);
143 releaseevr = rpm_query(handle, SOLVABLE_EVR);
144 rpm_byrpmdbid(0, 0, &state);
145 if ((p = strchr(releaseevr, '-')) != 0)
150 releaseevr = strdup("?");
153 p = pool_tmpjoin(pool, line, releaseevr, p2 + 11);
154 p2 = p + (p2 - line);
156 p = p2 + strlen(releaseevr);
159 if (!strncmp(p2, "$basearch", 9))
169 basearch = strdup(un.machine);
170 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
174 p = pool_tmpjoin(pool, line, basearch, p2 + 9);
175 p2 = p + (p2 - line);
177 p = p2 + strlen(basearch);
186 #define TYPE_UNKNOWN 0
187 #define TYPE_SUSETAGS 1
189 #define TYPE_PLAINDIR 3
190 #define TYPE_DEBIAN 4
193 read_repoinfos_sort(const void *ap, const void *bp)
195 const struct repoinfo *a = ap;
196 const struct repoinfo *b = bp;
197 return strcmp(a->alias, b->alias);
203 read_repoinfos(Pool *pool, const char *reposdir, int *nrepoinfosp)
206 char buf2[4096], *kp, *vp, *kpe;
211 struct repoinfo *repoinfos = 0, *cinfo;
214 rdlen = strlen(reposdir);
215 dir = opendir(reposdir);
221 while ((ent = readdir(dir)) != 0)
223 l = strlen(ent->d_name);
224 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
226 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
227 if ((fp = fopen(buf, "r")) == 0)
233 while(fgets(buf2, sizeof(buf2), fp))
238 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
241 while (*kp == ' ' || *kp == '\t')
243 if (!*kp || *kp == '#')
247 kp = yum_substitute(pool, kp);
251 vp = strrchr(kp, ']');
255 repoinfos = sat_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
256 cinfo = repoinfos + nrepoinfos++;
257 memset(cinfo, 0, sizeof(*cinfo));
258 cinfo->alias = strdup(kp + 1);
259 cinfo->type = TYPE_RPMMD;
260 cinfo->autorefresh = 1;
261 cinfo->priority = 99;
263 cinfo->repo_gpgcheck = 1;
265 cinfo->metadata_expire = METADATA_EXPIRE;
270 vp = strchr(kp, '=');
273 for (kpe = vp - 1; kpe >= kp; kpe--)
274 if (*kpe != ' ' && *kpe != '\t')
279 while (*vp == ' ' || *vp == '\t')
282 if (!strcmp(kp, "name"))
283 cinfo->name = strdup(vp);
284 else if (!strcmp(kp, "enabled"))
285 cinfo->enabled = *vp == '0' ? 0 : 1;
286 else if (!strcmp(kp, "autorefresh"))
287 cinfo->autorefresh = *vp == '0' ? 0 : 1;
288 else if (!strcmp(kp, "gpgcheck"))
289 cinfo->pkgs_gpgcheck = *vp == '0' ? 0 : 1;
290 else if (!strcmp(kp, "repo_gpgcheck"))
291 cinfo->repo_gpgcheck = *vp == '0' ? 0 : 1;
292 else if (!strcmp(kp, "baseurl"))
293 cinfo->baseurl = strdup(vp);
294 else if (!strcmp(kp, "mirrorlist"))
296 if (strstr(vp, "metalink"))
297 cinfo->metalink = strdup(vp);
299 cinfo->mirrorlist = strdup(vp);
301 else if (!strcmp(kp, "path"))
303 if (vp && strcmp(vp, "/") != 0)
304 cinfo->path = strdup(vp);
306 else if (!strcmp(kp, "type"))
308 if (!strcmp(vp, "yast2"))
309 cinfo->type = TYPE_SUSETAGS;
310 else if (!strcmp(vp, "rpm-md"))
311 cinfo->type = TYPE_RPMMD;
312 else if (!strcmp(vp, "plaindir"))
313 cinfo->type = TYPE_PLAINDIR;
315 cinfo->type = TYPE_UNKNOWN;
317 else if (!strcmp(kp, "priority"))
318 cinfo->priority = atoi(vp);
319 else if (!strcmp(kp, "keeppackages"))
320 cinfo->keeppackages = *vp == '0' ? 0 : 1;
326 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
327 *nrepoinfosp = nrepoinfos;
334 read_repoinfos(Pool *pool, const char *reposdir, int *nrepoinfosp)
340 char *kp, *url, *distro;
341 struct repoinfo *repoinfos = 0, *cinfo;
346 fp = fopen("/etc/apt/sources.list", "r");
353 dir = opendir("/etc/apt/sources.list.d");
357 if ((ent = readdir(dir)) == 0)
362 l = strlen(ent->d_name);
363 if (l < 5 || strcmp(ent->d_name + l - 5, ".list") != 0)
365 snprintf(buf, sizeof(buf), "%s/%s", "/etc/apt/sources.list.d", ent->d_name);
366 if (!(fp = fopen(buf, "r")))
369 while(fgets(buf2, sizeof(buf2), fp))
374 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
377 while (*kp == ' ' || *kp == '\t')
379 if (!*kp || *kp == '#')
381 if (strncmp(kp, "deb", 3) != 0)
384 if (*kp != ' ' && *kp != '\t')
386 while (*kp == ' ' || *kp == '\t')
391 while (*kp && *kp != ' ' && *kp != '\t')
395 while (*kp == ' ' || *kp == '\t')
400 while (*kp && *kp != ' ' && *kp != '\t')
404 while (*kp == ' ' || *kp == '\t')
408 repoinfos = sat_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
409 cinfo = repoinfos + nrepoinfos++;
410 memset(cinfo, 0, sizeof(*cinfo));
411 cinfo->baseurl = strdup(url);
412 cinfo->alias = sat_dupjoin(url, "/", distro);
413 cinfo->name = strdup(distro);
414 cinfo->type = TYPE_DEBIAN;
416 cinfo->autorefresh = 1;
417 cinfo->repo_gpgcheck = 1;
418 cinfo->metadata_expire = METADATA_EXPIRE;
422 while (*kp == ' ' || *kp == '\t')
427 while (*kp && *kp != ' ' && *kp != '\t')
431 cinfo->components = sat_extend(cinfo->components, cinfo->ncomponents, 1, sizeof(*cinfo->components), 15);
432 cinfo->components[cinfo->ncomponents++] = strdup(compo);
438 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
439 *nrepoinfosp = nrepoinfos;
446 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
449 for (i = 0; i < nrepoinfos; i++)
451 struct repoinfo *cinfo = repoinfos + i;
452 sat_free(cinfo->name);
453 sat_free(cinfo->alias);
454 sat_free(cinfo->path);
455 sat_free(cinfo->metalink);
456 sat_free(cinfo->mirrorlist);
457 sat_free(cinfo->baseurl);
458 for (j = 0; j < cinfo->ncomponents; j++)
459 sat_free(cinfo->components[j]);
460 sat_free(cinfo->components);
471 strcpy(tmpl, "/var/tmp/solvXXXXXX");
483 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
490 h = sat_chksum_create(chksumtype);
493 printf("%s: unknown checksum type\n", file);
496 while ((l = read(fd, buf, sizeof(buf))) > 0)
497 sat_chksum_add(h, buf, l);
498 lseek(fd, 0, SEEK_SET);
500 sum = sat_chksum_get(h, &l);
501 if (memcmp(sum, chksum, l))
503 printf("%s: checksum mismatch\n", file);
504 sat_chksum_free(h, 0);
507 sat_chksum_free(h, 0);
512 findfastest(char **urls, int nurls)
519 struct addrinfo hints, *result;;
521 fds = sat_calloc(nurls, sizeof(*fds));
522 socks = sat_calloc(nurls, sizeof(*socks));
523 for (i = 0; i < nurls; i++)
526 p = strchr(urls[i], '/');
539 if ((p2 = strchr(p, '@')) != 0)
542 if (!strncmp("https:", urls[i], 6))
544 else if (!strncmp("ftp:", urls[i], 4))
546 if ((p2 = strrchr(p, ':')) != 0)
555 sprintf(portstr, "%d", port);
556 memset(&hints, 0, sizeof(struct addrinfo));
557 hints.ai_family = AF_UNSPEC;
558 hints.ai_socktype = SOCK_STREAM;
559 hints.ai_flags = AI_NUMERICSERV;
561 if (!getaddrinfo(p, portstr, &hints, &result))
563 socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
566 fcntl(socks[i], F_SETFL, O_NONBLOCK);
567 if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1)
569 if (errno != EINPROGRESS)
576 freeaddrinfo(result);
583 for (i = j = 0; i < nurls; i++)
587 fds[j].fd = socks[i];
588 fds[j].events = POLLOUT;
596 if (poll(fds, j, 10000) <= 0)
598 i = -1; /* something is wrong */
601 for (i = 0; i < j; i++)
602 if ((fds[i].revents & POLLOUT) != 0)
605 socklen_t soel = sizeof(int);
606 if (getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, &soe, &soel) == -1 || soe != 0)
608 /* connect failed, kill socket */
609 for (j = 0; j < nurls; j++)
610 if (socks[j] == fds[i].fd)
623 i = -1; /* something is wrong, no bit was set */
626 /* now i contains the fastest fd index */
629 for (j = 0; j < nurls; j++)
630 if (socks[j] == fds[i].fd)
634 char *url0 = urls[0];
639 for (i = j = 0; i < nurls; i++)
647 findmetalinkurl(FILE *fp, unsigned char *chksump, Id *chksumtypep)
649 char buf[4096], *bp, *ep;
656 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
658 while (*bp == ' ' || *bp == '\t')
660 if (chksumtypep && !*chksumtypep && !strncmp(bp, "<hash type=\"sha256\">", 20))
665 memset(chksump, 0, 32);
666 for (i = 0; i < 64; i++)
669 if (c >= '0' && c <= '9')
670 chksump[i / 2] = chksump[i / 2] * 16 + (c - '0');
671 else if (c >= 'a' && c <= 'f')
672 chksump[i / 2] = chksump[i / 2] * 16 + (c - ('a' - 10));
673 else if (c >= 'A' && c <= 'F')
674 chksump[i / 2] = chksump[i / 2] * 16 + (c - ('A' - 10));
679 *chksumtypep = REPOKEY_TYPE_SHA256;
682 if (strncmp(bp, "<url", 4))
684 bp = strchr(bp, '>');
688 ep = strstr(bp, "repodata/repomd.xml</url>");
692 if (strncmp(bp, "http", 4))
694 urls = sat_extend(urls, nurls, 1, sizeof(*urls), 15);
695 urls[nurls++] = strdup(bp);
700 findfastest(urls, nurls > 5 ? 5 : nurls);
703 for (i = 0; i < nurls; i++)
706 ep = strchr(bp, '/');
707 if ((ep = strchr(ep + 2, '/')) != 0)
710 printf("[using mirror %s]\n", bp);
719 findmirrorlisturl(FILE *fp)
721 char buf[4096], *bp, *ep;
726 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
728 while (*bp == ' ' || *bp == '\t')
730 if (!*bp || *bp == '#')
733 while (l > 0 && (bp[l - 1] == ' ' || bp[l - 1] == '\t' || bp[l - 1] == '\n'))
735 urls = sat_extend(urls, nurls, 1, sizeof(*urls), 15);
736 urls[nurls++] = strdup(bp);
741 findfastest(urls, nurls > 5 ? 5 : nurls);
744 for (i = 0; i < nurls; i++)
747 ep = strchr(bp, '/');
748 if ((ep = strchr(ep + 2, '/')) != 0)
751 printf("[using mirror %s]\n", bp);
760 cookie_gzread(void *cookie, char *buf, size_t nbytes)
762 return gzread((gzFile *)cookie, buf, nbytes);
766 cookie_gzclose(void *cookie)
768 return gzclose((gzFile *)cookie);
772 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int *badchecksump)
778 const char *baseurl = cinfo->baseurl;
782 if (!cinfo->metalink && !cinfo->mirrorlist)
784 if (file != cinfo->metalink && file != cinfo->mirrorlist)
786 FILE *fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
787 unsigned char mlchksum[32];
792 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
794 cinfo->baseurl = findmirrorlisturl(fp);
799 if (strchr(cinfo->baseurl, '$'))
801 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
802 free(cinfo->baseurl);
803 cinfo->baseurl = strdup(b);
806 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
808 chksumtype = mlchksumtype;
811 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, badchecksump);
813 snprintf(url, sizeof(url), "%s", file);
818 if (l && baseurl[l - 1] == '/')
819 snprintf(url, sizeof(url), "%s%s", baseurl, file);
821 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
824 // printf("url: %s\n", url);
825 if ((pid = fork()) == (pid_t)-1)
837 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
842 while (waitpid(pid, &status, 0) != pid)
844 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
850 lseek(fd, 0, SEEK_SET);
853 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
859 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
869 cookie_io_functions_t cio;
872 sprintf(tmpl, "/dev/fd/%d", fd);
873 gzf = gzopen(tmpl, "r");
877 fprintf(stderr, "could not open /dev/fd/%d, /proc not mounted?\n", fd);
880 memset(&cio, 0, sizeof(cio));
881 cio.read = cookie_gzread;
882 cio.close = cookie_gzclose;
883 return fopencookie(gzf, "r", cio);
885 fcntl(fd, F_SETFD, FD_CLOEXEC);
886 return fdopen(fd, "r");
892 cleanupgpg(char *gpgdir)
895 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
897 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
899 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
901 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
903 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
909 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
918 off_t posfp, possigfp;
921 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
924 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
925 if (!(kfp = fopen(keysfile, "w")) )
931 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
935 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
936 if (!pubkey || !*pubkey)
938 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
940 if (fputc('\n', kfp) == EOF) /* Just in case... */
944 if (fclose(kfp) || !nkeys)
949 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
952 fprintf(stderr, "key import error\n");
957 posfp = lseek(fileno(fp), 0, SEEK_CUR);
958 lseek(fileno(fp), 0, SEEK_SET);
959 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
960 lseek(fileno(sigfp), 0, SEEK_SET);
961 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
962 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
963 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
965 lseek(fileno(sigfp), possigfp, SEEK_SET);
966 lseek(fileno(fp), posfp, SEEK_SET);
967 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
968 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
970 return r == 0 ? 1 : 0;
976 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
981 snprintf(cmd, sizeof(cmd), "gpgv -q --keyring /etc/apt/trusted.gpg /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", fileno(sigfp), fileno(fp));
982 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
983 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
985 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
986 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
987 return r == 0 ? 1 : 0;
992 #define CHKSUM_IDENT "1.1"
995 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
998 void *h = sat_chksum_create(chktype);
1001 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1002 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
1003 sat_chksum_add(h, buf, l);
1005 sat_chksum_free(h, out);
1009 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *out)
1011 void *h = sat_chksum_create(chktype);
1012 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1013 sat_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
1014 sat_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
1015 sat_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
1016 sat_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
1017 sat_chksum_free(h, out);
1029 pool_setarch(pool, un.machine);
1032 char *calccachepath(Repo *repo, const char *repoext)
1034 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
1037 p = pool_tmpjoin(repo->pool, p, "_", repoext);
1038 p = pool_tmpjoin(repo->pool, p, ".solvx", 0);
1041 p = pool_tmpjoin(repo->pool, p, ".solv", 0);
1042 q = p + strlen(SOLVCACHE_PATH) + 1;
1052 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1055 unsigned char mycookie[32];
1056 unsigned char myextcookie[32];
1057 struct repoinfo *cinfo;
1060 cinfo = repo->appdata;
1061 if (!(fp = fopen(calccachepath(repo, repoext), "r")))
1063 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1068 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1073 if (cinfo && !repoext)
1075 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1086 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1087 if (strcmp(repoext, "DL") != 0)
1088 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1091 if (repo_add_solv_flags(repo, fp, flags))
1096 if (cinfo && !repoext)
1098 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1099 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1102 futimes(fileno(fp), 0); /* try to set modification time */
1108 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1113 struct repoinfo *cinfo;
1116 cinfo = repo->appdata;
1117 mkdir(SOLVCACHE_PATH, 0755);
1118 tmpl = sat_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
1126 if (!(fp = fdopen(fd, "w")))
1135 for (i = repo->start; i < repo->end; i++)
1136 if (repo->pool->solvables[i].repo != repo)
1142 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
1144 repodata_write(info, fp, repo_write_stdkeyfilter, 0);
1147 int oldnrepodata = repo->nrepodata;
1148 repo->nrepodata = 1; /* XXX: do this right */
1149 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
1150 repo->nrepodata = oldnrepodata;
1154 if (!repoext && cinfo)
1156 if (!cinfo->extcookie[0])
1158 /* create the ext cookie and append it */
1159 /* we just need some unique ID */
1161 if (!fstat(fileno(fp), &stb))
1165 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cinfo->extcookie);
1166 for (i = 0; i < 32; i++)
1167 cinfo->extcookie[i] ^= cookie[i];
1169 if (cinfo->extcookie[0] == 0)
1170 cinfo->extcookie[0] = 1;
1172 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1180 /* append our cookie describing the metadata state */
1181 if (fwrite(cookie, 32, 1, fp) != 1)
1196 /* switch to just saved repo to activate paging and save memory */
1197 FILE *fp = fopen(tmpl, "r");
1203 repo_empty(repo, 1);
1204 if (repo_add_solv_flags(repo, fp, SOLV_ADD_NO_STUBS))
1206 /* oops, no way to recover from here */
1207 fprintf(stderr, "internal error\n");
1213 /* make sure repodata contains complete repo */
1214 /* (this is how repodata_write saves it) */
1215 repodata_extend_block(info, repo->start, repo->end - repo->start);
1216 info->state = REPODATA_LOADING;
1217 /* no need for LOCALPOOL as pool already contains ids */
1218 repo_add_solv_flags(repo, fp, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1219 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1224 if (!rename(tmpl, calccachepath(repo, repoext)))
1233 Pool *sigpool = pool_create();
1235 Repo *repo = repo_create(sigpool, "rpmdbkeys");
1236 repo_add_rpmdb_pubkeys(repo, 0, 0);
1242 /* repomd helpers */
1244 static inline const char *
1245 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1247 Pool *pool = repo->pool;
1249 const char *filename;
1254 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1255 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1256 if (dataiterator_step(&di))
1258 dataiterator_setpos_parent(&di);
1259 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1260 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1262 dataiterator_free(&di);
1263 if (filename && !*chksumtypep)
1265 printf("no %s file checksum!\n", what);
1272 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1274 Pool *pool = repo->pool;
1276 Id chksumtype, handle;
1277 const unsigned char *chksum;
1278 const char *filename;
1280 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1281 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1282 if (!dataiterator_step(&di))
1284 dataiterator_free(&di);
1287 if (!strcmp(what, "prestodelta"))
1289 dataiterator_setpos_parent(&di);
1290 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1291 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, &chksumtype);
1292 if (!filename || !chksum)
1294 dataiterator_free(&di);
1297 handle = repodata_new_handle(data);
1298 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1299 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1301 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1302 if (!strcmp(what, "deltainfo"))
1304 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1305 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1307 if (!strcmp(what, "filelists"))
1309 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1310 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1312 dataiterator_free(&di);
1313 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1318 /* susetags helpers */
1320 static inline const char *
1321 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1323 Pool *pool = repo->pool;
1325 const char *filename;
1330 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
1331 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1332 if (dataiterator_step(&di))
1334 dataiterator_setpos_parent(&di);
1335 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
1338 dataiterator_free(&di);
1339 if (filename && !*chksumtypep)
1341 printf("no %s file checksum!\n", what);
1347 static Id susetags_langtags[] = {
1348 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
1349 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
1350 SOLVABLE_EULA, REPOKEY_TYPE_STR,
1351 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
1352 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
1353 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
1358 susetags_add_ext(Repo *repo, Repodata *data)
1360 Pool *pool = repo->pool;
1363 Id handle, filechksumtype;
1364 const unsigned char *filechksum;
1367 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
1368 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1369 while (dataiterator_step(&di))
1371 if (strncmp(di.kv.str, "packages.", 9) != 0)
1373 if (!strcmp(di.kv.str + 9, "gz"))
1375 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
1377 ext[0] = di.kv.str[9];
1378 ext[1] = di.kv.str[10];
1380 if (!strcmp(ext, "en"))
1382 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
1384 handle = repodata_new_handle(data);
1385 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
1387 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
1388 if (!strcmp(ext, "DU"))
1390 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
1391 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
1393 else if (!strcmp(ext, "FL"))
1395 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1396 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1400 for (i = 0; susetags_langtags[i]; i += 2)
1402 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
1403 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
1406 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1408 dataiterator_free(&di);
1413 iscompressed(const char *name)
1415 int l = strlen(name);
1416 return l > 3 && !strcmp(name + l - 3, ".gz") ? 1 : 0;
1423 load_stub(Pool *pool, Repodata *data, void *dp)
1425 const char *filename, *descrdir, *repomdtype;
1426 const unsigned char *filechksum;
1428 struct repoinfo *cinfo;
1433 cinfo = data->repo->appdata;
1435 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1439 ext[0] = filename[9];
1440 ext[1] = filename[10];
1443 printf("[%s:%s", data->repo->name, ext);
1445 if (usecachedrepo(data->repo, ext, cinfo->extcookie, 0))
1447 printf(" cached]\n"); fflush(stdout);
1451 printf(" fetching]\n"); fflush(stdout);
1453 defvendor = repo_lookup_id(data->repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1454 descrdir = repo_lookup_str(data->repo, SOLVID_META, SUSETAGS_DESCRDIR);
1456 descrdir = "suse/setup/descr";
1458 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1459 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1461 repo_add_susetags(data->repo, fp, defvendor, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1463 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
1467 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1470 if (!strcmp(repomdtype, "filelists"))
1472 else if (!strcmp(repomdtype, "deltainfo"))
1477 printf("[%s:%s", data->repo->name, ext);
1479 if (usecachedrepo(data->repo, ext, cinfo->extcookie, 0))
1481 printf(" cached]\n");fflush(stdout);
1484 printf(" fetching]\n"); fflush(stdout);
1485 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1487 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1488 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1490 if (!strcmp(ext, "FL"))
1491 repo_add_rpmmd(data->repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1492 else if (!strcmp(ext, "DL"))
1493 repo_add_deltainfoxml(data->repo, fp, REPO_USE_LOADING);
1495 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
1502 static unsigned char installedcookie[32];
1506 repo_add_debdb(Repo *repo, int flags)
1509 if ((fp = fopen("/var/lib/dpkg/status", "r")) == 0)
1511 perror("/var/lib/dpkg/status");
1514 repo_add_debpackages(repo, fp, flags);
1519 hexstr2bytes(unsigned char *buf, const char *str, int buflen)
1522 for (i = 0; i < buflen; i++)
1524 #define c2h(c) (((c)>='0' && (c)<='9') ? ((c)-'0') \
1525 : ((c)>='a' && (c)<='f') ? ((c)-('a'-10)) \
1526 : ((c)>='A' && (c)<='F') ? ((c)-('A'-10)) \
1537 buf[i] = (buf[i] << 4) | v;
1544 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1548 unsigned char *chksum;
1553 static char *basearch;
1565 basearch = strdup(un.machine);
1566 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
1569 binarydir = sat_dupjoin("binary-", basearch, "/");
1570 lbinarydir = strlen(binarydir);
1571 compl = strlen(comp);
1575 chksum = sat_malloc(32);
1577 while(fgets(buf, sizeof(buf), fp))
1582 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1584 if (!strncasecmp(buf, "MD5Sum:", 7))
1586 curchksumtype = REPOKEY_TYPE_MD5;
1589 if (!strncasecmp(buf, "SHA1:", 5))
1591 curchksumtype = REPOKEY_TYPE_SHA1;
1594 if (!strncasecmp(buf, "SHA256:", 7))
1596 curchksumtype = REPOKEY_TYPE_SHA256;
1608 while (*bp && *bp != ' ' && *bp != '\t')
1613 while (*bp == ' ' || *bp == '\t')
1615 while (*bp && *bp != ' ' && *bp != '\t')
1619 while (*bp == ' ' || *bp == '\t')
1622 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1625 if (strncmp(bp, binarydir, lbinarydir))
1628 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1630 if (filename && !strcmp(bp, "Packages"))
1632 if (chksumtype && sat_chksum_len(chksumtype) > sat_chksum_len(curchksumtype))
1634 if (!hexstr2bytes(chksum, ch, sat_chksum_len(curchksumtype)))
1637 filename = strdup(fn);
1638 chksumtype = curchksumtype;
1644 fn = sat_dupjoin("/", filename, 0);
1646 filename = sat_dupjoin("dists/", cinfo->name, fn);
1650 chksum = sat_free(chksum);
1652 *chksumtypep = chksumtype;
1658 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1661 struct repoinfo *cinfo;
1665 const char *filename;
1666 const unsigned char *filechksum;
1668 const char *descrdir;
1680 repo = repo_create(pool, "@System");
1682 printf("rpm database:");
1683 if (stat("/var/lib/rpm/Packages", &stb))
1684 memset(&stb, 0, sizeof(&stb));
1686 printf("dpgk database:");
1687 if (stat("/var/lib/dpkg/status", &stb))
1688 memset(&stb, 0, sizeof(&stb));
1690 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, installedcookie);
1691 if (usecachedrepo(repo, 0, installedcookie, 0))
1692 printf(" cached\n");
1699 printf(" reading\n");
1701 #ifdef PRODUCTS_PATH
1702 repo_add_products(repo, PRODUCTS_PATH, 0, REPO_NO_INTERNALIZE);
1705 if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
1707 Repo *ref = repo_create(pool, "@System.old");
1708 if (!repo_add_solv(ref, ofp))
1710 repo_add_rpmdb(repo, ref, 0, REPO_REUSE_REPODATA);
1717 repo_add_rpmdb(repo, 0, 0, REPO_REUSE_REPODATA);
1719 repo_add_debdb(repo, REPO_REUSE_REPODATA);
1721 writecachedrepo(repo, 0, 0, installedcookie);
1723 pool_set_installed(pool, repo);
1725 for (i = 0; i < nrepoinfos; i++)
1727 cinfo = repoinfos + i;
1728 if (!cinfo->enabled)
1731 repo = repo_create(pool, cinfo->alias);
1733 repo->appdata = cinfo;
1734 repo->priority = 99 - cinfo->priority;
1736 dorefresh = cinfo->autorefresh;
1737 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0), &stb) == 0)
1739 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1742 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1744 printf("repo '%s':", cinfo->alias);
1745 printf(" cached\n");
1749 switch (cinfo->type)
1752 printf("rpmmd repo '%s':", cinfo->alias);
1754 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1756 printf(" no repomd.xml file, skipped\n");
1761 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1762 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1764 printf(" cached\n");
1768 if (cinfo->repo_gpgcheck)
1770 sigfp = curlfopen(cinfo, "repodata/repomd.xml.asc", 0, 0, 0, 0);
1773 printf(" unsigned, skipped\n");
1778 sigpool = read_sigs();
1779 if (!checksig(sigpool, fp, sigfp))
1781 printf(" checksig failed, skipped\n");
1788 repo_add_repomdxml(repo, fp, 0);
1790 printf(" fetching\n");
1791 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1792 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1794 repo_add_rpmmd(repo, fp, 0, 0);
1798 break; /* hopeless */
1800 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1801 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1803 repo_add_updateinfoxml(repo, fp, 0);
1807 data = repo_add_repodata(repo, 0);
1808 if (!repomd_add_ext(repo, data, "deltainfo"))
1809 repomd_add_ext(repo, data, "prestodelta");
1810 repomd_add_ext(repo, data, "filelists");
1811 repodata_internalize(data);
1813 writecachedrepo(repo, 0, 0, cinfo->cookie);
1814 repodata_create_stubs(repo_last_repodata(repo));
1818 printf("susetags repo '%s':", cinfo->alias);
1822 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1824 printf(" no content file, skipped\n");
1829 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1830 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1832 printf(" cached\n");
1836 if (cinfo->repo_gpgcheck)
1838 sigfp = curlfopen(cinfo, "content.asc", 0, 0, 0, 0);
1841 printf(" unsigned, skipped\n");
1848 sigpool = read_sigs();
1849 if (!checksig(sigpool, fp, sigfp))
1851 printf(" checksig failed, skipped\n");
1859 repo_add_content(repo, fp, 0);
1861 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1862 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1864 descrdir = "suse/setup/descr";
1865 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1867 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1870 printf(" no packages file entry, skipped\n");
1873 printf(" fetching\n");
1874 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) == 0)
1875 break; /* hopeless */
1876 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE);
1878 /* add default language */
1879 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1881 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1884 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1886 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES);
1890 repo_internalize(repo);
1891 data = repo_add_repodata(repo, 0);
1892 susetags_add_ext(repo, data);
1893 repodata_internalize(data);
1895 writecachedrepo(repo, 0, 0, cinfo->cookie);
1896 repodata_create_stubs(repo_last_repodata(repo));
1901 printf("debian repo '%s':", cinfo->alias);
1903 filename = sat_dupjoin("dists/", cinfo->name, "/Release");
1904 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
1906 printf(" no Release file, skipped\n");
1909 free((char *)filename);
1912 sat_free((char *)filename);
1913 if (cinfo->repo_gpgcheck)
1915 filename = sat_dupjoin("dists/", cinfo->name, "/Release.gpg");
1916 sigfp = curlfopen(cinfo, filename, 0, 0, 0, 0);
1917 sat_free((char *)filename);
1920 printf(" unsigned, skipped\n");
1925 sigpool = read_sigs();
1926 if (!checksig(sigpool, fpr, sigfp))
1928 printf(" checksig failed, skipped\n");
1935 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
1936 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1938 printf(" cached\n");
1942 printf(" fetching\n");
1943 for (j = 0; j < cinfo->ncomponents; j++)
1945 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
1947 printf("[component %s not found]\n", cinfo->components[j]);
1950 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1952 repo_add_debpackages(repo, fp, 0);
1955 sat_free((char *)filechksum);
1956 sat_free((char *)filename);
1960 writecachedrepo(repo, 0, 0, cinfo->cookie);
1965 printf("unsupported repo '%s': skipped\n", cinfo->alias);
1977 str2archid(Pool *pool, char *arch)
1982 id = str2id(pool, arch, 0);
1983 if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH)
1985 if (pool->id2arch && (id > pool->lastarch || !pool->id2arch[id]))
1991 #define DEPGLOB_NAME 1
1992 #define DEPGLOB_DEP 2
1993 #define DEPGLOB_NAMEDEP 3
1996 depglob(Pool *pool, char *name, Queue *job, int what)
1999 Id id = str2id(pool, name, 0);
2004 FOR_PROVIDES(p, pp, id)
2006 Solvable *s = pool->solvables + p;
2008 if (s->name == id && (what & DEPGLOB_NAME) != 0)
2010 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
2016 if (what == DEPGLOB_NAMEDEP)
2017 printf("[using capability match for '%s']\n", name);
2018 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
2023 if (strpbrk(name, "[*?") == 0)
2026 if ((what & DEPGLOB_NAME) != 0)
2028 /* looks like a name glob. hard work. */
2029 for (p = 1; p < pool->nsolvables; p++)
2031 Solvable *s = pool->solvables + p;
2032 if (!s->repo || !pool_installable(pool, s))
2035 if (fnmatch(name, id2str(pool, id), 0) == 0)
2037 for (i = 0; i < job->count; i += 2)
2038 if (job->elements[i] == SOLVER_SOLVABLE_NAME && job->elements[i + 1] == id)
2040 if (i == job->count)
2041 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
2048 if ((what & DEPGLOB_DEP))
2050 /* looks like a dep glob. really hard work. */
2051 for (id = 1; id < pool->ss.nstrings; id++)
2053 if (!pool->whatprovides[id])
2055 if (fnmatch(name, id2str(pool, id), 0) == 0)
2057 if (!match && what == DEPGLOB_NAMEDEP)
2058 printf("[using capability match for '%s']\n", name);
2059 for (i = 0; i < job->count; i += 2)
2060 if (job->elements[i] == SOLVER_SOLVABLE_PROVIDES && job->elements[i + 1] == id)
2062 if (i == job->count)
2063 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
2074 limitrelation(Pool *pool, Queue *job, int flags, Id evr)
2078 for (i = j = 0; i < job->count; i += 2)
2080 Id select = job->elements[i] & SOLVER_SELECTMASK;
2081 if (select != SOLVER_SOLVABLE_NAME && select != SOLVER_SOLVABLE_PROVIDES)
2083 fprintf(stderr, "limitrelation only works on name/provides jobs\n");
2086 job->elements[i + 1] = rel2id(pool, job->elements[i + 1], evr, flags, 1);
2087 if (flags == REL_ARCH)
2088 job->elements[i] |= SOLVER_SETARCH;
2089 if (flags == REL_EQ && select == SOLVER_SOLVABLE_NAME && job->elements[i])
2092 const char *evrstr = id2str(pool, evr);
2093 if (!strchr(evrstr, '-'))
2094 job->elements[i] |= SOLVER_SETEV;
2097 job->elements[i] |= SOLVER_SETEVR;
2099 /* make sure we still have matches */
2100 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2104 job->elements[j] = job->elements[i];
2105 job->elements[j + 1] = job->elements[i + 1];
2109 queue_truncate(job, j);
2114 limitrelation_arch(Pool *pool, Queue *job, int flags, char *evr)
2118 if ((r = strrchr(evr, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2121 limitrelation(pool, job, REL_ARCH, archid);
2122 limitrelation(pool, job, flags, str2id(pool, evr, 1));
2126 limitrelation(pool, job, flags, str2id(pool, evr, 1));
2127 return job->count / 2;
2131 limitrepo(Pool *pool, Id repofilter, Queue *job)
2139 for (i = j = 0; i < job->count; i += 2)
2142 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2144 s = pool_id2solvable(pool, p);
2145 if (s->repo && s->repo->repoid == repofilter)
2150 /* here we assume that repo == vendor, so we also set SOLVER_SETVENDOR */
2153 job->elements[j] = SOLVER_SOLVABLE | (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO | SOLVER_NOAUTOSET;
2154 job->elements[j + 1] = mq.elements[0];
2158 job->elements[j] = SOLVER_SOLVABLE_ONE_OF | (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO;
2159 job->elements[j + 1] = pool_queuetowhatprovides(pool, &mq);
2164 queue_truncate(job, j);
2170 mkselect(Pool *pool, int mode, char *name, Queue *job)
2181 dataiterator_init(&di, pool, mode == SOLVER_ERASE ? pool->installed : 0, 0, SOLVABLE_FILELIST, name, SEARCH_STRING|SEARCH_FILES|SEARCH_COMPLETE_FILELIST);
2182 while (dataiterator_step(&di))
2184 Solvable *s = pool->solvables + di.solvid;
2185 if (!s->repo || !pool_installable(pool, s))
2187 queue_push(&q, di.solvid);
2188 dataiterator_skip_solvable(&di);
2190 dataiterator_free(&di);
2193 printf("[using file list match for '%s']\n", name);
2195 queue_push2(job, SOLVER_SOLVABLE_ONE_OF, pool_queuetowhatprovides(pool, &q));
2197 queue_push2(job, SOLVER_SOLVABLE | SOLVER_NOAUTOSET, q.elements[0]);
2199 return job->count / 2;
2202 if ((r = strpbrk(name, "<=>")) != 0)
2204 /* relation case, support:
2209 int nend = r - name;
2222 while (*r && *r == ' ' && *r == '\t')
2224 while (nend && (name[nend - 1] == ' ' || name[nend -1 ] == '\t'))
2228 fprintf(stderr, "bad relation\n");
2231 oldnend = name[nend];
2233 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2235 name[nend] = oldnend;
2236 limitrelation(pool, job, rflags, str2id(pool, r, 1));
2237 return job->count / 2;
2239 if ((r2 = strrchr(name, '.')) != 0 && r2[1] && (archid = str2archid(pool, r2 + 1)) != 0)
2242 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2244 name[nend] = oldnend;
2246 limitrelation(pool, job, REL_ARCH, archid);
2247 limitrelation(pool, job, rflags, str2id(pool, r, 1));
2248 return job->count / 2;
2252 name[nend] = oldnend;
2256 /* no relation case, support:
2260 * nameglob-version.arch
2261 * nameglob-version-release
2262 * nameglob-version-release.arch
2264 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2265 return job->count / 2;
2266 if ((r = strrchr(name, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2269 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2272 limitrelation(pool, job, REL_ARCH, archid);
2273 return job->count / 2;
2277 if ((r = strrchr(name, '-')) != 0)
2280 if (depglob(pool, name, job, DEPGLOB_NAME))
2282 /* have just the version */
2283 limitrelation_arch(pool, job, REL_EQ, r + 1);
2285 return job->count / 2;
2287 if ((r2 = strrchr(name, '-')) != 0)
2292 if (depglob(pool, name, job, DEPGLOB_NAME))
2294 /* have version-release */
2295 limitrelation_arch(pool, job, REL_EQ, r + 1);
2297 return job->count / 2;
2308 yesno(const char *str)
2310 char inbuf[128], *ip;
2317 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2322 while (*ip == ' ' || *ip == '\t')
2329 if (*ip == 'y' || *ip == 'n')
2330 return *ip == 'y' ? 1 : 0;
2344 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2346 struct fcstate *fcstate = cbdata;
2354 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
2357 s = pool_id2solvable(pool, p);
2358 if (pool->installed && s->repo == pool->installed)
2360 if (!s->repo->rpmdbid)
2362 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2365 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
2367 for (i = 0; i < fcstate->newpkgscnt; i++)
2368 if (fcstate->checkq->elements[i] == p)
2370 if (i == fcstate->newpkgscnt)
2372 fp = fcstate->newpkgsfps[i];
2376 return rpm_byfp(fp, solvable2str(pool, s), &fcstate->rpmdbstate);
2381 runrpm(const char *arg, const char *name, int dupfd3)
2386 if ((pid = fork()) == (pid_t)-1)
2393 if (dupfd3 != -1 && dupfd3 != 3)
2399 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2400 if (strcmp(arg, "-e") == 0)
2401 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2403 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2407 while (waitpid(pid, &status, 0) != pid)
2411 printf("rpm failed\n");
2421 rundpkg(const char *arg, const char *name, int dupfd3)
2426 if ((pid = fork()) == (pid_t)-1)
2433 if (dupfd3 != -1 && dupfd3 != 3)
2439 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2440 if (strcmp(arg, "--install") == 0)
2441 execlp("dpkg", "dpkg", "--install", "--force", "all", name, (char *)0);
2443 execlp("dpkg", "dpkg", "--remove", "--force", "all", name, (char *)0);
2447 while (waitpid(pid, &status, 0) != pid)
2451 printf("dpkg failed\n");
2459 nscallback(Pool *pool, void *data, Id name, Id evr)
2461 if (name == NAMESPACE_PRODUCTBUDDY)
2463 /* SUSE specific hack: each product has an associated rpm */
2464 Solvable *s = pool->solvables + evr;
2467 cap = str2id(pool, pool_tmpjoin(pool, "product(", id2str(pool, s->name) + 8, ")"), 0);
2470 cap = rel2id(pool, cap, s->evr, REL_EQ, 0);
2473 FOR_PROVIDES(p, pp, cap)
2475 Solvable *ps = pool->solvables + p;
2476 if (ps->repo == s->repo && ps->arch == s->arch)
2484 #ifdef SOFTLOCKS_PATH
2487 addsoftlocks(Pool *pool, Queue *job)
2491 char *bp, *ep, buf[4096];
2493 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2495 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2497 while (*bp == ' ' || *bp == '\t')
2499 if (!*bp || *bp == '#')
2501 for (ep = bp; *ep; ep++)
2502 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2505 type = SOLVER_SOLVABLE_NAME;
2506 if (!strncmp(bp, "provides:", 9) && bp[9])
2508 type = SOLVER_SOLVABLE_PROVIDES;
2511 id = str2id(pool, bp, 1);
2512 if (pool->installed)
2514 FOR_JOB_SELECT(p, pp, type, id)
2515 if (pool->solvables[p].repo == pool->installed)
2518 continue; /* ignore, as it is already installed */
2520 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2529 rewrite_repos(Pool *pool, Id *addedfileprovides)
2534 Queue fileprovidesq;
2536 int i, j, n, nprovidedids;
2537 struct repoinfo *cinfo;
2539 map_init(&providedids, pool->ss.nstrings);
2540 queue_init(&fileprovidesq);
2541 for (nprovidedids = 0; (id = addedfileprovides[nprovidedids]) != 0; nprovidedids++)
2542 MAPSET(&providedids, id);
2545 /* make sure this repo has just one main repodata */
2546 if (!repo->nrepodata)
2548 cinfo = repo->appdata;
2549 data = repo->repodata + 0;
2550 if (data->store.pagefd == -1)
2552 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2555 for (j = 0; j < fileprovidesq.count; j++)
2556 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2558 if (n == nprovidedids)
2559 continue; /* nothing new added */
2562 for (j = 0; addedfileprovides[j]; j++)
2563 repodata_add_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, addedfileprovides[j]);
2564 repodata_internalize(data);
2565 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2567 queue_free(&fileprovidesq);
2568 map_free(&providedids);
2572 #define MODE_INSTALL 1
2573 #define MODE_ERASE 2
2574 #define MODE_UPDATE 3
2575 #define MODE_DISTUPGRADE 4
2576 #define MODE_VERIFY 5
2577 #define MODE_PATCH 6
2579 #define MODE_REPOLIST 8
2580 #define MODE_SEARCH 9
2581 #define MODE_ERASECLEAN 10
2586 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2587 fprintf(stderr, "\n");
2588 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2589 fprintf(stderr, " versions from the repositories\n");
2590 fprintf(stderr, " erase: erase installed packages\n");
2591 fprintf(stderr, " info: display package information\n");
2592 fprintf(stderr, " install: install packages\n");
2593 fprintf(stderr, " list: list packages\n");
2594 fprintf(stderr, " repos: list enabled repositories\n");
2595 fprintf(stderr, " search: search name/summary/description\n");
2596 fprintf(stderr, " update: update installed packages\n");
2597 fprintf(stderr, " verify: check dependencies of installed packages\n");
2598 fprintf(stderr, "\n");
2603 main(int argc, char **argv)
2606 Repo *commandlinerepo = 0;
2607 Id *commandlinepkgs = 0;
2609 struct repoinfo *repoinfos;
2611 int mainmode = 0, mode = 0;
2616 char inbuf[128], *ip;
2619 Id *addedfileprovides = 0;
2626 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2628 mainmode = MODE_INSTALL;
2629 mode = SOLVER_INSTALL;
2631 else if (!strcmp(argv[0], "patch"))
2633 mainmode = MODE_PATCH;
2634 mode = SOLVER_INSTALL;
2636 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2638 mainmode = MODE_ERASE;
2639 mode = SOLVER_ERASE;
2641 else if (!strcmp(argv[0], "eraseclean") || !strcmp(argv[0], "rmclean"))
2643 mainmode = MODE_ERASECLEAN;
2644 mode = SOLVER_ERASE;
2646 else if (!strcmp(argv[0], "list"))
2648 mainmode = MODE_LIST;
2651 else if (!strcmp(argv[0], "info"))
2653 mainmode = MODE_INFO;
2656 else if (!strcmp(argv[0], "search"))
2658 mainmode = MODE_SEARCH;
2661 else if (!strcmp(argv[0], "verify"))
2663 mainmode = MODE_VERIFY;
2664 mode = SOLVER_VERIFY;
2666 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2668 mainmode = MODE_UPDATE;
2669 mode = SOLVER_UPDATE;
2671 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2673 mainmode = MODE_DISTUPGRADE;
2674 mode = SOLVER_UPDATE;
2676 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2678 mainmode = MODE_REPOLIST;
2684 pool = pool_create();
2688 const char *langs[] = {"de_DE", "de", "en"};
2689 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2694 pool->obsoleteusescolors = 1;
2696 pool_setloadcallback(pool, load_stub, 0);
2697 pool->nscallback = nscallback;
2698 // pool_setdebuglevel(pool, 2);
2700 repoinfos = read_repoinfos(pool, REPOINFO_PATH, &nrepoinfos);
2702 if (mainmode == MODE_REPOLIST)
2705 for (i = 0; i < nrepoinfos; i++)
2707 struct repoinfo *cinfo = repoinfos + i;
2708 if (!cinfo->enabled)
2710 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2715 read_repos(pool, repoinfos, nrepoinfos);
2717 if (argc > 2 && !strcmp(argv[1], "-r"))
2719 const char *rname = argv[2], *rp;
2720 for (rp = rname; *rp; rp++)
2721 if (*rp <= '0' || *rp >= '9')
2725 /* repo specified by number */
2726 int rnum = atoi(rname);
2727 for (i = 0; i < nrepoinfos; i++)
2729 struct repoinfo *cinfo = repoinfos + i;
2730 if (!cinfo->enabled)
2733 repofilter = cinfo->repo->repoid;
2738 /* repo specified by alias */
2742 if (!strcasecmp(rname, repo->name))
2743 repofilter = repo->repoid;
2748 fprintf(stderr, "%s: no such repo\n", rname);
2754 if (mainmode == MODE_SEARCH)
2760 map_init(&m, pool->nsolvables);
2761 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2762 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2763 dataiterator_set_search(&di, 0, 0);
2764 while (dataiterator_step(&di))
2765 MAPSET(&m, di.solvid);
2766 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2767 dataiterator_set_search(&di, 0, 0);
2768 while (dataiterator_step(&di))
2769 MAPSET(&m, di.solvid);
2770 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2771 dataiterator_set_search(&di, 0, 0);
2772 while (dataiterator_step(&di))
2773 MAPSET(&m, di.solvid);
2774 dataiterator_free(&di);
2776 for (p = 1; p < pool->nsolvables; p++)
2778 Solvable *s = pool_id2solvable(pool, p);
2781 printf(" - %s: %s\n", solvable2str(pool, s), solvable_lookup_str(s, SOLVABLE_SUMMARY));
2788 if (mainmode == MODE_LIST || mainmode == MODE_INSTALL)
2790 for (i = 1; i < argc; i++)
2793 l = strlen(argv[i]);
2795 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2798 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2801 if (access(argv[i], R_OK))
2806 if (!commandlinepkgs)
2807 commandlinepkgs = sat_calloc(argc, sizeof(Id));
2808 if (!commandlinerepo)
2809 commandlinerepo = repo_create(pool, "@commandline");
2811 repo_add_rpms(commandlinerepo, (const char **)argv + i, 1, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2813 repo_add_debs(commandlinerepo, (const char **)argv + i, 1, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2815 commandlinepkgs[i] = commandlinerepo->end - 1;
2817 if (commandlinerepo)
2818 repo_internalize(commandlinerepo);
2821 // FOR_REPOS(i, repo)
2822 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2823 addedfileprovides = 0;
2824 pool_addfileprovides_ids(pool, 0, &addedfileprovides);
2825 if (addedfileprovides && *addedfileprovides)
2826 rewrite_repos(pool, addedfileprovides);
2827 sat_free(addedfileprovides);
2828 pool_createwhatprovides(pool);
2831 for (i = 1; i < argc; i++)
2836 if (commandlinepkgs && commandlinepkgs[i])
2838 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2842 if (!mkselect(pool, mode, argv[i], &job2))
2844 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2847 if (repofilter && !limitrepo(pool, repofilter, &job2))
2849 fprintf(stderr, "nothing in repo matches '%s'\n", argv[i]);
2852 for (j = 0; j < job2.count; j++)
2853 queue_push(&job, job2.elements[j]);
2857 if (!job.count && mainmode != MODE_UPDATE && mainmode != MODE_DISTUPGRADE && mainmode != MODE_VERIFY && mainmode != MODE_PATCH)
2859 printf("no package matched\n");
2866 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
2868 /* list mode, no solver needed */
2869 for (i = 0; i < job.count; i += 2)
2871 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
2873 Solvable *s = pool_id2solvable(pool, p);
2874 if (mainmode == MODE_INFO)
2877 printf("Name: %s\n", solvable2str(pool, s));
2878 printf("Repo: %s\n", s->repo->name);
2879 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
2880 str = solvable_lookup_str(s, SOLVABLE_URL);
2882 printf("Url: %s\n", str);
2883 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
2885 printf("License: %s\n", str);
2886 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
2892 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
2894 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
2896 printf(" - %s [%s]\n", solvable2str(pool, s), s->repo->name);
2898 printf(" %s\n", sum);
2904 free_repoinfos(repoinfos, nrepoinfos);
2905 sat_free(commandlinepkgs);
2907 yum_substitute(pool, 0);
2912 if (mainmode == MODE_PATCH)
2918 map_init(&installedmap, pool->nsolvables);
2919 if (pool->installed)
2920 FOR_REPO_SOLVABLES(pool->installed, p, s)
2921 MAPSET(&installedmap, p);
2923 /* install all patches */
2924 for (p = 1; p < pool->nsolvables; p++)
2930 s = pool->solvables + p;
2931 if (strncmp(id2str(pool, s->name), "patch:", 6) != 0)
2933 FOR_PROVIDES(p2, pp, s->name)
2935 Solvable *s2 = pool->solvables + p2;
2936 if (s2->name != s->name)
2938 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2939 if (r < 0 || (r == 0 && p > p2))
2944 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2945 if (type && !strcmp(type, "optional"))
2947 r = solvable_trivial_installable_map(s, &installedmap, 0);
2950 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2957 queue_push2(&job, SOLVER_SOLVABLE, p);
2959 map_free(&installedmap);
2963 for (i = 0; i < job.count; i += 2)
2965 if (mode == SOLVER_UPDATE)
2967 /* make update of not installed packages an install */
2968 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
2969 if (pool->installed && pool->solvables[p].repo == pool->installed)
2973 job.elements[i] |= SOLVER_INSTALL;
2977 job.elements[i] |= mode;
2978 if (mainmode == MODE_ERASECLEAN)
2979 job.elements[i] |= SOLVER_CLEANDEPS;
2982 if (mainmode == MODE_DISTUPGRADE && allpkgs && repofilter)
2983 queue_push2(&job, SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_REPO, repofilter);
2985 // multiversion test
2986 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae", 1));
2987 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-base", 1));
2988 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-extra", 1));
2990 #ifdef SOFTLOCKS_PATH
2991 addsoftlocks(pool, &job);
2999 Id problem, solution;
3002 solv = solver_create(pool);
3003 solv->ignorealreadyrecommended = 1;
3004 solv->updatesystem = allpkgs && !repofilter && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE);
3005 solv->dosplitprovides = solv->updatesystem;
3006 solv->fixsystem = allpkgs && !repofilter && mainmode == MODE_VERIFY;
3007 if (mainmode == MODE_DISTUPGRADE && allpkgs && !repofilter)
3009 solv->distupgrade = 1;
3010 solv->allowdowngrade = 1;
3011 solv->allowarchchange = 1;
3012 solv->allowvendorchange = 1;
3014 if (mainmode == MODE_ERASE || mainmode == MODE_ERASECLEAN)
3015 solv->allowuninstall = 1; /* don't nag */
3017 solver_solve(solv, &job);
3018 if (!solv->problems.count)
3020 pcnt = solver_problem_count(solv);
3021 printf("Found %d problems:\n", pcnt);
3022 for (problem = 1; problem <= pcnt; problem++)
3025 printf("Problem %d:\n", problem);
3026 solver_printprobleminfo(solv, problem);
3028 scnt = solver_solution_count(solv, problem);
3029 for (solution = 1; solution <= scnt; solution++)
3031 printf("Solution %d:\n", solution);
3032 solver_printsolution(solv, problem, solution);
3037 printf("Please choose a solution: ");
3040 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
3045 while (*ip == ' ' || *ip == '\t')
3047 if (*ip >= '0' && *ip <= '9')
3050 if (take >= 1 && take <= scnt)
3066 solver_take_solution(solv, problem, take, &job);
3072 trans = &solv->trans;
3073 if (!trans->steps.count)
3075 printf("Nothing to do.\n");
3079 free_repoinfos(repoinfos, nrepoinfos);
3080 sat_free(commandlinepkgs);
3082 yum_substitute(pool, 0);
3087 printf("Transaction summary:\n\n");
3088 solver_printtransaction(solv);
3090 #if !defined(FEDORA) && !defined(DEBIAN)
3097 duc[1].path = "/usr/share/man";
3098 duc[2].path = "/sbin";
3099 duc[3].path = "/etc";
3100 transaction_calc_duchanges(trans, duc, 4);
3101 for (i = 0; i < 4; i++)
3102 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
3105 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
3108 if (!yesno("OK to continue (y/n)? "))
3114 free_repoinfos(repoinfos, nrepoinfos);
3115 sat_free(commandlinepkgs);
3117 yum_substitute(pool, 0);
3122 queue_init(&checkq);
3123 newpkgs = transaction_installedresult(trans, &checkq);
3128 int downloadsize = 0;
3129 for (i = 0; i < newpkgs; i++)
3133 p = checkq.elements[i];
3134 s = pool_id2solvable(pool, p);
3135 downloadsize += solvable_lookup_num(s, SOLVABLE_DOWNLOADSIZE, 0);
3137 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
3138 newpkgsfps = sat_calloc(newpkgs, sizeof(*newpkgsfps));
3139 for (i = 0; i < newpkgs; i++)
3141 unsigned int medianr;
3144 struct repoinfo *cinfo;
3145 const unsigned char *chksum;
3149 p = checkq.elements[i];
3150 s = pool_id2solvable(pool, p);
3151 if (s->repo == commandlinerepo)
3153 loc = solvable_get_location(s, &medianr);
3154 if (!(newpkgsfps[i] = fopen(loc, "r")))
3162 cinfo = s->repo->appdata;
3165 printf("%s: no repository information\n", s->repo->name);
3168 loc = solvable_get_location(s, &medianr);
3172 if (pool->installed && pool->installed->nsolvables)
3174 /* try a delta first */
3175 char *matchname = strdup(id2str(pool, s->name));
3176 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
3177 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
3178 while (dataiterator_step(&di))
3182 dataiterator_setpos_parent(&di);
3183 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
3184 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
3186 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
3187 FOR_PROVIDES(op, pp, s->name)
3189 Solvable *os = pool->solvables + op;
3190 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
3193 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
3195 /* base is installed, run sequence check */
3196 const char *seqname;
3205 seqname = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME);
3206 seqevr = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR);
3207 seqnum = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM);
3208 seq = pool_tmpjoin(pool, seqname, "-", seqevr);
3209 seq = pool_tmpjoin(pool, seq, "-", seqnum);
3211 sprintf(cmd, "/usr/bin/applydeltarpm -a %s -c -s ", id2str(pool, s->arch));
3213 sprintf(cmd, "/usr/bin/applydeltarpm -c -s ");
3215 if (system(pool_tmpjoin(pool, cmd, seq, 0)) != 0)
3216 continue; /* didn't match */
3217 /* looks good, download delta */
3219 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
3221 continue; /* no way! */
3222 dloc = pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_DIR);
3223 dloc = pool_tmpjoin(pool, dloc, "/", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_NAME));
3224 dloc = pool_tmpjoin(pool, dloc, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_EVR));
3225 dloc = pool_tmpjoin(pool, dloc, ".", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_SUFFIX));
3226 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
3228 /* got it, now reconstruct */
3229 newfd = opentmpfile();
3231 sprintf(cmd, "applydeltarpm -a %s /dev/fd/%d /dev/fd/%d", id2str(pool, s->arch), fileno(fp), newfd);
3233 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
3235 fcntl(fileno(fp), F_SETFD, 0);
3242 lseek(newfd, 0, SEEK_SET);
3244 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3245 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
3251 newpkgsfps[i] = fdopen(newfd, "r");
3256 dataiterator_free(&di);
3257 sat_free(matchname);
3264 continue; /* delta worked! */
3266 if (cinfo->type == TYPE_SUSETAGS)
3268 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3269 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3272 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3273 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3275 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3288 struct fcstate fcstate;
3290 printf("Searching for file conflicts\n");
3291 queue_init(&conflicts);
3292 fcstate.rpmdbstate = 0;
3293 fcstate.newpkgscnt = newpkgs;
3294 fcstate.checkq = &checkq;
3295 fcstate.newpkgsfps = newpkgsfps;
3296 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fileconflict_cb, &fcstate);
3297 if (conflicts.count)
3300 for (i = 0; i < conflicts.count; i += 5)
3301 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]));
3303 if (yesno("Re-run solver (y/n/q)? "))
3305 for (i = 0; i < newpkgs; i++)
3307 fclose(newpkgsfps[i]);
3308 newpkgsfps = sat_free(newpkgsfps);
3310 pool_add_fileconflicts_deps(pool, &conflicts);
3311 pool_createwhatprovides(pool); /* Hmm... */
3315 queue_free(&conflicts);
3319 printf("Committing transaction:\n\n");
3320 transaction_order(trans, 0);
3321 for (i = 0; i < trans->steps.count; i++)
3324 const char *evr, *evrp, *nvra;
3330 p = trans->steps.elements[i];
3331 s = pool_id2solvable(pool, p);
3332 Id type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3335 case SOLVER_TRANSACTION_ERASE:
3336 printf("erase %s\n", solvid2str(pool, p));
3338 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3340 /* strip epoch from evr */
3341 evr = evrp = id2str(pool, s->evr);
3342 while (*evrp >= '0' && *evrp <= '9')
3344 if (evrp > evr && evrp[0] == ':' && evrp[1])
3346 nvra = pool_tmpjoin(pool, id2str(pool, s->name), "-", evr);
3347 nvra = pool_tmpjoin(pool, nvra, ".", id2str(pool, s->arch));
3348 runrpm("-e", nvra, -1); /* too bad that --querybynumber doesn't work */
3350 rundpkg("--remove", id2str(pool, s->name), 0);
3353 case SOLVER_TRANSACTION_INSTALL:
3354 case SOLVER_TRANSACTION_MULTIINSTALL:
3355 printf("install %s\n", solvid2str(pool, p));
3356 for (j = 0; j < newpkgs; j++)
3357 if (checkq.elements[j] == p)
3359 fp = j < newpkgs ? newpkgsfps[j] : 0;
3363 lseek(fileno(fp), 0, SEEK_SET);
3365 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp));
3367 rundpkg("--install", "/dev/fd/3", fileno(fp));
3377 for (i = 0; i < newpkgs; i++)
3379 fclose(newpkgsfps[i]);
3380 sat_free(newpkgsfps);
3381 queue_free(&checkq);
3385 free_repoinfos(repoinfos, nrepoinfos);
3386 sat_free(commandlinepkgs);
3388 yum_substitute(pool, 0);