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 cinfo->baseurl = strdup(url);
411 cinfo->alias = sat_dupjoin(url, "/", distro);
412 cinfo->name = strdup(distro);
413 cinfo->type = TYPE_DEBIAN;
415 cinfo->autorefresh = 1;
416 cinfo->repo_gpgcheck = 1;
417 cinfo->metadata_expire = METADATA_EXPIRE;
421 while (*kp == ' ' || *kp == '\t')
426 while (*kp && *kp != ' ' && *kp != '\t')
430 cinfo->components = sat_extend(cinfo->components, cinfo->ncomponents, 1, sizeof(*cinfo->components), 15);
431 cinfo->components[cinfo->ncomponents++] = strdup(compo);
437 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
438 *nrepoinfosp = nrepoinfos;
445 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
448 for (i = 0; i < nrepoinfos; i++)
450 struct repoinfo *cinfo = repoinfos + i;
451 sat_free(cinfo->name);
452 sat_free(cinfo->alias);
453 sat_free(cinfo->path);
454 sat_free(cinfo->metalink);
455 sat_free(cinfo->mirrorlist);
456 sat_free(cinfo->baseurl);
457 for (j = 0; j < cinfo->ncomponents; j++)
458 sat_free(cinfo->components[j]);
459 sat_free(cinfo->components);
470 strcpy(tmpl, "/var/tmp/solvXXXXXX");
482 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
489 h = sat_chksum_create(chksumtype);
492 printf("%s: unknown checksum type\n", file);
495 while ((l = read(fd, buf, sizeof(buf))) > 0)
496 sat_chksum_add(h, buf, l);
497 lseek(fd, 0, SEEK_SET);
499 sum = sat_chksum_get(h, &l);
500 if (memcmp(sum, chksum, l))
502 printf("%s: checksum mismatch\n", file);
503 sat_chksum_free(h, 0);
506 sat_chksum_free(h, 0);
511 findfastest(char **urls, int nurls)
518 struct addrinfo hints, *result;;
520 fds = sat_calloc(nurls, sizeof(*fds));
521 socks = sat_calloc(nurls, sizeof(*socks));
522 for (i = 0; i < nurls; i++)
525 p = strchr(urls[i], '/');
538 if ((p2 = strchr(p, '@')) != 0)
541 if (!strncmp("https:", urls[i], 6))
543 else if (!strncmp("ftp:", urls[i], 4))
545 if ((p2 = strrchr(p, ':')) != 0)
554 sprintf(portstr, "%d", port);
555 memset(&hints, 0, sizeof(struct addrinfo));
556 hints.ai_family = AF_UNSPEC;
557 hints.ai_socktype = SOCK_STREAM;
558 hints.ai_flags = AI_NUMERICSERV;
560 if (!getaddrinfo(p, portstr, &hints, &result))
562 socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
565 fcntl(socks[i], F_SETFL, O_NONBLOCK);
566 if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1)
568 if (errno != EINPROGRESS)
575 freeaddrinfo(result);
582 for (i = j = 0; i < nurls; i++)
586 fds[j].fd = socks[i];
587 fds[j].events = POLLOUT;
595 if (poll(fds, j, 10000) <= 0)
597 i = -1; /* something is wrong */
600 for (i = 0; i < j; i++)
601 if ((fds[i].revents & POLLOUT) != 0)
604 socklen_t soel = sizeof(int);
605 if (getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, &soe, &soel) == -1 || soe != 0)
607 /* connect failed, kill socket */
608 for (j = 0; j < nurls; j++)
609 if (socks[j] == fds[i].fd)
622 i = -1; /* something is wrong, no bit was set */
625 /* now i contains the fastest fd index */
628 for (j = 0; j < nurls; j++)
629 if (socks[j] == fds[i].fd)
633 char *url0 = urls[0];
638 for (i = j = 0; i < nurls; i++)
646 findmetalinkurl(FILE *fp, unsigned char *chksump, Id *chksumtypep)
648 char buf[4096], *bp, *ep;
655 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
657 while (*bp == ' ' || *bp == '\t')
659 if (chksumtypep && !*chksumtypep && !strncmp(bp, "<hash type=\"sha256\">", 20))
664 memset(chksump, 0, 32);
665 for (i = 0; i < 64; i++)
668 if (c >= '0' && c <= '9')
669 chksump[i / 2] = chksump[i / 2] * 16 + (c - '0');
670 else if (c >= 'a' && c <= 'f')
671 chksump[i / 2] = chksump[i / 2] * 16 + (c - ('a' - 10));
672 else if (c >= 'A' && c <= 'F')
673 chksump[i / 2] = chksump[i / 2] * 16 + (c - ('A' - 10));
678 *chksumtypep = REPOKEY_TYPE_SHA256;
681 if (strncmp(bp, "<url", 4))
683 bp = strchr(bp, '>');
687 ep = strstr(bp, "repodata/repomd.xml</url>");
691 if (strncmp(bp, "http", 4))
693 urls = sat_extend(urls, nurls, 1, sizeof(*urls), 15);
694 urls[nurls++] = strdup(bp);
699 findfastest(urls, nurls > 5 ? 5 : nurls);
702 for (i = 0; i < nurls; i++)
705 ep = strchr(bp, '/');
706 if ((ep = strchr(ep + 2, '/')) != 0)
709 printf("[using mirror %s]\n", bp);
718 findmirrorlisturl(FILE *fp)
720 char buf[4096], *bp, *ep;
725 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
727 while (*bp == ' ' || *bp == '\t')
729 if (!*bp || *bp == '#')
732 while (l > 0 && (bp[l - 1] == ' ' || bp[l - 1] == '\t' || bp[l - 1] == '\n'))
734 urls = sat_extend(urls, nurls, 1, sizeof(*urls), 15);
735 urls[nurls++] = strdup(bp);
740 findfastest(urls, nurls > 5 ? 5 : nurls);
743 for (i = 0; i < nurls; i++)
746 ep = strchr(bp, '/');
747 if ((ep = strchr(ep + 2, '/')) != 0)
750 printf("[using mirror %s]\n", bp);
759 cookie_gzread(void *cookie, char *buf, size_t nbytes)
761 return gzread((gzFile *)cookie, buf, nbytes);
765 cookie_gzclose(void *cookie)
767 return gzclose((gzFile *)cookie);
771 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int *badchecksump)
777 const char *baseurl = cinfo->baseurl;
781 if (!cinfo->metalink && !cinfo->mirrorlist)
783 if (file != cinfo->metalink && file != cinfo->mirrorlist)
785 FILE *fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
786 unsigned char mlchksum[32];
791 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
793 cinfo->baseurl = findmirrorlisturl(fp);
798 if (strchr(cinfo->baseurl, '$'))
800 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
801 free(cinfo->baseurl);
802 cinfo->baseurl = strdup(b);
805 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
807 chksumtype = mlchksumtype;
810 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, badchecksump);
812 snprintf(url, sizeof(url), "%s", file);
817 if (l && baseurl[l - 1] == '/')
818 snprintf(url, sizeof(url), "%s%s", baseurl, file);
820 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
823 // printf("url: %s\n", url);
824 if ((pid = fork()) == (pid_t)-1)
836 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
841 while (waitpid(pid, &status, 0) != pid)
843 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
849 lseek(fd, 0, SEEK_SET);
852 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
858 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
868 cookie_io_functions_t cio;
871 sprintf(tmpl, "/dev/fd/%d", fd);
872 gzf = gzopen(tmpl, "r");
876 fprintf(stderr, "could not open /dev/fd/%d, /proc not mounted?\n", fd);
879 memset(&cio, 0, sizeof(cio));
880 cio.read = cookie_gzread;
881 cio.close = cookie_gzclose;
882 return fopencookie(gzf, "r", cio);
884 fcntl(fd, F_SETFD, FD_CLOEXEC);
885 return fdopen(fd, "r");
891 cleanupgpg(char *gpgdir)
894 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
896 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
898 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
900 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
902 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
908 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
917 off_t posfp, possigfp;
920 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
923 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
924 if (!(kfp = fopen(keysfile, "w")) )
930 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
934 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
935 if (!pubkey || !*pubkey)
937 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
939 if (fputc('\n', kfp) == EOF) /* Just in case... */
943 if (fclose(kfp) || !nkeys)
948 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
951 fprintf(stderr, "key import error\n");
956 posfp = lseek(fileno(fp), 0, SEEK_CUR);
957 lseek(fileno(fp), 0, SEEK_SET);
958 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
959 lseek(fileno(sigfp), 0, SEEK_SET);
960 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
961 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
962 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
964 lseek(fileno(sigfp), possigfp, SEEK_SET);
965 lseek(fileno(fp), posfp, SEEK_SET);
966 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
967 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
969 return r == 0 ? 1 : 0;
975 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
980 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));
981 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
982 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
984 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
985 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
986 return r == 0 ? 1 : 0;
991 #define CHKSUM_IDENT "1.1"
994 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
997 void *h = sat_chksum_create(chktype);
1000 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1001 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
1002 sat_chksum_add(h, buf, l);
1004 sat_chksum_free(h, out);
1008 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *out)
1010 void *h = sat_chksum_create(chktype);
1011 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1012 sat_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
1013 sat_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
1014 sat_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
1015 sat_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
1016 sat_chksum_free(h, out);
1028 pool_setarch(pool, un.machine);
1031 char *calccachepath(Repo *repo, const char *repoext)
1033 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
1036 p = pool_tmpjoin(repo->pool, p, "_", repoext);
1037 p = pool_tmpjoin(repo->pool, p, ".solvx", 0);
1040 p = pool_tmpjoin(repo->pool, p, ".solv", 0);
1041 q = p + strlen(SOLVCACHE_PATH) + 1;
1051 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1054 unsigned char mycookie[32];
1055 unsigned char myextcookie[32];
1056 struct repoinfo *cinfo;
1059 cinfo = repo->appdata;
1060 if (!(fp = fopen(calccachepath(repo, repoext), "r")))
1062 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1067 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1072 if (cinfo && !repoext)
1074 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1085 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1086 if (strcmp(repoext, "DL") != 0)
1087 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1090 if (repo_add_solv_flags(repo, fp, flags))
1095 if (cinfo && !repoext)
1097 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1098 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1101 futimes(fileno(fp), 0); /* try to set modification time */
1107 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1112 struct repoinfo *cinfo;
1115 cinfo = repo->appdata;
1116 mkdir(SOLVCACHE_PATH, 0755);
1117 tmpl = sat_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
1125 if (!(fp = fdopen(fd, "w")))
1134 for (i = repo->start; i < repo->end; i++)
1135 if (repo->pool->solvables[i].repo != repo)
1141 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
1143 repodata_write(info, fp, repo_write_stdkeyfilter, 0);
1146 int oldnrepodata = repo->nrepodata;
1147 repo->nrepodata = 1; /* XXX: do this right */
1148 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
1149 repo->nrepodata = oldnrepodata;
1153 if (!repoext && cinfo)
1155 if (!cinfo->extcookie[0])
1157 /* create the ext cookie and append it */
1158 /* we just need some unique ID */
1160 if (!fstat(fileno(fp), &stb))
1164 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cinfo->extcookie);
1165 for (i = 0; i < 32; i++)
1166 cinfo->extcookie[i] ^= cookie[i];
1168 if (cinfo->extcookie[0] == 0)
1169 cinfo->extcookie[0] = 1;
1171 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1179 /* append our cookie describing the metadata state */
1180 if (fwrite(cookie, 32, 1, fp) != 1)
1195 /* switch to just saved repo to activate paging and save memory */
1196 FILE *fp = fopen(tmpl, "r");
1202 repo_empty(repo, 1);
1203 if (repo_add_solv_flags(repo, fp, SOLV_ADD_NO_STUBS))
1205 /* oops, no way to recover from here */
1206 fprintf(stderr, "internal error\n");
1212 /* make sure repodata contains complete repo */
1213 /* (this is how repodata_write saves it) */
1214 repodata_extend_block(info, repo->start, repo->end - repo->start);
1215 info->state = REPODATA_LOADING;
1216 /* no need for LOCALPOOL as pool already contains ids */
1217 repo_add_solv_flags(repo, fp, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1218 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1223 if (!rename(tmpl, calccachepath(repo, repoext)))
1232 Pool *sigpool = pool_create();
1234 Repo *repo = repo_create(sigpool, "rpmdbkeys");
1235 repo_add_rpmdb_pubkeys(repo, 0, 0);
1241 /* repomd helpers */
1243 static inline const char *
1244 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1246 Pool *pool = repo->pool;
1248 const char *filename;
1253 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1254 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1255 if (dataiterator_step(&di))
1257 dataiterator_setpos_parent(&di);
1258 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1259 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1261 dataiterator_free(&di);
1262 if (filename && !*chksumtypep)
1264 printf("no %s file checksum!\n", what);
1271 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1273 Pool *pool = repo->pool;
1275 Id chksumtype, handle;
1276 const unsigned char *chksum;
1277 const char *filename;
1279 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1280 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1281 if (!dataiterator_step(&di))
1283 dataiterator_free(&di);
1286 if (!strcmp(what, "prestodelta"))
1288 dataiterator_setpos_parent(&di);
1289 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1290 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, &chksumtype);
1291 if (!filename || !chksum)
1293 dataiterator_free(&di);
1296 handle = repodata_new_handle(data);
1297 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1298 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1300 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1301 if (!strcmp(what, "deltainfo"))
1303 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1304 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1306 if (!strcmp(what, "filelists"))
1308 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1309 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1311 dataiterator_free(&di);
1312 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1317 /* susetags helpers */
1319 static inline const char *
1320 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1322 Pool *pool = repo->pool;
1324 const char *filename;
1329 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
1330 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1331 if (dataiterator_step(&di))
1333 dataiterator_setpos_parent(&di);
1334 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
1337 dataiterator_free(&di);
1338 if (filename && !*chksumtypep)
1340 printf("no %s file checksum!\n", what);
1346 static Id susetags_langtags[] = {
1347 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
1348 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
1349 SOLVABLE_EULA, REPOKEY_TYPE_STR,
1350 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
1351 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
1352 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
1357 susetags_add_ext(Repo *repo, Repodata *data)
1359 Pool *pool = repo->pool;
1362 Id handle, filechksumtype;
1363 const unsigned char *filechksum;
1366 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
1367 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1368 while (dataiterator_step(&di))
1370 if (strncmp(di.kv.str, "packages.", 9) != 0)
1372 if (!strcmp(di.kv.str + 9, "gz"))
1374 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
1376 ext[0] = di.kv.str[9];
1377 ext[1] = di.kv.str[10];
1379 if (!strcmp(ext, "en"))
1381 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
1383 handle = repodata_new_handle(data);
1384 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
1386 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
1387 if (!strcmp(ext, "DU"))
1389 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
1390 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
1392 else if (!strcmp(ext, "FL"))
1394 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1395 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1399 for (i = 0; susetags_langtags[i]; i += 2)
1401 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
1402 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
1405 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1407 dataiterator_free(&di);
1412 iscompressed(const char *name)
1414 int l = strlen(name);
1415 return l > 3 && !strcmp(name + l - 3, ".gz") ? 1 : 0;
1422 load_stub(Pool *pool, Repodata *data, void *dp)
1424 const char *filename, *descrdir, *repomdtype;
1425 const unsigned char *filechksum;
1427 struct repoinfo *cinfo;
1432 cinfo = data->repo->appdata;
1434 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1438 ext[0] = filename[9];
1439 ext[1] = filename[10];
1442 printf("[%s:%s", data->repo->name, ext);
1444 if (usecachedrepo(data->repo, ext, cinfo->extcookie, 0))
1446 printf(" cached]\n"); fflush(stdout);
1450 printf(" fetching]\n"); fflush(stdout);
1452 defvendor = repo_lookup_id(data->repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1453 descrdir = repo_lookup_str(data->repo, SOLVID_META, SUSETAGS_DESCRDIR);
1455 descrdir = "suse/setup/descr";
1457 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1458 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1460 repo_add_susetags(data->repo, fp, defvendor, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1462 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
1466 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1469 if (!strcmp(repomdtype, "filelists"))
1471 else if (!strcmp(repomdtype, "deltainfo"))
1476 printf("[%s:%s", data->repo->name, ext);
1478 if (usecachedrepo(data->repo, ext, cinfo->extcookie, 0))
1480 printf(" cached]\n");fflush(stdout);
1483 printf(" fetching]\n"); fflush(stdout);
1484 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1486 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1487 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1489 if (!strcmp(ext, "FL"))
1490 repo_add_rpmmd(data->repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1491 else if (!strcmp(ext, "DL"))
1492 repo_add_deltainfoxml(data->repo, fp, REPO_USE_LOADING);
1494 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
1501 static unsigned char installedcookie[32];
1505 repo_add_debdb(Repo *repo, int flags)
1508 if ((fp = fopen("/var/lib/dpkg/status", "r")) == 0)
1510 perror("/var/lib/dpkg/status");
1513 repo_add_debpackages(repo, fp, flags);
1518 hexstr2bytes(unsigned char *buf, const char *str, int buflen)
1521 for (i = 0; i < buflen; i++)
1523 #define c2h(c) (((c)>='0' && (c)<='9') ? ((c)-'0') \
1524 : ((c)>='a' && (c)<='f') ? ((c)-('a'-10)) \
1525 : ((c)>='A' && (c)<='F') ? ((c)-('A'-10)) \
1536 buf[i] = (buf[i] << 4) | v;
1543 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1547 unsigned char *chksum;
1552 static char *basearch;
1564 basearch = strdup(un.machine);
1565 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
1568 binarydir = sat_dupjoin("binary-", basearch, "/");
1569 lbinarydir = strlen(binarydir);
1570 compl = strlen(comp);
1574 chksum = sat_malloc(32);
1576 while(fgets(buf, sizeof(buf), fp))
1581 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1583 if (!strncasecmp(buf, "MD5Sum:", 7))
1585 curchksumtype = REPOKEY_TYPE_MD5;
1588 if (!strncasecmp(buf, "SHA1:", 5))
1590 curchksumtype = REPOKEY_TYPE_SHA1;
1593 if (!strncasecmp(buf, "SHA256:", 7))
1595 curchksumtype = REPOKEY_TYPE_SHA256;
1607 while (*bp && *bp != ' ' && *bp != '\t')
1612 while (*bp == ' ' || *bp == '\t')
1614 while (*bp && *bp != ' ' && *bp != '\t')
1618 while (*bp == ' ' || *bp == '\t')
1621 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1624 if (strncmp(bp, binarydir, lbinarydir))
1627 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1629 if (filename && !strcmp(bp, "Packages"))
1631 if (chksumtype && sat_chksum_len(chksumtype) > sat_chksum_len(curchksumtype))
1633 if (!hexstr2bytes(chksum, ch, sat_chksum_len(curchksumtype)))
1636 filename = strdup(fn);
1637 chksumtype = curchksumtype;
1643 fn = sat_dupjoin("/", filename, 0);
1645 filename = sat_dupjoin("dists/", cinfo->name, fn);
1649 chksum = sat_free(chksum);
1651 *chksumtypep = chksumtype;
1657 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1660 struct repoinfo *cinfo;
1664 const char *filename;
1665 const unsigned char *filechksum;
1667 const char *descrdir;
1679 repo = repo_create(pool, "@System");
1681 printf("rpm database:");
1682 if (stat("/var/lib/rpm/Packages", &stb))
1683 memset(&stb, 0, sizeof(&stb));
1685 printf("dpgk database:");
1686 if (stat("/var/lib/dpkg/status", &stb))
1687 memset(&stb, 0, sizeof(&stb));
1689 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, installedcookie);
1690 if (usecachedrepo(repo, 0, installedcookie, 0))
1691 printf(" cached\n");
1698 printf(" reading\n");
1700 #ifdef PRODUCTS_PATH
1701 repo_add_products(repo, PRODUCTS_PATH, 0, REPO_NO_INTERNALIZE);
1704 if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
1706 Repo *ref = repo_create(pool, "@System.old");
1707 if (!repo_add_solv(ref, ofp))
1709 repo_add_rpmdb(repo, ref, 0, REPO_REUSE_REPODATA);
1716 repo_add_rpmdb(repo, 0, 0, REPO_REUSE_REPODATA);
1718 repo_add_debdb(repo, REPO_REUSE_REPODATA);
1720 writecachedrepo(repo, 0, 0, installedcookie);
1722 pool_set_installed(pool, repo);
1724 for (i = 0; i < nrepoinfos; i++)
1726 cinfo = repoinfos + i;
1727 if (!cinfo->enabled)
1730 repo = repo_create(pool, cinfo->alias);
1732 repo->appdata = cinfo;
1733 repo->priority = 99 - cinfo->priority;
1735 dorefresh = cinfo->autorefresh;
1736 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0), &stb) == 0)
1738 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1741 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1743 printf("repo '%s':", cinfo->alias);
1744 printf(" cached\n");
1748 switch (cinfo->type)
1751 printf("rpmmd repo '%s':", cinfo->alias);
1753 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1755 printf(" no repomd.xml file, skipped\n");
1760 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1761 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1763 printf(" cached\n");
1767 if (cinfo->repo_gpgcheck)
1769 sigfp = curlfopen(cinfo, "repodata/repomd.xml.asc", 0, 0, 0, 0);
1772 printf(" unsigned, skipped\n");
1777 sigpool = read_sigs();
1778 if (!checksig(sigpool, fp, sigfp))
1780 printf(" checksig failed, skipped\n");
1787 repo_add_repomdxml(repo, fp, 0);
1789 printf(" fetching\n");
1790 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1791 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1793 repo_add_rpmmd(repo, fp, 0, 0);
1797 break; /* hopeless */
1799 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1800 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1802 repo_add_updateinfoxml(repo, fp, 0);
1806 data = repo_add_repodata(repo, 0);
1807 if (!repomd_add_ext(repo, data, "deltainfo"))
1808 repomd_add_ext(repo, data, "prestodelta");
1809 repomd_add_ext(repo, data, "filelists");
1810 repodata_internalize(data);
1812 writecachedrepo(repo, 0, 0, cinfo->cookie);
1813 repodata_create_stubs(repo_last_repodata(repo));
1817 printf("susetags repo '%s':", cinfo->alias);
1821 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1823 printf(" no content file, skipped\n");
1828 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1829 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1831 printf(" cached\n");
1835 if (cinfo->repo_gpgcheck)
1837 sigfp = curlfopen(cinfo, "content.asc", 0, 0, 0, 0);
1840 printf(" unsigned, skipped\n");
1847 sigpool = read_sigs();
1848 if (!checksig(sigpool, fp, sigfp))
1850 printf(" checksig failed, skipped\n");
1858 repo_add_content(repo, fp, 0);
1860 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1861 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1863 descrdir = "suse/setup/descr";
1864 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1866 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1869 printf(" no packages file entry, skipped\n");
1872 printf(" fetching\n");
1873 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) == 0)
1874 break; /* hopeless */
1875 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE);
1877 /* add default language */
1878 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1880 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1883 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1885 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES);
1889 repo_internalize(repo);
1890 data = repo_add_repodata(repo, 0);
1891 susetags_add_ext(repo, data);
1892 repodata_internalize(data);
1894 writecachedrepo(repo, 0, 0, cinfo->cookie);
1895 repodata_create_stubs(repo_last_repodata(repo));
1900 printf("debian repo '%s':", cinfo->alias);
1902 filename = sat_dupjoin("dists/", cinfo->name, "/Release");
1903 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
1905 printf(" no Release file, skipped\n");
1908 free((char *)filename);
1911 sat_free((char *)filename);
1912 if (cinfo->repo_gpgcheck)
1914 filename = sat_dupjoin("dists/", cinfo->name, "/Release.gpg");
1915 sigfp = curlfopen(cinfo, filename, 0, 0, 0, 0);
1916 sat_free((char *)filename);
1919 printf(" unsigned, skipped\n");
1924 sigpool = read_sigs();
1925 if (!checksig(sigpool, fpr, sigfp))
1927 printf(" checksig failed, skipped\n");
1934 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
1935 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1937 printf(" cached\n");
1941 printf(" fetching\n");
1942 for (j = 0; j < cinfo->ncomponents; j++)
1944 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
1946 printf("[component %s not found]\n", cinfo->components[j]);
1949 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1951 repo_add_debpackages(repo, fp, 0);
1954 sat_free((char *)filechksum);
1955 sat_free((char *)filename);
1959 writecachedrepo(repo, 0, 0, cinfo->cookie);
1964 printf("unsupported repo '%s': skipped\n", cinfo->alias);
1976 str2archid(Pool *pool, char *arch)
1981 id = str2id(pool, arch, 0);
1982 if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH)
1984 if (pool->id2arch && (id > pool->lastarch || !pool->id2arch[id]))
1990 #define DEPGLOB_NAME 1
1991 #define DEPGLOB_DEP 2
1992 #define DEPGLOB_NAMEDEP 3
1995 depglob(Pool *pool, char *name, Queue *job, int what)
1998 Id id = str2id(pool, name, 0);
2003 FOR_PROVIDES(p, pp, id)
2005 Solvable *s = pool->solvables + p;
2007 if (s->name == id && (what & DEPGLOB_NAME) != 0)
2009 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
2015 if (what == DEPGLOB_NAMEDEP)
2016 printf("[using capability match for '%s']\n", name);
2017 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
2022 if (strpbrk(name, "[*?") == 0)
2025 if ((what & DEPGLOB_NAME) != 0)
2027 /* looks like a name glob. hard work. */
2028 for (p = 1; p < pool->nsolvables; p++)
2030 Solvable *s = pool->solvables + p;
2031 if (!s->repo || !pool_installable(pool, s))
2034 if (fnmatch(name, id2str(pool, id), 0) == 0)
2036 for (i = 0; i < job->count; i += 2)
2037 if (job->elements[i] == SOLVER_SOLVABLE_NAME && job->elements[i + 1] == id)
2039 if (i == job->count)
2040 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
2047 if ((what & DEPGLOB_DEP))
2049 /* looks like a dep glob. really hard work. */
2050 for (id = 1; id < pool->ss.nstrings; id++)
2052 if (!pool->whatprovides[id])
2054 if (fnmatch(name, id2str(pool, id), 0) == 0)
2056 if (!match && what == DEPGLOB_NAMEDEP)
2057 printf("[using capability match for '%s']\n", name);
2058 for (i = 0; i < job->count; i += 2)
2059 if (job->elements[i] == SOLVER_SOLVABLE_PROVIDES && job->elements[i + 1] == id)
2061 if (i == job->count)
2062 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
2073 limitrelation(Pool *pool, Queue *job, int flags, Id evr)
2077 for (i = j = 0; i < job->count; i += 2)
2079 Id select = job->elements[i] & SOLVER_SELECTMASK;
2080 if (select != SOLVER_SOLVABLE_NAME && select != SOLVER_SOLVABLE_PROVIDES)
2082 fprintf(stderr, "limitrelation only works on name/provides jobs\n");
2085 job->elements[i + 1] = rel2id(pool, job->elements[i + 1], evr, flags, 1);
2086 if (flags == REL_ARCH)
2087 job->elements[i] |= SOLVER_SETARCH;
2088 if (flags == REL_EQ && select == SOLVER_SOLVABLE_NAME && job->elements[i])
2091 const char *evrstr = id2str(pool, evr);
2092 if (!strchr(evrstr, '-'))
2093 job->elements[i] |= SOLVER_SETEV;
2096 job->elements[i] |= SOLVER_SETEVR;
2098 /* make sure we still have matches */
2099 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2103 job->elements[j] = job->elements[i];
2104 job->elements[j + 1] = job->elements[i + 1];
2108 queue_truncate(job, j);
2113 limitrelation_arch(Pool *pool, Queue *job, int flags, char *evr)
2117 if ((r = strrchr(evr, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2120 limitrelation(pool, job, REL_ARCH, archid);
2121 limitrelation(pool, job, flags, str2id(pool, evr, 1));
2125 limitrelation(pool, job, flags, str2id(pool, evr, 1));
2126 return job->count / 2;
2130 limitrepo(Pool *pool, Id repofilter, Queue *job)
2138 for (i = j = 0; i < job->count; i += 2)
2141 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2143 s = pool_id2solvable(pool, p);
2144 if (s->repo && s->repo->repoid == repofilter)
2149 /* here we assume that repo == vendor, so we also set SOLVER_SETVENDOR */
2152 job->elements[j] = SOLVER_SOLVABLE | (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO | SOLVER_NOAUTOSET;
2153 job->elements[j + 1] = mq.elements[0];
2157 job->elements[j] = SOLVER_SOLVABLE_ONE_OF | (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO;
2158 job->elements[j + 1] = pool_queuetowhatprovides(pool, &mq);
2163 queue_truncate(job, j);
2169 mkselect(Pool *pool, int mode, char *name, Queue *job)
2180 dataiterator_init(&di, pool, mode == SOLVER_ERASE ? pool->installed : 0, 0, SOLVABLE_FILELIST, name, SEARCH_STRING|SEARCH_FILES|SEARCH_COMPLETE_FILELIST);
2181 while (dataiterator_step(&di))
2183 Solvable *s = pool->solvables + di.solvid;
2184 if (!s->repo || !pool_installable(pool, s))
2186 queue_push(&q, di.solvid);
2187 dataiterator_skip_solvable(&di);
2189 dataiterator_free(&di);
2192 printf("[using file list match for '%s']\n", name);
2194 queue_push2(job, SOLVER_SOLVABLE_ONE_OF, pool_queuetowhatprovides(pool, &q));
2196 queue_push2(job, SOLVER_SOLVABLE | SOLVER_NOAUTOSET, q.elements[0]);
2198 return job->count / 2;
2201 if ((r = strpbrk(name, "<=>")) != 0)
2203 /* relation case, support:
2208 int nend = r - name;
2221 while (*r && *r == ' ' && *r == '\t')
2223 while (nend && (name[nend - 1] == ' ' || name[nend -1 ] == '\t'))
2227 fprintf(stderr, "bad relation\n");
2230 oldnend = name[nend];
2232 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2234 name[nend] = oldnend;
2235 limitrelation(pool, job, rflags, str2id(pool, r, 1));
2236 return job->count / 2;
2238 if ((r2 = strrchr(name, '.')) != 0 && r2[1] && (archid = str2archid(pool, r2 + 1)) != 0)
2241 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2243 name[nend] = oldnend;
2245 limitrelation(pool, job, REL_ARCH, archid);
2246 limitrelation(pool, job, rflags, str2id(pool, r, 1));
2247 return job->count / 2;
2251 name[nend] = oldnend;
2255 /* no relation case, support:
2259 * nameglob-version.arch
2260 * nameglob-version-release
2261 * nameglob-version-release.arch
2263 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2264 return job->count / 2;
2265 if ((r = strrchr(name, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2268 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2271 limitrelation(pool, job, REL_ARCH, archid);
2272 return job->count / 2;
2276 if ((r = strrchr(name, '-')) != 0)
2279 if (depglob(pool, name, job, DEPGLOB_NAME))
2281 /* have just the version */
2282 limitrelation_arch(pool, job, REL_EQ, r + 1);
2284 return job->count / 2;
2286 if ((r2 = strrchr(name, '-')) != 0)
2291 if (depglob(pool, name, job, DEPGLOB_NAME))
2293 /* have version-release */
2294 limitrelation_arch(pool, job, REL_EQ, r + 1);
2296 return job->count / 2;
2307 yesno(const char *str)
2309 char inbuf[128], *ip;
2316 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2321 while (*ip == ' ' || *ip == '\t')
2328 if (*ip == 'y' || *ip == 'n')
2329 return *ip == 'y' ? 1 : 0;
2343 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2345 struct fcstate *fcstate = cbdata;
2353 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
2356 s = pool_id2solvable(pool, p);
2357 if (pool->installed && s->repo == pool->installed)
2359 if (!s->repo->rpmdbid)
2361 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2364 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
2366 for (i = 0; i < fcstate->newpkgscnt; i++)
2367 if (fcstate->checkq->elements[i] == p)
2369 if (i == fcstate->newpkgscnt)
2371 fp = fcstate->newpkgsfps[i];
2375 return rpm_byfp(fp, solvable2str(pool, s), &fcstate->rpmdbstate);
2380 runrpm(const char *arg, const char *name, int dupfd3)
2385 if ((pid = fork()) == (pid_t)-1)
2392 if (dupfd3 != -1 && dupfd3 != 3)
2398 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2399 if (strcmp(arg, "-e") == 0)
2400 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2402 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2406 while (waitpid(pid, &status, 0) != pid)
2410 printf("rpm failed\n");
2420 rundpkg(const char *arg, const char *name, int dupfd3)
2425 if ((pid = fork()) == (pid_t)-1)
2432 if (dupfd3 != -1 && dupfd3 != 3)
2438 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2439 if (strcmp(arg, "--install") == 0)
2440 execlp("dpkg", "dpkg", "--install", "--force", "all", name, (char *)0);
2442 execlp("dpkg", "dpkg", "--remove", "--force", "all", name, (char *)0);
2446 while (waitpid(pid, &status, 0) != pid)
2450 printf("dpkg failed\n");
2458 nscallback(Pool *pool, void *data, Id name, Id evr)
2460 if (name == NAMESPACE_PRODUCTBUDDY)
2462 /* SUSE specific hack: each product has an associated rpm */
2463 Solvable *s = pool->solvables + evr;
2466 cap = str2id(pool, pool_tmpjoin(pool, "product(", id2str(pool, s->name) + 8, ")"), 0);
2469 cap = rel2id(pool, cap, s->evr, REL_EQ, 0);
2472 FOR_PROVIDES(p, pp, cap)
2474 Solvable *ps = pool->solvables + p;
2475 if (ps->repo == s->repo && ps->arch == s->arch)
2483 #ifdef SOFTLOCKS_PATH
2486 addsoftlocks(Pool *pool, Queue *job)
2490 char *bp, *ep, buf[4096];
2492 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2494 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2496 while (*bp == ' ' || *bp == '\t')
2498 if (!*bp || *bp == '#')
2500 for (ep = bp; *ep; ep++)
2501 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2504 type = SOLVER_SOLVABLE_NAME;
2505 if (!strncmp(bp, "provides:", 9) && bp[9])
2507 type = SOLVER_SOLVABLE_PROVIDES;
2510 id = str2id(pool, bp, 1);
2511 if (pool->installed)
2513 FOR_JOB_SELECT(p, pp, type, id)
2514 if (pool->solvables[p].repo == pool->installed)
2517 continue; /* ignore, as it is already installed */
2519 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2528 rewrite_repos(Pool *pool, Id *addedfileprovides)
2533 Queue fileprovidesq;
2535 int i, j, n, nprovidedids;
2536 struct repoinfo *cinfo;
2538 map_init(&providedids, pool->ss.nstrings);
2539 queue_init(&fileprovidesq);
2540 for (nprovidedids = 0; (id = addedfileprovides[nprovidedids]) != 0; nprovidedids++)
2541 MAPSET(&providedids, id);
2544 /* make sure this repo has just one main repodata */
2545 if (!repo->nrepodata)
2547 cinfo = repo->appdata;
2548 data = repo->repodata + 0;
2549 if (data->store.pagefd == -1)
2551 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2554 for (j = 0; j < fileprovidesq.count; j++)
2555 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2557 if (n == nprovidedids)
2558 continue; /* nothing new added */
2561 for (j = 0; addedfileprovides[j]; j++)
2562 repodata_add_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, addedfileprovides[j]);
2563 repodata_internalize(data);
2564 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2566 queue_free(&fileprovidesq);
2567 map_free(&providedids);
2571 #define MODE_INSTALL 1
2572 #define MODE_ERASE 2
2573 #define MODE_UPDATE 3
2574 #define MODE_DISTUPGRADE 4
2575 #define MODE_VERIFY 5
2576 #define MODE_PATCH 6
2578 #define MODE_REPOLIST 8
2579 #define MODE_SEARCH 9
2580 #define MODE_ERASECLEAN 10
2585 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2586 fprintf(stderr, "\n");
2587 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2588 fprintf(stderr, " versions from the repositories\n");
2589 fprintf(stderr, " erase: erase installed packages\n");
2590 fprintf(stderr, " info: display package information\n");
2591 fprintf(stderr, " install: install packages\n");
2592 fprintf(stderr, " list: list packages\n");
2593 fprintf(stderr, " repos: list enabled repositories\n");
2594 fprintf(stderr, " search: search name/summary/description\n");
2595 fprintf(stderr, " update: update installed packages\n");
2596 fprintf(stderr, " verify: check dependencies of installed packages\n");
2597 fprintf(stderr, "\n");
2602 main(int argc, char **argv)
2605 Repo *commandlinerepo = 0;
2606 Id *commandlinepkgs = 0;
2608 struct repoinfo *repoinfos;
2610 int mainmode = 0, mode = 0;
2615 char inbuf[128], *ip;
2618 Id *addedfileprovides = 0;
2625 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2627 mainmode = MODE_INSTALL;
2628 mode = SOLVER_INSTALL;
2630 else if (!strcmp(argv[0], "patch"))
2632 mainmode = MODE_PATCH;
2633 mode = SOLVER_INSTALL;
2635 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2637 mainmode = MODE_ERASE;
2638 mode = SOLVER_ERASE;
2640 else if (!strcmp(argv[0], "eraseclean") || !strcmp(argv[0], "rmclean"))
2642 mainmode = MODE_ERASECLEAN;
2643 mode = SOLVER_ERASE;
2645 else if (!strcmp(argv[0], "list"))
2647 mainmode = MODE_LIST;
2650 else if (!strcmp(argv[0], "info"))
2652 mainmode = MODE_INFO;
2655 else if (!strcmp(argv[0], "search"))
2657 mainmode = MODE_SEARCH;
2660 else if (!strcmp(argv[0], "verify"))
2662 mainmode = MODE_VERIFY;
2663 mode = SOLVER_VERIFY;
2665 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2667 mainmode = MODE_UPDATE;
2668 mode = SOLVER_UPDATE;
2670 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2672 mainmode = MODE_DISTUPGRADE;
2673 mode = SOLVER_UPDATE;
2675 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2677 mainmode = MODE_REPOLIST;
2683 pool = pool_create();
2687 const char *langs[] = {"de_DE", "de", "en"};
2688 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2693 pool->obsoleteusescolors = 1;
2695 pool_setloadcallback(pool, load_stub, 0);
2696 pool->nscallback = nscallback;
2697 // pool_setdebuglevel(pool, 2);
2699 repoinfos = read_repoinfos(pool, REPOINFO_PATH, &nrepoinfos);
2701 if (mainmode == MODE_REPOLIST)
2704 for (i = 0; i < nrepoinfos; i++)
2706 struct repoinfo *cinfo = repoinfos + i;
2707 if (!cinfo->enabled)
2709 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2714 read_repos(pool, repoinfos, nrepoinfos);
2716 if (argc > 2 && !strcmp(argv[1], "-r"))
2718 const char *rname = argv[2], *rp;
2719 for (rp = rname; *rp; rp++)
2720 if (*rp <= '0' || *rp >= '9')
2724 /* repo specified by number */
2725 int rnum = atoi(rname);
2726 for (i = 0; i < nrepoinfos; i++)
2728 struct repoinfo *cinfo = repoinfos + i;
2729 if (!cinfo->enabled)
2732 repofilter = cinfo->repo->repoid;
2737 /* repo specified by alias */
2741 if (!strcasecmp(rname, repo->name))
2742 repofilter = repo->repoid;
2747 fprintf(stderr, "%s: no such repo\n", rname);
2753 if (mainmode == MODE_SEARCH)
2759 map_init(&m, pool->nsolvables);
2760 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2761 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2762 dataiterator_set_search(&di, 0, 0);
2763 while (dataiterator_step(&di))
2764 MAPSET(&m, di.solvid);
2765 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2766 dataiterator_set_search(&di, 0, 0);
2767 while (dataiterator_step(&di))
2768 MAPSET(&m, di.solvid);
2769 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2770 dataiterator_set_search(&di, 0, 0);
2771 while (dataiterator_step(&di))
2772 MAPSET(&m, di.solvid);
2773 dataiterator_free(&di);
2775 for (p = 1; p < pool->nsolvables; p++)
2777 Solvable *s = pool_id2solvable(pool, p);
2780 printf(" - %s: %s\n", solvable2str(pool, s), solvable_lookup_str(s, SOLVABLE_SUMMARY));
2787 if (mainmode == MODE_LIST || mainmode == MODE_INSTALL)
2789 for (i = 1; i < argc; i++)
2792 l = strlen(argv[i]);
2794 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2797 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2800 if (access(argv[i], R_OK))
2805 if (!commandlinepkgs)
2806 commandlinepkgs = sat_calloc(argc, sizeof(Id));
2807 if (!commandlinerepo)
2808 commandlinerepo = repo_create(pool, "@commandline");
2810 repo_add_rpms(commandlinerepo, (const char **)argv + i, 1, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2812 repo_add_debs(commandlinerepo, (const char **)argv + i, 1, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2814 commandlinepkgs[i] = commandlinerepo->end - 1;
2816 if (commandlinerepo)
2817 repo_internalize(commandlinerepo);
2820 // FOR_REPOS(i, repo)
2821 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2822 addedfileprovides = 0;
2823 pool_addfileprovides_ids(pool, 0, &addedfileprovides);
2824 if (addedfileprovides && *addedfileprovides)
2825 rewrite_repos(pool, addedfileprovides);
2826 sat_free(addedfileprovides);
2827 pool_createwhatprovides(pool);
2830 for (i = 1; i < argc; i++)
2835 if (commandlinepkgs && commandlinepkgs[i])
2837 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2841 if (!mkselect(pool, mode, argv[i], &job2))
2843 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2846 if (repofilter && !limitrepo(pool, repofilter, &job2))
2848 fprintf(stderr, "nothing in repo matches '%s'\n", argv[i]);
2851 for (j = 0; j < job2.count; j++)
2852 queue_push(&job, job2.elements[j]);
2856 if (!job.count && mainmode != MODE_UPDATE && mainmode != MODE_DISTUPGRADE && mainmode != MODE_VERIFY && mainmode != MODE_PATCH)
2858 printf("no package matched\n");
2865 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
2867 /* list mode, no solver needed */
2868 for (i = 0; i < job.count; i += 2)
2870 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
2872 Solvable *s = pool_id2solvable(pool, p);
2873 if (mainmode == MODE_INFO)
2876 printf("Name: %s\n", solvable2str(pool, s));
2877 printf("Repo: %s\n", s->repo->name);
2878 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
2879 str = solvable_lookup_str(s, SOLVABLE_URL);
2881 printf("Url: %s\n", str);
2882 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
2884 printf("License: %s\n", str);
2885 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
2891 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
2893 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
2895 printf(" - %s [%s]\n", solvable2str(pool, s), s->repo->name);
2897 printf(" %s\n", sum);
2903 free_repoinfos(repoinfos, nrepoinfos);
2904 sat_free(commandlinepkgs);
2906 yum_substitute(pool, 0);
2911 if (mainmode == MODE_PATCH)
2917 map_init(&installedmap, pool->nsolvables);
2918 if (pool->installed)
2919 FOR_REPO_SOLVABLES(pool->installed, p, s)
2920 MAPSET(&installedmap, p);
2922 /* install all patches */
2923 for (p = 1; p < pool->nsolvables; p++)
2929 s = pool->solvables + p;
2930 if (strncmp(id2str(pool, s->name), "patch:", 6) != 0)
2932 FOR_PROVIDES(p2, pp, s->name)
2934 Solvable *s2 = pool->solvables + p2;
2935 if (s2->name != s->name)
2937 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2938 if (r < 0 || (r == 0 && p > p2))
2943 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2944 if (type && !strcmp(type, "optional"))
2946 r = solvable_trivial_installable_map(s, &installedmap, 0);
2949 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2956 queue_push2(&job, SOLVER_SOLVABLE, p);
2958 map_free(&installedmap);
2962 for (i = 0; i < job.count; i += 2)
2964 if (mode == SOLVER_UPDATE)
2966 /* make update of not installed packages an install */
2967 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
2968 if (pool->installed && pool->solvables[p].repo == pool->installed)
2972 job.elements[i] |= SOLVER_INSTALL;
2976 job.elements[i] |= mode;
2977 if (mainmode == MODE_ERASECLEAN)
2978 job.elements[i] |= SOLVER_CLEANDEPS;
2981 if (mainmode == MODE_DISTUPGRADE && allpkgs && repofilter)
2982 queue_push2(&job, SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_REPO, repofilter);
2984 // multiversion test
2985 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae", 1));
2986 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-base", 1));
2987 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-extra", 1));
2989 #ifdef SOFTLOCKS_PATH
2990 addsoftlocks(pool, &job);
2998 Id problem, solution;
3001 solv = solver_create(pool);
3002 solv->ignorealreadyrecommended = 1;
3003 solv->updatesystem = allpkgs && !repofilter && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE);
3004 solv->dosplitprovides = solv->updatesystem;
3005 solv->fixsystem = allpkgs && !repofilter && mainmode == MODE_VERIFY;
3006 if (mainmode == MODE_DISTUPGRADE && allpkgs && !repofilter)
3008 solv->distupgrade = 1;
3009 solv->allowdowngrade = 1;
3010 solv->allowarchchange = 1;
3011 solv->allowvendorchange = 1;
3013 if (mainmode == MODE_ERASE || mainmode == MODE_ERASECLEAN)
3014 solv->allowuninstall = 1; /* don't nag */
3016 solver_solve(solv, &job);
3017 if (!solv->problems.count)
3019 pcnt = solver_problem_count(solv);
3020 printf("Found %d problems:\n", pcnt);
3021 for (problem = 1; problem <= pcnt; problem++)
3024 printf("Problem %d:\n", problem);
3025 solver_printprobleminfo(solv, problem);
3027 scnt = solver_solution_count(solv, problem);
3028 for (solution = 1; solution <= scnt; solution++)
3030 printf("Solution %d:\n", solution);
3031 solver_printsolution(solv, problem, solution);
3036 printf("Please choose a solution: ");
3039 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
3044 while (*ip == ' ' || *ip == '\t')
3046 if (*ip >= '0' && *ip <= '9')
3049 if (take >= 1 && take <= scnt)
3065 solver_take_solution(solv, problem, take, &job);
3071 trans = &solv->trans;
3072 if (!trans->steps.count)
3074 printf("Nothing to do.\n");
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);