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>
45 #include <sys/socket.h>
57 #include "solverdebug.h"
59 #include "repo_solv.h"
61 #include "repo_write.h"
63 #include "repo_rpmdb.h"
67 #include "repo_products.h"
68 #include "repo_rpmmd.h"
69 #include "repo_susetags.h"
70 #include "repo_repomdxml.h"
71 #include "repo_updateinfoxml.h"
72 #include "repo_deltainfoxml.h"
73 #include "repo_content.h"
74 #include "pool_fileconflicts.h"
76 #include "../tools/common_myfopen.h"
79 # define REPOINFO_PATH "/etc/yum.repos.d"
81 # define REPOINFO_PATH "/etc/zypp/repos.d"
82 # define PRODUCTS_PATH "/etc/products.d"
83 # define SOFTLOCKS_PATH "/var/lib/zypp/SoftLocks"
86 #define SOLVCACHE_PATH "/var/cache/solv"
88 #define METADATA_EXPIRE (60 * 90)
110 unsigned char cookie[32];
111 unsigned char extcookie[32];
116 yum_substitute(Pool *pool, char *line)
119 static char *releaseevr;
120 static char *basearch;
124 sat_free(releaseevr);
131 while ((p2 = strchr(p, '$')) != 0)
133 if (!strncmp(p2, "$releasever", 11))
140 rpm_installedrpmdbids(0, "Providename", "redhat-release", &q);
143 void *handle, *state = 0;
145 handle = rpm_byrpmdbid(q.elements[0], 0, &state);
146 releaseevr = rpm_query(handle, SOLVABLE_EVR);
147 rpm_byrpmdbid(0, 0, &state);
148 if ((p = strchr(releaseevr, '-')) != 0)
153 releaseevr = strdup("?");
156 p = pool_tmpjoin(pool, line, releaseevr, p2 + 11);
157 p2 = p + (p2 - line);
159 p = p2 + strlen(releaseevr);
162 if (!strncmp(p2, "$basearch", 9))
172 basearch = strdup(un.machine);
173 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
177 p = pool_tmpjoin(pool, line, basearch, p2 + 9);
178 p2 = p + (p2 - line);
180 p = p2 + strlen(basearch);
189 #define TYPE_UNKNOWN 0
190 #define TYPE_SUSETAGS 1
192 #define TYPE_PLAINDIR 3
193 #define TYPE_DEBIAN 4
196 read_repoinfos_sort(const void *ap, const void *bp)
198 const struct repoinfo *a = ap;
199 const struct repoinfo *b = bp;
200 return strcmp(a->alias, b->alias);
206 read_repoinfos(Pool *pool, const char *reposdir, int *nrepoinfosp)
209 char buf2[4096], *kp, *vp, *kpe;
214 struct repoinfo *repoinfos = 0, *cinfo;
217 rdlen = strlen(reposdir);
218 dir = opendir(reposdir);
224 while ((ent = readdir(dir)) != 0)
226 if (ent->d_name[0] == '.')
228 l = strlen(ent->d_name);
229 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
231 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
232 if ((fp = fopen(buf, "r")) == 0)
238 while(fgets(buf2, sizeof(buf2), fp))
243 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
246 while (*kp == ' ' || *kp == '\t')
248 if (!*kp || *kp == '#')
252 kp = yum_substitute(pool, kp);
256 vp = strrchr(kp, ']');
260 repoinfos = sat_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
261 cinfo = repoinfos + nrepoinfos++;
262 memset(cinfo, 0, sizeof(*cinfo));
263 cinfo->alias = strdup(kp + 1);
264 cinfo->type = TYPE_RPMMD;
265 cinfo->autorefresh = 1;
266 cinfo->priority = 99;
268 cinfo->repo_gpgcheck = 1;
270 cinfo->metadata_expire = METADATA_EXPIRE;
275 vp = strchr(kp, '=');
278 for (kpe = vp - 1; kpe >= kp; kpe--)
279 if (*kpe != ' ' && *kpe != '\t')
284 while (*vp == ' ' || *vp == '\t')
287 if (!strcmp(kp, "name"))
288 cinfo->name = strdup(vp);
289 else if (!strcmp(kp, "enabled"))
290 cinfo->enabled = *vp == '0' ? 0 : 1;
291 else if (!strcmp(kp, "autorefresh"))
292 cinfo->autorefresh = *vp == '0' ? 0 : 1;
293 else if (!strcmp(kp, "gpgcheck"))
294 cinfo->pkgs_gpgcheck = *vp == '0' ? 0 : 1;
295 else if (!strcmp(kp, "repo_gpgcheck"))
296 cinfo->repo_gpgcheck = *vp == '0' ? 0 : 1;
297 else if (!strcmp(kp, "baseurl"))
298 cinfo->baseurl = strdup(vp);
299 else if (!strcmp(kp, "mirrorlist"))
301 if (strstr(vp, "metalink"))
302 cinfo->metalink = strdup(vp);
304 cinfo->mirrorlist = strdup(vp);
306 else if (!strcmp(kp, "path"))
308 if (vp && strcmp(vp, "/") != 0)
309 cinfo->path = strdup(vp);
311 else if (!strcmp(kp, "type"))
313 if (!strcmp(vp, "yast2"))
314 cinfo->type = TYPE_SUSETAGS;
315 else if (!strcmp(vp, "rpm-md"))
316 cinfo->type = TYPE_RPMMD;
317 else if (!strcmp(vp, "plaindir"))
318 cinfo->type = TYPE_PLAINDIR;
320 cinfo->type = TYPE_UNKNOWN;
322 else if (!strcmp(kp, "priority"))
323 cinfo->priority = atoi(vp);
324 else if (!strcmp(kp, "keeppackages"))
325 cinfo->keeppackages = *vp == '0' ? 0 : 1;
331 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
332 *nrepoinfosp = nrepoinfos;
339 read_repoinfos(Pool *pool, const char *reposdir, int *nrepoinfosp)
345 char *kp, *url, *distro;
346 struct repoinfo *repoinfos = 0, *cinfo;
351 fp = fopen("/etc/apt/sources.list", "r");
358 dir = opendir("/etc/apt/sources.list.d");
362 if ((ent = readdir(dir)) == 0)
367 if (ent->d_name[0] == '.')
369 l = strlen(ent->d_name);
370 if (l < 5 || strcmp(ent->d_name + l - 5, ".list") != 0)
372 snprintf(buf, sizeof(buf), "%s/%s", "/etc/apt/sources.list.d", ent->d_name);
373 if (!(fp = fopen(buf, "r")))
376 while(fgets(buf2, sizeof(buf2), fp))
381 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
384 while (*kp == ' ' || *kp == '\t')
386 if (!*kp || *kp == '#')
388 if (strncmp(kp, "deb", 3) != 0)
391 if (*kp != ' ' && *kp != '\t')
393 while (*kp == ' ' || *kp == '\t')
398 while (*kp && *kp != ' ' && *kp != '\t')
402 while (*kp == ' ' || *kp == '\t')
407 while (*kp && *kp != ' ' && *kp != '\t')
411 while (*kp == ' ' || *kp == '\t')
415 repoinfos = sat_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
416 cinfo = repoinfos + nrepoinfos++;
417 memset(cinfo, 0, sizeof(*cinfo));
418 cinfo->baseurl = strdup(url);
419 cinfo->alias = sat_dupjoin(url, "/", distro);
420 cinfo->name = strdup(distro);
421 cinfo->type = TYPE_DEBIAN;
423 cinfo->autorefresh = 1;
424 cinfo->repo_gpgcheck = 1;
425 cinfo->metadata_expire = METADATA_EXPIRE;
429 while (*kp == ' ' || *kp == '\t')
434 while (*kp && *kp != ' ' && *kp != '\t')
438 cinfo->components = sat_extend(cinfo->components, cinfo->ncomponents, 1, sizeof(*cinfo->components), 15);
439 cinfo->components[cinfo->ncomponents++] = strdup(compo);
445 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
446 *nrepoinfosp = nrepoinfos;
453 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
456 for (i = 0; i < nrepoinfos; i++)
458 struct repoinfo *cinfo = repoinfos + i;
459 sat_free(cinfo->name);
460 sat_free(cinfo->alias);
461 sat_free(cinfo->path);
462 sat_free(cinfo->metalink);
463 sat_free(cinfo->mirrorlist);
464 sat_free(cinfo->baseurl);
465 for (j = 0; j < cinfo->ncomponents; j++)
466 sat_free(cinfo->components[j]);
467 sat_free(cinfo->components);
478 strcpy(tmpl, "/var/tmp/solvXXXXXX");
490 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
497 h = sat_chksum_create(chksumtype);
500 printf("%s: unknown checksum type\n", file);
503 while ((l = read(fd, buf, sizeof(buf))) > 0)
504 sat_chksum_add(h, buf, l);
505 lseek(fd, 0, SEEK_SET);
507 sum = sat_chksum_get(h, &l);
508 if (memcmp(sum, chksum, l))
510 printf("%s: checksum mismatch\n", file);
511 sat_chksum_free(h, 0);
514 sat_chksum_free(h, 0);
519 findfastest(char **urls, int nurls)
526 struct addrinfo hints, *result;;
528 fds = sat_calloc(nurls, sizeof(*fds));
529 socks = sat_calloc(nurls, sizeof(*socks));
530 for (i = 0; i < nurls; i++)
533 p = strchr(urls[i], '/');
546 if ((p2 = strchr(p, '@')) != 0)
549 if (!strncmp("https:", urls[i], 6))
551 else if (!strncmp("ftp:", urls[i], 4))
553 if ((p2 = strrchr(p, ':')) != 0)
562 sprintf(portstr, "%d", port);
563 memset(&hints, 0, sizeof(struct addrinfo));
564 hints.ai_family = AF_UNSPEC;
565 hints.ai_socktype = SOCK_STREAM;
566 hints.ai_flags = AI_NUMERICSERV;
568 if (!getaddrinfo(p, portstr, &hints, &result))
570 socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
573 fcntl(socks[i], F_SETFL, O_NONBLOCK);
574 if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1)
576 if (errno != EINPROGRESS)
583 freeaddrinfo(result);
590 for (i = j = 0; i < nurls; i++)
594 fds[j].fd = socks[i];
595 fds[j].events = POLLOUT;
603 if (poll(fds, j, 10000) <= 0)
605 i = -1; /* something is wrong */
608 for (i = 0; i < j; i++)
609 if ((fds[i].revents & POLLOUT) != 0)
612 socklen_t soel = sizeof(int);
613 if (getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, &soe, &soel) == -1 || soe != 0)
615 /* connect failed, kill socket */
616 for (j = 0; j < nurls; j++)
617 if (socks[j] == fds[i].fd)
630 i = -1; /* something is wrong, no bit was set */
633 /* now i contains the fastest fd index */
636 for (j = 0; j < nurls; j++)
637 if (socks[j] == fds[i].fd)
641 char *url0 = urls[0];
646 for (i = j = 0; i < nurls; i++)
654 findmetalinkurl(FILE *fp, unsigned char *chksump, Id *chksumtypep)
656 char buf[4096], *bp, *ep;
663 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
665 while (*bp == ' ' || *bp == '\t')
667 if (chksumtypep && !*chksumtypep && !strncmp(bp, "<hash type=\"sha256\">", 20))
672 memset(chksump, 0, 32);
673 for (i = 0; i < 64; i++)
676 if (c >= '0' && c <= '9')
677 chksump[i / 2] = chksump[i / 2] * 16 + (c - '0');
678 else if (c >= 'a' && c <= 'f')
679 chksump[i / 2] = chksump[i / 2] * 16 + (c - ('a' - 10));
680 else if (c >= 'A' && c <= 'F')
681 chksump[i / 2] = chksump[i / 2] * 16 + (c - ('A' - 10));
686 *chksumtypep = REPOKEY_TYPE_SHA256;
689 if (strncmp(bp, "<url", 4))
691 bp = strchr(bp, '>');
695 ep = strstr(bp, "repodata/repomd.xml</url>");
699 if (strncmp(bp, "http", 4))
701 urls = sat_extend(urls, nurls, 1, sizeof(*urls), 15);
702 urls[nurls++] = strdup(bp);
707 findfastest(urls, nurls > 5 ? 5 : nurls);
710 for (i = 0; i < nurls; i++)
713 ep = strchr(bp, '/');
714 if ((ep = strchr(ep + 2, '/')) != 0)
717 printf("[using mirror %s]\n", bp);
726 findmirrorlisturl(FILE *fp)
728 char buf[4096], *bp, *ep;
733 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
735 while (*bp == ' ' || *bp == '\t')
737 if (!*bp || *bp == '#')
740 while (l > 0 && (bp[l - 1] == ' ' || bp[l - 1] == '\t' || bp[l - 1] == '\n'))
742 urls = sat_extend(urls, nurls, 1, sizeof(*urls), 15);
743 urls[nurls++] = strdup(bp);
748 findfastest(urls, nurls > 5 ? 5 : nurls);
751 for (i = 0; i < nurls; i++)
754 ep = strchr(bp, '/');
755 if ((ep = strchr(ep + 2, '/')) != 0)
758 printf("[using mirror %s]\n", bp);
767 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int *badchecksump)
773 const char *baseurl = cinfo->baseurl;
777 if (!cinfo->metalink && !cinfo->mirrorlist)
779 if (file != cinfo->metalink && file != cinfo->mirrorlist)
781 FILE *fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
782 unsigned char mlchksum[32];
787 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
789 cinfo->baseurl = findmirrorlisturl(fp);
794 if (strchr(cinfo->baseurl, '$'))
796 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
797 free(cinfo->baseurl);
798 cinfo->baseurl = strdup(b);
801 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
803 chksumtype = mlchksumtype;
806 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, badchecksump);
808 snprintf(url, sizeof(url), "%s", file);
813 if (l && baseurl[l - 1] == '/')
814 snprintf(url, sizeof(url), "%s%s", baseurl, file);
816 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
819 // printf("url: %s\n", url);
820 if ((pid = fork()) == (pid_t)-1)
832 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
837 while (waitpid(pid, &status, 0) != pid)
839 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
845 lseek(fd, 0, SEEK_SET);
848 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
854 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
866 sprintf(tmpl, "/dev/fd/%d", fd);
867 gzf = gzopen(tmpl, "r");
871 fprintf(stderr, "could not open /dev/fd/%d, /proc not mounted?\n", fd);
874 return mygzfopen(gzf);
876 fcntl(fd, F_SETFD, FD_CLOEXEC);
877 return fdopen(fd, "r");
883 cleanupgpg(char *gpgdir)
886 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
888 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
890 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
892 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
894 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
900 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
909 off_t posfp, possigfp;
912 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
915 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
916 if (!(kfp = fopen(keysfile, "w")) )
922 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
926 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
927 if (!pubkey || !*pubkey)
929 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
931 if (fputc('\n', kfp) == EOF) /* Just in case... */
935 if (fclose(kfp) || !nkeys)
940 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
943 fprintf(stderr, "key import error\n");
948 posfp = lseek(fileno(fp), 0, SEEK_CUR);
949 lseek(fileno(fp), 0, SEEK_SET);
950 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
951 lseek(fileno(sigfp), 0, SEEK_SET);
952 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
953 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
954 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
956 lseek(fileno(sigfp), possigfp, SEEK_SET);
957 lseek(fileno(fp), posfp, SEEK_SET);
958 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
959 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
961 return r == 0 ? 1 : 0;
967 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
972 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));
973 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
974 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
976 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
977 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
978 return r == 0 ? 1 : 0;
983 #define CHKSUM_IDENT "1.1"
986 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
989 void *h = sat_chksum_create(chktype);
992 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
993 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
994 sat_chksum_add(h, buf, l);
996 sat_chksum_free(h, out);
1000 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *out)
1002 void *h = sat_chksum_create(chktype);
1003 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1004 sat_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
1005 sat_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
1006 sat_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
1007 sat_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
1008 sat_chksum_free(h, out);
1020 pool_setarch(pool, un.machine);
1023 char *calccachepath(Repo *repo, const char *repoext)
1025 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
1028 p = pool_tmpjoin(repo->pool, p, "_", repoext);
1029 p = pool_tmpjoin(repo->pool, p, ".solvx", 0);
1032 p = pool_tmpjoin(repo->pool, p, ".solv", 0);
1033 q = p + strlen(SOLVCACHE_PATH) + 1;
1043 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1046 unsigned char mycookie[32];
1047 unsigned char myextcookie[32];
1048 struct repoinfo *cinfo;
1051 cinfo = repo->appdata;
1052 if (!(fp = fopen(calccachepath(repo, repoext), "r")))
1054 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1059 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1064 if (cinfo && !repoext)
1066 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1077 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1078 if (strcmp(repoext, "DL") != 0)
1079 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1082 if (repo_add_solv_flags(repo, fp, flags))
1087 if (cinfo && !repoext)
1089 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1090 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1093 futimes(fileno(fp), 0); /* try to set modification time */
1099 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1104 struct repoinfo *cinfo;
1107 cinfo = repo->appdata;
1108 mkdir(SOLVCACHE_PATH, 0755);
1109 tmpl = sat_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
1117 if (!(fp = fdopen(fd, "w")))
1126 for (i = repo->start; i < repo->end; i++)
1127 if (repo->pool->solvables[i].repo != repo)
1133 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
1135 repodata_write(info, fp, repo_write_stdkeyfilter, 0);
1138 int oldnrepodata = repo->nrepodata;
1139 repo->nrepodata = 1; /* XXX: do this right */
1140 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
1141 repo->nrepodata = oldnrepodata;
1145 if (!repoext && cinfo)
1147 if (!cinfo->extcookie[0])
1149 /* create the ext cookie and append it */
1150 /* we just need some unique ID */
1152 if (!fstat(fileno(fp), &stb))
1156 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cinfo->extcookie);
1157 for (i = 0; i < 32; i++)
1158 cinfo->extcookie[i] ^= cookie[i];
1160 if (cinfo->extcookie[0] == 0)
1161 cinfo->extcookie[0] = 1;
1163 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1171 /* append our cookie describing the metadata state */
1172 if (fwrite(cookie, 32, 1, fp) != 1)
1187 /* switch to just saved repo to activate paging and save memory */
1188 FILE *fp = fopen(tmpl, "r");
1194 repo_empty(repo, 1);
1195 if (repo_add_solv_flags(repo, fp, SOLV_ADD_NO_STUBS))
1197 /* oops, no way to recover from here */
1198 fprintf(stderr, "internal error\n");
1204 /* make sure repodata contains complete repo */
1205 /* (this is how repodata_write saves it) */
1206 repodata_extend_block(info, repo->start, repo->end - repo->start);
1207 info->state = REPODATA_LOADING;
1208 /* no need for LOCALPOOL as pool already contains ids */
1209 repo_add_solv_flags(repo, fp, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1210 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1215 if (!rename(tmpl, calccachepath(repo, repoext)))
1224 Pool *sigpool = pool_create();
1226 Repo *repo = repo_create(sigpool, "rpmdbkeys");
1227 repo_add_rpmdb_pubkeys(repo, 0, 0);
1233 /* repomd helpers */
1235 static inline const char *
1236 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1238 Pool *pool = repo->pool;
1240 const char *filename;
1245 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1246 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1247 if (dataiterator_step(&di))
1249 dataiterator_setpos_parent(&di);
1250 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1251 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1253 dataiterator_free(&di);
1254 if (filename && !*chksumtypep)
1256 printf("no %s file checksum!\n", what);
1263 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1265 Pool *pool = repo->pool;
1267 Id chksumtype, handle;
1268 const unsigned char *chksum;
1269 const char *filename;
1271 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1272 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1273 if (!dataiterator_step(&di))
1275 dataiterator_free(&di);
1278 if (!strcmp(what, "prestodelta"))
1280 dataiterator_setpos_parent(&di);
1281 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1282 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, &chksumtype);
1283 if (!filename || !chksum)
1285 dataiterator_free(&di);
1288 handle = repodata_new_handle(data);
1289 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1290 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1292 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1293 if (!strcmp(what, "deltainfo"))
1295 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1296 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1298 if (!strcmp(what, "filelists"))
1300 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1301 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1303 dataiterator_free(&di);
1304 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1309 /* susetags helpers */
1311 static inline const char *
1312 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1314 Pool *pool = repo->pool;
1316 const char *filename;
1321 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
1322 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1323 if (dataiterator_step(&di))
1325 dataiterator_setpos_parent(&di);
1326 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
1329 dataiterator_free(&di);
1330 if (filename && !*chksumtypep)
1332 printf("no %s file checksum!\n", what);
1338 static Id susetags_langtags[] = {
1339 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
1340 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
1341 SOLVABLE_EULA, REPOKEY_TYPE_STR,
1342 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
1343 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
1344 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
1349 susetags_add_ext(Repo *repo, Repodata *data)
1351 Pool *pool = repo->pool;
1354 Id handle, filechksumtype;
1355 const unsigned char *filechksum;
1358 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
1359 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1360 while (dataiterator_step(&di))
1362 if (strncmp(di.kv.str, "packages.", 9) != 0)
1364 if (!strcmp(di.kv.str + 9, "gz"))
1366 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
1368 ext[0] = di.kv.str[9];
1369 ext[1] = di.kv.str[10];
1371 if (!strcmp(ext, "en"))
1373 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
1375 handle = repodata_new_handle(data);
1376 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
1378 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
1379 if (!strcmp(ext, "DU"))
1381 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
1382 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
1384 else if (!strcmp(ext, "FL"))
1386 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1387 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1391 for (i = 0; susetags_langtags[i]; i += 2)
1393 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
1394 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
1397 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1399 dataiterator_free(&di);
1404 iscompressed(const char *name)
1406 int l = strlen(name);
1407 return l > 3 && !strcmp(name + l - 3, ".gz") ? 1 : 0;
1414 load_stub(Pool *pool, Repodata *data, void *dp)
1416 const char *filename, *descrdir, *repomdtype;
1417 const unsigned char *filechksum;
1419 struct repoinfo *cinfo;
1424 cinfo = data->repo->appdata;
1426 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1430 ext[0] = filename[9];
1431 ext[1] = filename[10];
1434 printf("[%s:%s", data->repo->name, ext);
1436 if (usecachedrepo(data->repo, ext, cinfo->extcookie, 0))
1438 printf(" cached]\n"); fflush(stdout);
1442 printf(" fetching]\n"); fflush(stdout);
1444 defvendor = repo_lookup_id(data->repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1445 descrdir = repo_lookup_str(data->repo, SOLVID_META, SUSETAGS_DESCRDIR);
1447 descrdir = "suse/setup/descr";
1449 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1450 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1452 repo_add_susetags(data->repo, fp, defvendor, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1454 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
1458 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1461 if (!strcmp(repomdtype, "filelists"))
1463 else if (!strcmp(repomdtype, "deltainfo"))
1468 printf("[%s:%s", data->repo->name, ext);
1470 if (usecachedrepo(data->repo, ext, cinfo->extcookie, 0))
1472 printf(" cached]\n");fflush(stdout);
1475 printf(" fetching]\n"); fflush(stdout);
1476 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1478 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1479 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1481 if (!strcmp(ext, "FL"))
1482 repo_add_rpmmd(data->repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1483 else if (!strcmp(ext, "DL"))
1484 repo_add_deltainfoxml(data->repo, fp, REPO_USE_LOADING);
1486 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
1493 static unsigned char installedcookie[32];
1497 repo_add_debdb(Repo *repo, int flags)
1500 if ((fp = fopen("/var/lib/dpkg/status", "r")) == 0)
1502 perror("/var/lib/dpkg/status");
1505 repo_add_debpackages(repo, fp, flags);
1510 hexstr2bytes(unsigned char *buf, const char *str, int buflen)
1513 for (i = 0; i < buflen; i++)
1515 #define c2h(c) (((c)>='0' && (c)<='9') ? ((c)-'0') \
1516 : ((c)>='a' && (c)<='f') ? ((c)-('a'-10)) \
1517 : ((c)>='A' && (c)<='F') ? ((c)-('A'-10)) \
1528 buf[i] = (buf[i] << 4) | v;
1535 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1539 unsigned char *chksum;
1544 static char *basearch;
1556 basearch = strdup(un.machine);
1557 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
1560 binarydir = sat_dupjoin("binary-", basearch, "/");
1561 lbinarydir = strlen(binarydir);
1562 compl = strlen(comp);
1566 chksum = sat_malloc(32);
1568 while(fgets(buf, sizeof(buf), fp))
1573 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1575 if (!strncasecmp(buf, "MD5Sum:", 7))
1577 curchksumtype = REPOKEY_TYPE_MD5;
1580 if (!strncasecmp(buf, "SHA1:", 5))
1582 curchksumtype = REPOKEY_TYPE_SHA1;
1585 if (!strncasecmp(buf, "SHA256:", 7))
1587 curchksumtype = REPOKEY_TYPE_SHA256;
1599 while (*bp && *bp != ' ' && *bp != '\t')
1604 while (*bp == ' ' || *bp == '\t')
1606 while (*bp && *bp != ' ' && *bp != '\t')
1610 while (*bp == ' ' || *bp == '\t')
1613 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1616 if (strncmp(bp, binarydir, lbinarydir))
1619 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1621 if (filename && !strcmp(bp, "Packages"))
1623 if (chksumtype && sat_chksum_len(chksumtype) > sat_chksum_len(curchksumtype))
1625 if (!hexstr2bytes(chksum, ch, sat_chksum_len(curchksumtype)))
1628 filename = strdup(fn);
1629 chksumtype = curchksumtype;
1635 fn = sat_dupjoin("/", filename, 0);
1637 filename = sat_dupjoin("dists/", cinfo->name, fn);
1641 chksum = sat_free(chksum);
1643 *chksumtypep = chksumtype;
1649 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1652 struct repoinfo *cinfo;
1656 const char *filename;
1657 const unsigned char *filechksum;
1659 const char *descrdir;
1671 repo = repo_create(pool, "@System");
1673 printf("rpm database:");
1674 if (stat("/var/lib/rpm/Packages", &stb))
1675 memset(&stb, 0, sizeof(&stb));
1677 printf("dpgk database:");
1678 if (stat("/var/lib/dpkg/status", &stb))
1679 memset(&stb, 0, sizeof(&stb));
1681 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, installedcookie);
1682 if (usecachedrepo(repo, 0, installedcookie, 0))
1683 printf(" cached\n");
1690 printf(" reading\n");
1692 #ifdef PRODUCTS_PATH
1693 repo_add_products(repo, PRODUCTS_PATH, 0, REPO_NO_INTERNALIZE);
1696 if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
1698 Repo *ref = repo_create(pool, "@System.old");
1699 if (!repo_add_solv(ref, ofp))
1701 repo_add_rpmdb(repo, ref, 0, REPO_REUSE_REPODATA);
1708 repo_add_rpmdb(repo, 0, 0, REPO_REUSE_REPODATA);
1710 repo_add_debdb(repo, REPO_REUSE_REPODATA);
1712 writecachedrepo(repo, 0, 0, installedcookie);
1714 pool_set_installed(pool, repo);
1716 for (i = 0; i < nrepoinfos; i++)
1718 cinfo = repoinfos + i;
1719 if (!cinfo->enabled)
1722 repo = repo_create(pool, cinfo->alias);
1724 repo->appdata = cinfo;
1725 repo->priority = 99 - cinfo->priority;
1727 dorefresh = cinfo->autorefresh;
1728 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0), &stb) == 0)
1730 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1733 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1735 printf("repo '%s':", cinfo->alias);
1736 printf(" cached\n");
1740 switch (cinfo->type)
1743 printf("rpmmd repo '%s':", cinfo->alias);
1745 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1747 printf(" no repomd.xml file, skipped\n");
1752 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1753 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1755 printf(" cached\n");
1759 if (cinfo->repo_gpgcheck)
1761 sigfp = curlfopen(cinfo, "repodata/repomd.xml.asc", 0, 0, 0, 0);
1764 printf(" unsigned, skipped\n");
1769 sigpool = read_sigs();
1770 if (!checksig(sigpool, fp, sigfp))
1772 printf(" checksig failed, skipped\n");
1779 repo_add_repomdxml(repo, fp, 0);
1781 printf(" fetching\n");
1782 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1783 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1785 repo_add_rpmmd(repo, fp, 0, 0);
1789 break; /* hopeless */
1791 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1792 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1794 repo_add_updateinfoxml(repo, fp, 0);
1798 data = repo_add_repodata(repo, 0);
1799 if (!repomd_add_ext(repo, data, "deltainfo"))
1800 repomd_add_ext(repo, data, "prestodelta");
1801 repomd_add_ext(repo, data, "filelists");
1802 repodata_internalize(data);
1804 writecachedrepo(repo, 0, 0, cinfo->cookie);
1805 repodata_create_stubs(repo_last_repodata(repo));
1809 printf("susetags repo '%s':", cinfo->alias);
1813 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1815 printf(" no content file, skipped\n");
1820 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1821 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1823 printf(" cached\n");
1827 if (cinfo->repo_gpgcheck)
1829 sigfp = curlfopen(cinfo, "content.asc", 0, 0, 0, 0);
1832 printf(" unsigned, skipped\n");
1839 sigpool = read_sigs();
1840 if (!checksig(sigpool, fp, sigfp))
1842 printf(" checksig failed, skipped\n");
1850 repo_add_content(repo, fp, 0);
1852 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1853 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1855 descrdir = "suse/setup/descr";
1856 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1858 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1861 printf(" no packages file entry, skipped\n");
1864 printf(" fetching\n");
1865 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) == 0)
1866 break; /* hopeless */
1867 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE);
1869 /* add default language */
1870 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1872 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1875 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1877 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES);
1881 repo_internalize(repo);
1882 data = repo_add_repodata(repo, 0);
1883 susetags_add_ext(repo, data);
1884 repodata_internalize(data);
1886 writecachedrepo(repo, 0, 0, cinfo->cookie);
1887 repodata_create_stubs(repo_last_repodata(repo));
1892 printf("debian repo '%s':", cinfo->alias);
1894 filename = sat_dupjoin("dists/", cinfo->name, "/Release");
1895 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
1897 printf(" no Release file, skipped\n");
1900 free((char *)filename);
1903 sat_free((char *)filename);
1904 if (cinfo->repo_gpgcheck)
1906 filename = sat_dupjoin("dists/", cinfo->name, "/Release.gpg");
1907 sigfp = curlfopen(cinfo, filename, 0, 0, 0, 0);
1908 sat_free((char *)filename);
1911 printf(" unsigned, skipped\n");
1916 sigpool = read_sigs();
1917 if (!checksig(sigpool, fpr, sigfp))
1919 printf(" checksig failed, skipped\n");
1926 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
1927 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1929 printf(" cached\n");
1933 printf(" fetching\n");
1934 for (j = 0; j < cinfo->ncomponents; j++)
1936 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
1938 printf("[component %s not found]\n", cinfo->components[j]);
1941 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1943 repo_add_debpackages(repo, fp, 0);
1946 sat_free((char *)filechksum);
1947 sat_free((char *)filename);
1951 writecachedrepo(repo, 0, 0, cinfo->cookie);
1956 printf("unsupported repo '%s': skipped\n", cinfo->alias);
1968 str2archid(Pool *pool, char *arch)
1973 id = str2id(pool, arch, 0);
1974 if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH)
1976 if (pool->id2arch && (id > pool->lastarch || !pool->id2arch[id]))
1982 #define DEPGLOB_NAME 1
1983 #define DEPGLOB_DEP 2
1984 #define DEPGLOB_NAMEDEP 3
1987 depglob(Pool *pool, char *name, Queue *job, int what)
1990 Id id = str2id(pool, name, 0);
1995 FOR_PROVIDES(p, pp, id)
1997 Solvable *s = pool->solvables + p;
1999 if (s->name == id && (what & DEPGLOB_NAME) != 0)
2001 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
2007 if (what == DEPGLOB_NAMEDEP)
2008 printf("[using capability match for '%s']\n", name);
2009 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
2014 if (strpbrk(name, "[*?") == 0)
2017 if ((what & DEPGLOB_NAME) != 0)
2019 /* looks like a name glob. hard work. */
2020 for (p = 1; p < pool->nsolvables; p++)
2022 Solvable *s = pool->solvables + p;
2023 if (!s->repo || !pool_installable(pool, s))
2026 if (fnmatch(name, id2str(pool, id), 0) == 0)
2028 for (i = 0; i < job->count; i += 2)
2029 if (job->elements[i] == SOLVER_SOLVABLE_NAME && job->elements[i + 1] == id)
2031 if (i == job->count)
2032 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
2039 if ((what & DEPGLOB_DEP))
2041 /* looks like a dep glob. really hard work. */
2042 for (id = 1; id < pool->ss.nstrings; id++)
2044 if (!pool->whatprovides[id])
2046 if (fnmatch(name, id2str(pool, id), 0) == 0)
2048 if (!match && what == DEPGLOB_NAMEDEP)
2049 printf("[using capability match for '%s']\n", name);
2050 for (i = 0; i < job->count; i += 2)
2051 if (job->elements[i] == SOLVER_SOLVABLE_PROVIDES && job->elements[i + 1] == id)
2053 if (i == job->count)
2054 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
2065 limitrelation(Pool *pool, Queue *job, int flags, Id evr)
2069 for (i = j = 0; i < job->count; i += 2)
2071 Id select = job->elements[i] & SOLVER_SELECTMASK;
2072 if (select != SOLVER_SOLVABLE_NAME && select != SOLVER_SOLVABLE_PROVIDES)
2074 fprintf(stderr, "limitrelation only works on name/provides jobs\n");
2077 job->elements[i + 1] = rel2id(pool, job->elements[i + 1], evr, flags, 1);
2078 if (flags == REL_ARCH)
2079 job->elements[i] |= SOLVER_SETARCH;
2080 if (flags == REL_EQ && select == SOLVER_SOLVABLE_NAME && job->elements[i])
2083 const char *evrstr = id2str(pool, evr);
2084 if (!strchr(evrstr, '-'))
2085 job->elements[i] |= SOLVER_SETEV;
2088 job->elements[i] |= SOLVER_SETEVR;
2090 /* make sure we still have matches */
2091 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2095 job->elements[j] = job->elements[i];
2096 job->elements[j + 1] = job->elements[i + 1];
2100 queue_truncate(job, j);
2105 limitrelation_arch(Pool *pool, Queue *job, int flags, char *evr)
2109 if ((r = strrchr(evr, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2112 limitrelation(pool, job, REL_ARCH, archid);
2113 limitrelation(pool, job, flags, str2id(pool, evr, 1));
2117 limitrelation(pool, job, flags, str2id(pool, evr, 1));
2118 return job->count / 2;
2122 limitrepo(Pool *pool, Id repofilter, Queue *job)
2130 for (i = j = 0; i < job->count; i += 2)
2133 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2135 s = pool_id2solvable(pool, p);
2136 if (s->repo && s->repo->repoid == repofilter)
2141 /* here we assume that repo == vendor, so we also set SOLVER_SETVENDOR */
2144 job->elements[j] = SOLVER_SOLVABLE | (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO | SOLVER_NOAUTOSET;
2145 job->elements[j + 1] = mq.elements[0];
2149 job->elements[j] = SOLVER_SOLVABLE_ONE_OF | (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO;
2150 job->elements[j + 1] = pool_queuetowhatprovides(pool, &mq);
2155 queue_truncate(job, j);
2161 mkselect(Pool *pool, int mode, char *name, Queue *job)
2169 int type = strpbrk(name, "[*?") == 0 ? SEARCH_STRING : SEARCH_GLOB;
2172 dataiterator_init(&di, pool, mode == SOLVER_ERASE ? pool->installed : 0, 0, SOLVABLE_FILELIST, name, type|SEARCH_FILES|SEARCH_COMPLETE_FILELIST);
2173 while (dataiterator_step(&di))
2175 Solvable *s = pool->solvables + di.solvid;
2176 if (!s->repo || !pool_installable(pool, s))
2178 queue_push(&q, di.solvid);
2179 dataiterator_skip_solvable(&di);
2181 dataiterator_free(&di);
2184 printf("[using file list match for '%s']\n", name);
2186 queue_push2(job, SOLVER_SOLVABLE_ONE_OF, pool_queuetowhatprovides(pool, &q));
2188 queue_push2(job, SOLVER_SOLVABLE | SOLVER_NOAUTOSET, q.elements[0]);
2190 return job->count / 2;
2193 if ((r = strpbrk(name, "<=>")) != 0)
2195 /* relation case, support:
2200 int nend = r - name;
2213 while (*r && *r == ' ' && *r == '\t')
2215 while (nend && (name[nend - 1] == ' ' || name[nend -1 ] == '\t'))
2219 fprintf(stderr, "bad relation\n");
2222 oldnend = name[nend];
2224 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2226 name[nend] = oldnend;
2227 limitrelation(pool, job, rflags, str2id(pool, r, 1));
2228 return job->count / 2;
2230 if ((r2 = strrchr(name, '.')) != 0 && r2[1] && (archid = str2archid(pool, r2 + 1)) != 0)
2233 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2235 name[nend] = oldnend;
2237 limitrelation(pool, job, REL_ARCH, archid);
2238 limitrelation(pool, job, rflags, str2id(pool, r, 1));
2239 return job->count / 2;
2243 name[nend] = oldnend;
2247 /* no relation case, support:
2251 * nameglob-version.arch
2252 * nameglob-version-release
2253 * nameglob-version-release.arch
2255 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2256 return job->count / 2;
2257 if ((r = strrchr(name, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2260 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2263 limitrelation(pool, job, REL_ARCH, archid);
2264 return job->count / 2;
2268 if ((r = strrchr(name, '-')) != 0)
2271 if (depglob(pool, name, job, DEPGLOB_NAME))
2273 /* have just the version */
2274 limitrelation_arch(pool, job, REL_EQ, r + 1);
2276 return job->count / 2;
2278 if ((r2 = strrchr(name, '-')) != 0)
2283 if (depglob(pool, name, job, DEPGLOB_NAME))
2285 /* have version-release */
2286 limitrelation_arch(pool, job, REL_EQ, r + 1);
2288 return job->count / 2;
2299 yesno(const char *str)
2301 char inbuf[128], *ip;
2308 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2313 while (*ip == ' ' || *ip == '\t')
2320 if (*ip == 'y' || *ip == 'n')
2321 return *ip == 'y' ? 1 : 0;
2335 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2337 struct fcstate *fcstate = cbdata;
2345 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
2348 s = pool_id2solvable(pool, p);
2349 if (pool->installed && s->repo == pool->installed)
2351 if (!s->repo->rpmdbid)
2353 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2356 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
2358 for (i = 0; i < fcstate->newpkgscnt; i++)
2359 if (fcstate->checkq->elements[i] == p)
2361 if (i == fcstate->newpkgscnt)
2363 fp = fcstate->newpkgsfps[i];
2367 return rpm_byfp(fp, solvable2str(pool, s), &fcstate->rpmdbstate);
2372 runrpm(const char *arg, const char *name, int dupfd3)
2377 if ((pid = fork()) == (pid_t)-1)
2384 if (dupfd3 != -1 && dupfd3 != 3)
2390 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2391 if (strcmp(arg, "-e") == 0)
2392 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2394 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2398 while (waitpid(pid, &status, 0) != pid)
2402 printf("rpm failed\n");
2412 rundpkg(const char *arg, const char *name, int dupfd3)
2417 if ((pid = fork()) == (pid_t)-1)
2424 if (dupfd3 != -1 && dupfd3 != 3)
2430 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2431 if (strcmp(arg, "--install") == 0)
2432 execlp("dpkg", "dpkg", "--install", "--force", "all", name, (char *)0);
2434 execlp("dpkg", "dpkg", "--remove", "--force", "all", name, (char *)0);
2438 while (waitpid(pid, &status, 0) != pid)
2442 printf("dpkg failed\n");
2450 nscallback(Pool *pool, void *data, Id name, Id evr)
2452 if (name == NAMESPACE_PRODUCTBUDDY)
2454 /* SUSE specific hack: each product has an associated rpm */
2455 Solvable *s = pool->solvables + evr;
2458 cap = str2id(pool, pool_tmpjoin(pool, "product(", id2str(pool, s->name) + 8, ")"), 0);
2461 cap = rel2id(pool, cap, s->evr, REL_EQ, 0);
2464 FOR_PROVIDES(p, pp, cap)
2466 Solvable *ps = pool->solvables + p;
2467 if (ps->repo == s->repo && ps->arch == s->arch)
2475 #ifdef SOFTLOCKS_PATH
2478 addsoftlocks(Pool *pool, Queue *job)
2482 char *bp, *ep, buf[4096];
2484 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2486 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2488 while (*bp == ' ' || *bp == '\t')
2490 if (!*bp || *bp == '#')
2492 for (ep = bp; *ep; ep++)
2493 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2496 type = SOLVER_SOLVABLE_NAME;
2497 if (!strncmp(bp, "provides:", 9) && bp[9])
2499 type = SOLVER_SOLVABLE_PROVIDES;
2502 id = str2id(pool, bp, 1);
2503 if (pool->installed)
2505 FOR_JOB_SELECT(p, pp, type, id)
2506 if (pool->solvables[p].repo == pool->installed)
2509 continue; /* ignore, as it is already installed */
2511 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2520 rewrite_repos(Pool *pool, Id *addedfileprovides)
2525 Queue fileprovidesq;
2527 int i, j, n, nprovidedids;
2528 struct repoinfo *cinfo;
2530 map_init(&providedids, pool->ss.nstrings);
2531 queue_init(&fileprovidesq);
2532 for (nprovidedids = 0; (id = addedfileprovides[nprovidedids]) != 0; nprovidedids++)
2533 MAPSET(&providedids, id);
2536 /* make sure this repo has just one main repodata */
2537 if (!repo->nrepodata)
2539 cinfo = repo->appdata;
2540 data = repo->repodata + 0;
2541 if (data->store.pagefd == -1)
2543 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2546 for (j = 0; j < fileprovidesq.count; j++)
2547 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2549 if (n == nprovidedids)
2550 continue; /* nothing new added */
2553 for (j = 0; addedfileprovides[j]; j++)
2554 repodata_add_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, addedfileprovides[j]);
2555 repodata_internalize(data);
2556 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2558 queue_free(&fileprovidesq);
2559 map_free(&providedids);
2563 #define MODE_INSTALL 1
2564 #define MODE_ERASE 2
2565 #define MODE_UPDATE 3
2566 #define MODE_DISTUPGRADE 4
2567 #define MODE_VERIFY 5
2568 #define MODE_PATCH 6
2570 #define MODE_REPOLIST 8
2571 #define MODE_SEARCH 9
2572 #define MODE_ERASECLEAN 10
2577 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2578 fprintf(stderr, "\n");
2579 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2580 fprintf(stderr, " versions from the repositories\n");
2581 fprintf(stderr, " erase: erase installed packages\n");
2582 fprintf(stderr, " info: display package information\n");
2583 fprintf(stderr, " install: install packages\n");
2584 fprintf(stderr, " list: list packages\n");
2585 fprintf(stderr, " repos: list enabled repositories\n");
2586 fprintf(stderr, " search: search name/summary/description\n");
2587 fprintf(stderr, " update: update installed packages\n");
2588 fprintf(stderr, " verify: check dependencies of installed packages\n");
2589 fprintf(stderr, "\n");
2594 main(int argc, char **argv)
2597 Repo *commandlinerepo = 0;
2598 Id *commandlinepkgs = 0;
2600 struct repoinfo *repoinfos;
2602 int mainmode = 0, mode = 0;
2607 char inbuf[128], *ip;
2610 Id *addedfileprovides = 0;
2617 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2619 mainmode = MODE_INSTALL;
2620 mode = SOLVER_INSTALL;
2622 else if (!strcmp(argv[0], "patch"))
2624 mainmode = MODE_PATCH;
2625 mode = SOLVER_INSTALL;
2627 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2629 mainmode = MODE_ERASE;
2630 mode = SOLVER_ERASE;
2632 else if (!strcmp(argv[0], "eraseclean") || !strcmp(argv[0], "rmclean"))
2634 mainmode = MODE_ERASECLEAN;
2635 mode = SOLVER_ERASE;
2637 else if (!strcmp(argv[0], "list"))
2639 mainmode = MODE_LIST;
2642 else if (!strcmp(argv[0], "info"))
2644 mainmode = MODE_INFO;
2647 else if (!strcmp(argv[0], "search"))
2649 mainmode = MODE_SEARCH;
2652 else if (!strcmp(argv[0], "verify"))
2654 mainmode = MODE_VERIFY;
2655 mode = SOLVER_VERIFY;
2657 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2659 mainmode = MODE_UPDATE;
2660 mode = SOLVER_UPDATE;
2662 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2664 mainmode = MODE_DISTUPGRADE;
2665 mode = SOLVER_UPDATE;
2667 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2669 mainmode = MODE_REPOLIST;
2675 pool = pool_create();
2679 const char *langs[] = {"de_DE", "de", "en"};
2680 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2685 pool->obsoleteusescolors = 1;
2687 pool_setloadcallback(pool, load_stub, 0);
2688 pool->nscallback = nscallback;
2689 // pool_setdebuglevel(pool, 2);
2691 repoinfos = read_repoinfos(pool, REPOINFO_PATH, &nrepoinfos);
2693 if (mainmode == MODE_REPOLIST)
2696 for (i = 0; i < nrepoinfos; i++)
2698 struct repoinfo *cinfo = repoinfos + i;
2699 if (!cinfo->enabled)
2701 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2706 read_repos(pool, repoinfos, nrepoinfos);
2708 if (argc > 2 && !strcmp(argv[1], "-r"))
2710 const char *rname = argv[2], *rp;
2711 for (rp = rname; *rp; rp++)
2712 if (*rp <= '0' || *rp >= '9')
2716 /* repo specified by number */
2717 int rnum = atoi(rname);
2718 for (i = 0; i < nrepoinfos; i++)
2720 struct repoinfo *cinfo = repoinfos + i;
2721 if (!cinfo->enabled)
2724 repofilter = cinfo->repo->repoid;
2729 /* repo specified by alias */
2733 if (!strcasecmp(rname, repo->name))
2734 repofilter = repo->repoid;
2739 fprintf(stderr, "%s: no such repo\n", rname);
2745 if (mainmode == MODE_SEARCH)
2751 map_init(&m, pool->nsolvables);
2752 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2753 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2754 dataiterator_set_search(&di, 0, 0);
2755 while (dataiterator_step(&di))
2756 MAPSET(&m, di.solvid);
2757 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2758 dataiterator_set_search(&di, 0, 0);
2759 while (dataiterator_step(&di))
2760 MAPSET(&m, di.solvid);
2761 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2762 dataiterator_set_search(&di, 0, 0);
2763 while (dataiterator_step(&di))
2764 MAPSET(&m, di.solvid);
2765 dataiterator_free(&di);
2767 for (p = 1; p < pool->nsolvables; p++)
2769 Solvable *s = pool_id2solvable(pool, p);
2772 printf(" - %s: %s\n", solvable2str(pool, s), solvable_lookup_str(s, SOLVABLE_SUMMARY));
2779 if (mainmode == MODE_LIST || mainmode == MODE_INSTALL)
2781 for (i = 1; i < argc; i++)
2784 l = strlen(argv[i]);
2786 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2789 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2792 if (access(argv[i], R_OK))
2797 if (!commandlinepkgs)
2798 commandlinepkgs = sat_calloc(argc, sizeof(Id));
2799 if (!commandlinerepo)
2800 commandlinerepo = repo_create(pool, "@commandline");
2802 repo_add_rpms(commandlinerepo, (const char **)argv + i, 1, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2804 repo_add_debs(commandlinerepo, (const char **)argv + i, 1, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2806 commandlinepkgs[i] = commandlinerepo->end - 1;
2808 if (commandlinerepo)
2809 repo_internalize(commandlinerepo);
2812 // FOR_REPOS(i, repo)
2813 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2814 addedfileprovides = 0;
2815 pool_addfileprovides_ids(pool, 0, &addedfileprovides);
2816 if (addedfileprovides && *addedfileprovides)
2817 rewrite_repos(pool, addedfileprovides);
2818 sat_free(addedfileprovides);
2819 pool_createwhatprovides(pool);
2822 for (i = 1; i < argc; i++)
2827 if (commandlinepkgs && commandlinepkgs[i])
2829 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2833 if (!mkselect(pool, mode, argv[i], &job2))
2835 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2838 if (repofilter && !limitrepo(pool, repofilter, &job2))
2840 fprintf(stderr, "nothing in repo matches '%s'\n", argv[i]);
2843 for (j = 0; j < job2.count; j++)
2844 queue_push(&job, job2.elements[j]);
2848 if (!job.count && mainmode != MODE_UPDATE && mainmode != MODE_DISTUPGRADE && mainmode != MODE_VERIFY && mainmode != MODE_PATCH)
2850 printf("no package matched\n");
2857 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
2859 /* list mode, no solver needed */
2860 for (i = 0; i < job.count; i += 2)
2862 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
2864 Solvable *s = pool_id2solvable(pool, p);
2865 if (mainmode == MODE_INFO)
2868 printf("Name: %s\n", solvable2str(pool, s));
2869 printf("Repo: %s\n", s->repo->name);
2870 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
2871 str = solvable_lookup_str(s, SOLVABLE_URL);
2873 printf("Url: %s\n", str);
2874 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
2876 printf("License: %s\n", str);
2877 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
2883 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
2885 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
2887 printf(" - %s [%s]\n", solvable2str(pool, s), s->repo->name);
2889 printf(" %s\n", sum);
2895 free_repoinfos(repoinfos, nrepoinfos);
2896 sat_free(commandlinepkgs);
2898 yum_substitute(pool, 0);
2903 if (mainmode == MODE_PATCH)
2909 map_init(&installedmap, pool->nsolvables);
2910 if (pool->installed)
2911 FOR_REPO_SOLVABLES(pool->installed, p, s)
2912 MAPSET(&installedmap, p);
2914 /* install all patches */
2915 for (p = 1; p < pool->nsolvables; p++)
2921 s = pool->solvables + p;
2922 if (strncmp(id2str(pool, s->name), "patch:", 6) != 0)
2924 FOR_PROVIDES(p2, pp, s->name)
2926 Solvable *s2 = pool->solvables + p2;
2927 if (s2->name != s->name)
2929 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2930 if (r < 0 || (r == 0 && p > p2))
2935 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2936 if (type && !strcmp(type, "optional"))
2938 r = solvable_trivial_installable_map(s, &installedmap, 0);
2941 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2948 queue_push2(&job, SOLVER_SOLVABLE, p);
2950 map_free(&installedmap);
2954 for (i = 0; i < job.count; i += 2)
2956 if (mode == SOLVER_UPDATE)
2958 /* make update of not installed packages an install */
2959 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
2960 if (pool->installed && pool->solvables[p].repo == pool->installed)
2964 job.elements[i] |= SOLVER_INSTALL;
2968 job.elements[i] |= mode;
2969 if (mainmode == MODE_ERASECLEAN)
2970 job.elements[i] |= SOLVER_CLEANDEPS;
2973 if (mainmode == MODE_DISTUPGRADE && allpkgs && repofilter)
2974 queue_push2(&job, SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_REPO, repofilter);
2976 // multiversion test
2977 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae", 1));
2978 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-base", 1));
2979 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-extra", 1));
2981 #ifdef SOFTLOCKS_PATH
2982 addsoftlocks(pool, &job);
2990 Id problem, solution;
2993 solv = solver_create(pool);
2994 solv->ignorealreadyrecommended = 1;
2995 solv->updatesystem = allpkgs && !repofilter && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE);
2996 solv->dosplitprovides = solv->updatesystem;
2997 solv->fixsystem = allpkgs && !repofilter && mainmode == MODE_VERIFY;
2998 if (mainmode == MODE_DISTUPGRADE && allpkgs && !repofilter)
3000 solv->distupgrade = 1;
3001 solv->allowdowngrade = 1;
3002 solv->allowarchchange = 1;
3003 solv->allowvendorchange = 1;
3005 if (mainmode == MODE_ERASE || mainmode == MODE_ERASECLEAN)
3006 solv->allowuninstall = 1; /* don't nag */
3008 solver_solve(solv, &job);
3009 if (!solv->problems.count)
3011 pcnt = solver_problem_count(solv);
3012 printf("Found %d problems:\n", pcnt);
3013 for (problem = 1; problem <= pcnt; problem++)
3016 printf("Problem %d:\n", problem);
3017 solver_printprobleminfo(solv, problem);
3019 scnt = solver_solution_count(solv, problem);
3020 for (solution = 1; solution <= scnt; solution++)
3022 printf("Solution %d:\n", solution);
3023 solver_printsolution(solv, problem, solution);
3028 printf("Please choose a solution: ");
3031 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
3036 while (*ip == ' ' || *ip == '\t')
3038 if (*ip >= '0' && *ip <= '9')
3041 if (take >= 1 && take <= scnt)
3057 solver_take_solution(solv, problem, take, &job);
3063 trans = &solv->trans;
3064 if (!trans->steps.count)
3066 printf("Nothing to do.\n");
3070 free_repoinfos(repoinfos, nrepoinfos);
3071 sat_free(commandlinepkgs);
3073 yum_substitute(pool, 0);
3078 printf("Transaction summary:\n\n");
3079 solver_printtransaction(solv);
3081 #if !defined(FEDORA) && !defined(DEBIAN)
3088 duc[1].path = "/usr/share/man";
3089 duc[2].path = "/sbin";
3090 duc[3].path = "/etc";
3091 transaction_calc_duchanges(trans, duc, 4);
3092 for (i = 0; i < 4; i++)
3093 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
3096 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
3099 if (!yesno("OK to continue (y/n)? "))
3105 free_repoinfos(repoinfos, nrepoinfos);
3106 sat_free(commandlinepkgs);
3108 yum_substitute(pool, 0);
3113 queue_init(&checkq);
3114 newpkgs = transaction_installedresult(trans, &checkq);
3119 int downloadsize = 0;
3120 for (i = 0; i < newpkgs; i++)
3124 p = checkq.elements[i];
3125 s = pool_id2solvable(pool, p);
3126 downloadsize += solvable_lookup_num(s, SOLVABLE_DOWNLOADSIZE, 0);
3128 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
3129 newpkgsfps = sat_calloc(newpkgs, sizeof(*newpkgsfps));
3130 for (i = 0; i < newpkgs; i++)
3132 unsigned int medianr;
3135 struct repoinfo *cinfo;
3136 const unsigned char *chksum;
3140 p = checkq.elements[i];
3141 s = pool_id2solvable(pool, p);
3142 if (s->repo == commandlinerepo)
3144 loc = solvable_get_location(s, &medianr);
3145 if (!(newpkgsfps[i] = fopen(loc, "r")))
3153 cinfo = s->repo->appdata;
3156 printf("%s: no repository information\n", s->repo->name);
3159 loc = solvable_get_location(s, &medianr);
3163 if (pool->installed && pool->installed->nsolvables)
3165 /* try a delta first */
3166 char *matchname = strdup(id2str(pool, s->name));
3167 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
3168 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
3169 while (dataiterator_step(&di))
3173 dataiterator_setpos_parent(&di);
3174 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
3175 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
3177 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
3178 FOR_PROVIDES(op, pp, s->name)
3180 Solvable *os = pool->solvables + op;
3181 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
3184 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
3186 /* base is installed, run sequence check */
3187 const char *seqname;
3196 seqname = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME);
3197 seqevr = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR);
3198 seqnum = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM);
3199 seq = pool_tmpjoin(pool, seqname, "-", seqevr);
3200 seq = pool_tmpjoin(pool, seq, "-", seqnum);
3202 sprintf(cmd, "/usr/bin/applydeltarpm -a %s -c -s ", id2str(pool, s->arch));
3204 sprintf(cmd, "/usr/bin/applydeltarpm -c -s ");
3206 if (system(pool_tmpjoin(pool, cmd, seq, 0)) != 0)
3207 continue; /* didn't match */
3208 /* looks good, download delta */
3210 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
3212 continue; /* no way! */
3213 dloc = pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_DIR);
3214 dloc = pool_tmpjoin(pool, dloc, "/", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_NAME));
3215 dloc = pool_tmpjoin(pool, dloc, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_EVR));
3216 dloc = pool_tmpjoin(pool, dloc, ".", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_SUFFIX));
3217 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
3219 /* got it, now reconstruct */
3220 newfd = opentmpfile();
3222 sprintf(cmd, "applydeltarpm -a %s /dev/fd/%d /dev/fd/%d", id2str(pool, s->arch), fileno(fp), newfd);
3224 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
3226 fcntl(fileno(fp), F_SETFD, 0);
3233 lseek(newfd, 0, SEEK_SET);
3235 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3236 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
3242 newpkgsfps[i] = fdopen(newfd, "r");
3247 dataiterator_free(&di);
3248 sat_free(matchname);
3255 continue; /* delta worked! */
3257 if (cinfo->type == TYPE_SUSETAGS)
3259 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3260 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3263 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3264 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3266 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3279 struct fcstate fcstate;
3281 printf("Searching for file conflicts\n");
3282 queue_init(&conflicts);
3283 fcstate.rpmdbstate = 0;
3284 fcstate.newpkgscnt = newpkgs;
3285 fcstate.checkq = &checkq;
3286 fcstate.newpkgsfps = newpkgsfps;
3287 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fileconflict_cb, &fcstate);
3288 if (conflicts.count)
3291 for (i = 0; i < conflicts.count; i += 5)
3292 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]));
3294 if (yesno("Re-run solver (y/n/q)? "))
3296 for (i = 0; i < newpkgs; i++)
3298 fclose(newpkgsfps[i]);
3299 newpkgsfps = sat_free(newpkgsfps);
3301 pool_add_fileconflicts_deps(pool, &conflicts);
3302 pool_createwhatprovides(pool); /* Hmm... */
3306 queue_free(&conflicts);
3310 printf("Committing transaction:\n\n");
3311 transaction_order(trans, 0);
3312 for (i = 0; i < trans->steps.count; i++)
3315 const char *evr, *evrp, *nvra;
3321 p = trans->steps.elements[i];
3322 s = pool_id2solvable(pool, p);
3323 Id type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3326 case SOLVER_TRANSACTION_ERASE:
3327 printf("erase %s\n", solvid2str(pool, p));
3329 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3331 /* strip epoch from evr */
3332 evr = evrp = id2str(pool, s->evr);
3333 while (*evrp >= '0' && *evrp <= '9')
3335 if (evrp > evr && evrp[0] == ':' && evrp[1])
3337 nvra = pool_tmpjoin(pool, id2str(pool, s->name), "-", evr);
3338 nvra = pool_tmpjoin(pool, nvra, ".", id2str(pool, s->arch));
3339 runrpm("-e", nvra, -1); /* too bad that --querybynumber doesn't work */
3341 rundpkg("--remove", id2str(pool, s->name), 0);
3344 case SOLVER_TRANSACTION_INSTALL:
3345 case SOLVER_TRANSACTION_MULTIINSTALL:
3346 printf("install %s\n", solvid2str(pool, p));
3347 for (j = 0; j < newpkgs; j++)
3348 if (checkq.elements[j] == p)
3350 fp = j < newpkgs ? newpkgsfps[j] : 0;
3354 lseek(fileno(fp), 0, SEEK_SET);
3356 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp));
3358 rundpkg("--install", "/dev/fd/3", fileno(fp));
3368 for (i = 0; i < newpkgs; i++)
3370 fclose(newpkgsfps[i]);
3371 sat_free(newpkgsfps);
3372 queue_free(&checkq);
3376 free_repoinfos(repoinfos, nrepoinfos);
3377 sat_free(commandlinepkgs);
3379 yum_substitute(pool, 0);