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"
78 # define REPOINFO_PATH "/etc/yum.repos.d"
80 # define REPOINFO_PATH "/etc/zypp/repos.d"
81 # define PRODUCTS_PATH "/etc/products.d"
82 # define SOFTLOCKS_PATH "/var/lib/zypp/SoftLocks"
85 #define SOLVCACHE_PATH "/var/cache/solv"
87 #define METADATA_EXPIRE (60 * 90)
109 unsigned char cookie[32];
110 unsigned char extcookie[32];
115 yum_substitute(Pool *pool, char *line)
118 static char *releaseevr;
119 static char *basearch;
123 sat_free(releaseevr);
130 while ((p2 = strchr(p, '$')) != 0)
132 if (!strncmp(p2, "$releasever", 11))
139 rpm_installedrpmdbids(0, "Providename", "redhat-release", &q);
142 void *handle, *state = 0;
144 handle = rpm_byrpmdbid(q.elements[0], 0, &state);
145 releaseevr = rpm_query(handle, SOLVABLE_EVR);
146 rpm_byrpmdbid(0, 0, &state);
147 if ((p = strchr(releaseevr, '-')) != 0)
152 releaseevr = strdup("?");
155 p = pool_tmpjoin(pool, line, releaseevr, p2 + 11);
156 p2 = p + (p2 - line);
158 p = p2 + strlen(releaseevr);
161 if (!strncmp(p2, "$basearch", 9))
171 basearch = strdup(un.machine);
172 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
176 p = pool_tmpjoin(pool, line, basearch, p2 + 9);
177 p2 = p + (p2 - line);
179 p = p2 + strlen(basearch);
188 #define TYPE_UNKNOWN 0
189 #define TYPE_SUSETAGS 1
191 #define TYPE_PLAINDIR 3
192 #define TYPE_DEBIAN 4
195 read_repoinfos_sort(const void *ap, const void *bp)
197 const struct repoinfo *a = ap;
198 const struct repoinfo *b = bp;
199 return strcmp(a->alias, b->alias);
205 read_repoinfos(Pool *pool, const char *reposdir, int *nrepoinfosp)
208 char buf2[4096], *kp, *vp, *kpe;
213 struct repoinfo *repoinfos = 0, *cinfo;
216 rdlen = strlen(reposdir);
217 dir = opendir(reposdir);
223 while ((ent = readdir(dir)) != 0)
225 if (ent->d_name[0] == '.')
227 l = strlen(ent->d_name);
228 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
230 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
231 if ((fp = fopen(buf, "r")) == 0)
237 while(fgets(buf2, sizeof(buf2), fp))
242 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
245 while (*kp == ' ' || *kp == '\t')
247 if (!*kp || *kp == '#')
251 kp = yum_substitute(pool, kp);
255 vp = strrchr(kp, ']');
259 repoinfos = sat_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
260 cinfo = repoinfos + nrepoinfos++;
261 memset(cinfo, 0, sizeof(*cinfo));
262 cinfo->alias = strdup(kp + 1);
263 cinfo->type = TYPE_RPMMD;
264 cinfo->autorefresh = 1;
265 cinfo->priority = 99;
267 cinfo->repo_gpgcheck = 1;
269 cinfo->metadata_expire = METADATA_EXPIRE;
274 vp = strchr(kp, '=');
277 for (kpe = vp - 1; kpe >= kp; kpe--)
278 if (*kpe != ' ' && *kpe != '\t')
283 while (*vp == ' ' || *vp == '\t')
286 if (!strcmp(kp, "name"))
287 cinfo->name = strdup(vp);
288 else if (!strcmp(kp, "enabled"))
289 cinfo->enabled = *vp == '0' ? 0 : 1;
290 else if (!strcmp(kp, "autorefresh"))
291 cinfo->autorefresh = *vp == '0' ? 0 : 1;
292 else if (!strcmp(kp, "gpgcheck"))
293 cinfo->pkgs_gpgcheck = *vp == '0' ? 0 : 1;
294 else if (!strcmp(kp, "repo_gpgcheck"))
295 cinfo->repo_gpgcheck = *vp == '0' ? 0 : 1;
296 else if (!strcmp(kp, "baseurl"))
297 cinfo->baseurl = strdup(vp);
298 else if (!strcmp(kp, "mirrorlist"))
300 if (strstr(vp, "metalink"))
301 cinfo->metalink = strdup(vp);
303 cinfo->mirrorlist = strdup(vp);
305 else if (!strcmp(kp, "path"))
307 if (vp && strcmp(vp, "/") != 0)
308 cinfo->path = strdup(vp);
310 else if (!strcmp(kp, "type"))
312 if (!strcmp(vp, "yast2"))
313 cinfo->type = TYPE_SUSETAGS;
314 else if (!strcmp(vp, "rpm-md"))
315 cinfo->type = TYPE_RPMMD;
316 else if (!strcmp(vp, "plaindir"))
317 cinfo->type = TYPE_PLAINDIR;
319 cinfo->type = TYPE_UNKNOWN;
321 else if (!strcmp(kp, "priority"))
322 cinfo->priority = atoi(vp);
323 else if (!strcmp(kp, "keeppackages"))
324 cinfo->keeppackages = *vp == '0' ? 0 : 1;
330 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
331 *nrepoinfosp = nrepoinfos;
338 read_repoinfos(Pool *pool, const char *reposdir, int *nrepoinfosp)
344 char *kp, *url, *distro;
345 struct repoinfo *repoinfos = 0, *cinfo;
350 fp = fopen("/etc/apt/sources.list", "r");
357 dir = opendir("/etc/apt/sources.list.d");
361 if ((ent = readdir(dir)) == 0)
366 if (ent->d_name[0] == '.')
368 l = strlen(ent->d_name);
369 if (l < 5 || strcmp(ent->d_name + l - 5, ".list") != 0)
371 snprintf(buf, sizeof(buf), "%s/%s", "/etc/apt/sources.list.d", ent->d_name);
372 if (!(fp = fopen(buf, "r")))
375 while(fgets(buf2, sizeof(buf2), fp))
380 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
383 while (*kp == ' ' || *kp == '\t')
385 if (!*kp || *kp == '#')
387 if (strncmp(kp, "deb", 3) != 0)
390 if (*kp != ' ' && *kp != '\t')
392 while (*kp == ' ' || *kp == '\t')
397 while (*kp && *kp != ' ' && *kp != '\t')
401 while (*kp == ' ' || *kp == '\t')
406 while (*kp && *kp != ' ' && *kp != '\t')
410 while (*kp == ' ' || *kp == '\t')
414 repoinfos = sat_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
415 cinfo = repoinfos + nrepoinfos++;
416 memset(cinfo, 0, sizeof(*cinfo));
417 cinfo->baseurl = strdup(url);
418 cinfo->alias = sat_dupjoin(url, "/", distro);
419 cinfo->name = strdup(distro);
420 cinfo->type = TYPE_DEBIAN;
422 cinfo->autorefresh = 1;
423 cinfo->repo_gpgcheck = 1;
424 cinfo->metadata_expire = METADATA_EXPIRE;
428 while (*kp == ' ' || *kp == '\t')
433 while (*kp && *kp != ' ' && *kp != '\t')
437 cinfo->components = sat_extend(cinfo->components, cinfo->ncomponents, 1, sizeof(*cinfo->components), 15);
438 cinfo->components[cinfo->ncomponents++] = strdup(compo);
444 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
445 *nrepoinfosp = nrepoinfos;
452 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
455 for (i = 0; i < nrepoinfos; i++)
457 struct repoinfo *cinfo = repoinfos + i;
458 sat_free(cinfo->name);
459 sat_free(cinfo->alias);
460 sat_free(cinfo->path);
461 sat_free(cinfo->metalink);
462 sat_free(cinfo->mirrorlist);
463 sat_free(cinfo->baseurl);
464 for (j = 0; j < cinfo->ncomponents; j++)
465 sat_free(cinfo->components[j]);
466 sat_free(cinfo->components);
477 strcpy(tmpl, "/var/tmp/solvXXXXXX");
489 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
496 h = sat_chksum_create(chksumtype);
499 printf("%s: unknown checksum type\n", file);
502 while ((l = read(fd, buf, sizeof(buf))) > 0)
503 sat_chksum_add(h, buf, l);
504 lseek(fd, 0, SEEK_SET);
506 sum = sat_chksum_get(h, &l);
507 if (memcmp(sum, chksum, l))
509 printf("%s: checksum mismatch\n", file);
510 sat_chksum_free(h, 0);
513 sat_chksum_free(h, 0);
518 findfastest(char **urls, int nurls)
525 struct addrinfo hints, *result;;
527 fds = sat_calloc(nurls, sizeof(*fds));
528 socks = sat_calloc(nurls, sizeof(*socks));
529 for (i = 0; i < nurls; i++)
532 p = strchr(urls[i], '/');
545 if ((p2 = strchr(p, '@')) != 0)
548 if (!strncmp("https:", urls[i], 6))
550 else if (!strncmp("ftp:", urls[i], 4))
552 if ((p2 = strrchr(p, ':')) != 0)
561 sprintf(portstr, "%d", port);
562 memset(&hints, 0, sizeof(struct addrinfo));
563 hints.ai_family = AF_UNSPEC;
564 hints.ai_socktype = SOCK_STREAM;
565 hints.ai_flags = AI_NUMERICSERV;
567 if (!getaddrinfo(p, portstr, &hints, &result))
569 socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
572 fcntl(socks[i], F_SETFL, O_NONBLOCK);
573 if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1)
575 if (errno != EINPROGRESS)
582 freeaddrinfo(result);
589 for (i = j = 0; i < nurls; i++)
593 fds[j].fd = socks[i];
594 fds[j].events = POLLOUT;
602 if (poll(fds, j, 10000) <= 0)
604 i = -1; /* something is wrong */
607 for (i = 0; i < j; i++)
608 if ((fds[i].revents & POLLOUT) != 0)
611 socklen_t soel = sizeof(int);
612 if (getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, &soe, &soel) == -1 || soe != 0)
614 /* connect failed, kill socket */
615 for (j = 0; j < nurls; j++)
616 if (socks[j] == fds[i].fd)
629 i = -1; /* something is wrong, no bit was set */
632 /* now i contains the fastest fd index */
635 for (j = 0; j < nurls; j++)
636 if (socks[j] == fds[i].fd)
640 char *url0 = urls[0];
645 for (i = j = 0; i < nurls; i++)
653 findmetalinkurl(FILE *fp, unsigned char *chksump, Id *chksumtypep)
655 char buf[4096], *bp, *ep;
662 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
664 while (*bp == ' ' || *bp == '\t')
666 if (chksumtypep && !*chksumtypep && !strncmp(bp, "<hash type=\"sha256\">", 20))
671 memset(chksump, 0, 32);
672 for (i = 0; i < 64; i++)
675 if (c >= '0' && c <= '9')
676 chksump[i / 2] = chksump[i / 2] * 16 + (c - '0');
677 else if (c >= 'a' && c <= 'f')
678 chksump[i / 2] = chksump[i / 2] * 16 + (c - ('a' - 10));
679 else if (c >= 'A' && c <= 'F')
680 chksump[i / 2] = chksump[i / 2] * 16 + (c - ('A' - 10));
685 *chksumtypep = REPOKEY_TYPE_SHA256;
688 if (strncmp(bp, "<url", 4))
690 bp = strchr(bp, '>');
694 ep = strstr(bp, "repodata/repomd.xml</url>");
698 if (strncmp(bp, "http", 4))
700 urls = sat_extend(urls, nurls, 1, sizeof(*urls), 15);
701 urls[nurls++] = strdup(bp);
706 findfastest(urls, nurls > 5 ? 5 : nurls);
709 for (i = 0; i < nurls; i++)
712 ep = strchr(bp, '/');
713 if ((ep = strchr(ep + 2, '/')) != 0)
716 printf("[using mirror %s]\n", bp);
725 findmirrorlisturl(FILE *fp)
727 char buf[4096], *bp, *ep;
732 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
734 while (*bp == ' ' || *bp == '\t')
736 if (!*bp || *bp == '#')
739 while (l > 0 && (bp[l - 1] == ' ' || bp[l - 1] == '\t' || bp[l - 1] == '\n'))
741 urls = sat_extend(urls, nurls, 1, sizeof(*urls), 15);
742 urls[nurls++] = strdup(bp);
747 findfastest(urls, nurls > 5 ? 5 : nurls);
750 for (i = 0; i < nurls; i++)
753 ep = strchr(bp, '/');
754 if ((ep = strchr(ep + 2, '/')) != 0)
757 printf("[using mirror %s]\n", bp);
766 cookie_gzread(void *cookie, char *buf, size_t nbytes)
768 return gzread((gzFile *)cookie, buf, nbytes);
772 cookie_gzclose(void *cookie)
774 return gzclose((gzFile *)cookie);
778 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int *badchecksump)
784 const char *baseurl = cinfo->baseurl;
788 if (!cinfo->metalink && !cinfo->mirrorlist)
790 if (file != cinfo->metalink && file != cinfo->mirrorlist)
792 FILE *fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
793 unsigned char mlchksum[32];
798 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
800 cinfo->baseurl = findmirrorlisturl(fp);
805 if (strchr(cinfo->baseurl, '$'))
807 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
808 free(cinfo->baseurl);
809 cinfo->baseurl = strdup(b);
812 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
814 chksumtype = mlchksumtype;
817 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, badchecksump);
819 snprintf(url, sizeof(url), "%s", file);
824 if (l && baseurl[l - 1] == '/')
825 snprintf(url, sizeof(url), "%s%s", baseurl, file);
827 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
830 // printf("url: %s\n", url);
831 if ((pid = fork()) == (pid_t)-1)
843 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
848 while (waitpid(pid, &status, 0) != pid)
850 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
856 lseek(fd, 0, SEEK_SET);
859 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
865 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
875 cookie_io_functions_t cio;
878 sprintf(tmpl, "/dev/fd/%d", fd);
879 gzf = gzopen(tmpl, "r");
883 fprintf(stderr, "could not open /dev/fd/%d, /proc not mounted?\n", fd);
886 memset(&cio, 0, sizeof(cio));
887 cio.read = cookie_gzread;
888 cio.close = cookie_gzclose;
889 return fopencookie(gzf, "r", cio);
891 fcntl(fd, F_SETFD, FD_CLOEXEC);
892 return fdopen(fd, "r");
898 cleanupgpg(char *gpgdir)
901 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
903 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
905 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
907 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
909 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
915 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
924 off_t posfp, possigfp;
927 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
930 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
931 if (!(kfp = fopen(keysfile, "w")) )
937 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
941 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
942 if (!pubkey || !*pubkey)
944 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
946 if (fputc('\n', kfp) == EOF) /* Just in case... */
950 if (fclose(kfp) || !nkeys)
955 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
958 fprintf(stderr, "key import error\n");
963 posfp = lseek(fileno(fp), 0, SEEK_CUR);
964 lseek(fileno(fp), 0, SEEK_SET);
965 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
966 lseek(fileno(sigfp), 0, SEEK_SET);
967 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
968 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
969 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
971 lseek(fileno(sigfp), possigfp, SEEK_SET);
972 lseek(fileno(fp), posfp, SEEK_SET);
973 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
974 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
976 return r == 0 ? 1 : 0;
982 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
987 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));
988 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
989 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
991 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
992 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
993 return r == 0 ? 1 : 0;
998 #define CHKSUM_IDENT "1.1"
1001 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
1004 void *h = sat_chksum_create(chktype);
1007 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1008 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
1009 sat_chksum_add(h, buf, l);
1011 sat_chksum_free(h, out);
1015 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *out)
1017 void *h = sat_chksum_create(chktype);
1018 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1019 sat_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
1020 sat_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
1021 sat_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
1022 sat_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
1023 sat_chksum_free(h, out);
1035 pool_setarch(pool, un.machine);
1038 char *calccachepath(Repo *repo, const char *repoext)
1040 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
1043 p = pool_tmpjoin(repo->pool, p, "_", repoext);
1044 p = pool_tmpjoin(repo->pool, p, ".solvx", 0);
1047 p = pool_tmpjoin(repo->pool, p, ".solv", 0);
1048 q = p + strlen(SOLVCACHE_PATH) + 1;
1058 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1061 unsigned char mycookie[32];
1062 unsigned char myextcookie[32];
1063 struct repoinfo *cinfo;
1066 cinfo = repo->appdata;
1067 if (!(fp = fopen(calccachepath(repo, repoext), "r")))
1069 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1074 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1079 if (cinfo && !repoext)
1081 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1092 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1093 if (strcmp(repoext, "DL") != 0)
1094 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1097 if (repo_add_solv_flags(repo, fp, flags))
1102 if (cinfo && !repoext)
1104 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1105 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1108 futimes(fileno(fp), 0); /* try to set modification time */
1114 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1119 struct repoinfo *cinfo;
1122 cinfo = repo->appdata;
1123 mkdir(SOLVCACHE_PATH, 0755);
1124 tmpl = sat_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
1132 if (!(fp = fdopen(fd, "w")))
1141 for (i = repo->start; i < repo->end; i++)
1142 if (repo->pool->solvables[i].repo != repo)
1148 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
1150 repodata_write(info, fp, repo_write_stdkeyfilter, 0);
1153 int oldnrepodata = repo->nrepodata;
1154 repo->nrepodata = 1; /* XXX: do this right */
1155 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
1156 repo->nrepodata = oldnrepodata;
1160 if (!repoext && cinfo)
1162 if (!cinfo->extcookie[0])
1164 /* create the ext cookie and append it */
1165 /* we just need some unique ID */
1167 if (!fstat(fileno(fp), &stb))
1171 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cinfo->extcookie);
1172 for (i = 0; i < 32; i++)
1173 cinfo->extcookie[i] ^= cookie[i];
1175 if (cinfo->extcookie[0] == 0)
1176 cinfo->extcookie[0] = 1;
1178 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1186 /* append our cookie describing the metadata state */
1187 if (fwrite(cookie, 32, 1, fp) != 1)
1202 /* switch to just saved repo to activate paging and save memory */
1203 FILE *fp = fopen(tmpl, "r");
1209 repo_empty(repo, 1);
1210 if (repo_add_solv_flags(repo, fp, SOLV_ADD_NO_STUBS))
1212 /* oops, no way to recover from here */
1213 fprintf(stderr, "internal error\n");
1219 /* make sure repodata contains complete repo */
1220 /* (this is how repodata_write saves it) */
1221 repodata_extend_block(info, repo->start, repo->end - repo->start);
1222 info->state = REPODATA_LOADING;
1223 /* no need for LOCALPOOL as pool already contains ids */
1224 repo_add_solv_flags(repo, fp, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1225 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1230 if (!rename(tmpl, calccachepath(repo, repoext)))
1239 Pool *sigpool = pool_create();
1241 Repo *repo = repo_create(sigpool, "rpmdbkeys");
1242 repo_add_rpmdb_pubkeys(repo, 0, 0);
1248 /* repomd helpers */
1250 static inline const char *
1251 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1253 Pool *pool = repo->pool;
1255 const char *filename;
1260 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1261 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1262 if (dataiterator_step(&di))
1264 dataiterator_setpos_parent(&di);
1265 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1266 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1268 dataiterator_free(&di);
1269 if (filename && !*chksumtypep)
1271 printf("no %s file checksum!\n", what);
1278 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1280 Pool *pool = repo->pool;
1282 Id chksumtype, handle;
1283 const unsigned char *chksum;
1284 const char *filename;
1286 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1287 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1288 if (!dataiterator_step(&di))
1290 dataiterator_free(&di);
1293 if (!strcmp(what, "prestodelta"))
1295 dataiterator_setpos_parent(&di);
1296 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1297 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, &chksumtype);
1298 if (!filename || !chksum)
1300 dataiterator_free(&di);
1303 handle = repodata_new_handle(data);
1304 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1305 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1307 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1308 if (!strcmp(what, "deltainfo"))
1310 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1311 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1313 if (!strcmp(what, "filelists"))
1315 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1316 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1318 dataiterator_free(&di);
1319 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1324 /* susetags helpers */
1326 static inline const char *
1327 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1329 Pool *pool = repo->pool;
1331 const char *filename;
1336 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
1337 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1338 if (dataiterator_step(&di))
1340 dataiterator_setpos_parent(&di);
1341 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
1344 dataiterator_free(&di);
1345 if (filename && !*chksumtypep)
1347 printf("no %s file checksum!\n", what);
1353 static Id susetags_langtags[] = {
1354 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
1355 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
1356 SOLVABLE_EULA, REPOKEY_TYPE_STR,
1357 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
1358 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
1359 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
1364 susetags_add_ext(Repo *repo, Repodata *data)
1366 Pool *pool = repo->pool;
1369 Id handle, filechksumtype;
1370 const unsigned char *filechksum;
1373 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
1374 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1375 while (dataiterator_step(&di))
1377 if (strncmp(di.kv.str, "packages.", 9) != 0)
1379 if (!strcmp(di.kv.str + 9, "gz"))
1381 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
1383 ext[0] = di.kv.str[9];
1384 ext[1] = di.kv.str[10];
1386 if (!strcmp(ext, "en"))
1388 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
1390 handle = repodata_new_handle(data);
1391 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
1393 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
1394 if (!strcmp(ext, "DU"))
1396 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
1397 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
1399 else if (!strcmp(ext, "FL"))
1401 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1402 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1406 for (i = 0; susetags_langtags[i]; i += 2)
1408 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
1409 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
1412 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1414 dataiterator_free(&di);
1419 iscompressed(const char *name)
1421 int l = strlen(name);
1422 return l > 3 && !strcmp(name + l - 3, ".gz") ? 1 : 0;
1429 load_stub(Pool *pool, Repodata *data, void *dp)
1431 const char *filename, *descrdir, *repomdtype;
1432 const unsigned char *filechksum;
1434 struct repoinfo *cinfo;
1439 cinfo = data->repo->appdata;
1441 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1445 ext[0] = filename[9];
1446 ext[1] = filename[10];
1449 printf("[%s:%s", data->repo->name, ext);
1451 if (usecachedrepo(data->repo, ext, cinfo->extcookie, 0))
1453 printf(" cached]\n"); fflush(stdout);
1457 printf(" fetching]\n"); fflush(stdout);
1459 defvendor = repo_lookup_id(data->repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1460 descrdir = repo_lookup_str(data->repo, SOLVID_META, SUSETAGS_DESCRDIR);
1462 descrdir = "suse/setup/descr";
1464 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1465 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1467 repo_add_susetags(data->repo, fp, defvendor, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1469 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
1473 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1476 if (!strcmp(repomdtype, "filelists"))
1478 else if (!strcmp(repomdtype, "deltainfo"))
1483 printf("[%s:%s", data->repo->name, ext);
1485 if (usecachedrepo(data->repo, ext, cinfo->extcookie, 0))
1487 printf(" cached]\n");fflush(stdout);
1490 printf(" fetching]\n"); fflush(stdout);
1491 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1493 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1494 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1496 if (!strcmp(ext, "FL"))
1497 repo_add_rpmmd(data->repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1498 else if (!strcmp(ext, "DL"))
1499 repo_add_deltainfoxml(data->repo, fp, REPO_USE_LOADING);
1501 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
1508 static unsigned char installedcookie[32];
1512 repo_add_debdb(Repo *repo, int flags)
1515 if ((fp = fopen("/var/lib/dpkg/status", "r")) == 0)
1517 perror("/var/lib/dpkg/status");
1520 repo_add_debpackages(repo, fp, flags);
1525 hexstr2bytes(unsigned char *buf, const char *str, int buflen)
1528 for (i = 0; i < buflen; i++)
1530 #define c2h(c) (((c)>='0' && (c)<='9') ? ((c)-'0') \
1531 : ((c)>='a' && (c)<='f') ? ((c)-('a'-10)) \
1532 : ((c)>='A' && (c)<='F') ? ((c)-('A'-10)) \
1543 buf[i] = (buf[i] << 4) | v;
1550 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1554 unsigned char *chksum;
1559 static char *basearch;
1571 basearch = strdup(un.machine);
1572 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
1575 binarydir = sat_dupjoin("binary-", basearch, "/");
1576 lbinarydir = strlen(binarydir);
1577 compl = strlen(comp);
1581 chksum = sat_malloc(32);
1583 while(fgets(buf, sizeof(buf), fp))
1588 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1590 if (!strncasecmp(buf, "MD5Sum:", 7))
1592 curchksumtype = REPOKEY_TYPE_MD5;
1595 if (!strncasecmp(buf, "SHA1:", 5))
1597 curchksumtype = REPOKEY_TYPE_SHA1;
1600 if (!strncasecmp(buf, "SHA256:", 7))
1602 curchksumtype = REPOKEY_TYPE_SHA256;
1614 while (*bp && *bp != ' ' && *bp != '\t')
1619 while (*bp == ' ' || *bp == '\t')
1621 while (*bp && *bp != ' ' && *bp != '\t')
1625 while (*bp == ' ' || *bp == '\t')
1628 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1631 if (strncmp(bp, binarydir, lbinarydir))
1634 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1636 if (filename && !strcmp(bp, "Packages"))
1638 if (chksumtype && sat_chksum_len(chksumtype) > sat_chksum_len(curchksumtype))
1640 if (!hexstr2bytes(chksum, ch, sat_chksum_len(curchksumtype)))
1643 filename = strdup(fn);
1644 chksumtype = curchksumtype;
1650 fn = sat_dupjoin("/", filename, 0);
1652 filename = sat_dupjoin("dists/", cinfo->name, fn);
1656 chksum = sat_free(chksum);
1658 *chksumtypep = chksumtype;
1664 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1667 struct repoinfo *cinfo;
1671 const char *filename;
1672 const unsigned char *filechksum;
1674 const char *descrdir;
1686 repo = repo_create(pool, "@System");
1688 printf("rpm database:");
1689 if (stat("/var/lib/rpm/Packages", &stb))
1690 memset(&stb, 0, sizeof(&stb));
1692 printf("dpgk database:");
1693 if (stat("/var/lib/dpkg/status", &stb))
1694 memset(&stb, 0, sizeof(&stb));
1696 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, installedcookie);
1697 if (usecachedrepo(repo, 0, installedcookie, 0))
1698 printf(" cached\n");
1705 printf(" reading\n");
1707 #ifdef PRODUCTS_PATH
1708 repo_add_products(repo, PRODUCTS_PATH, 0, REPO_NO_INTERNALIZE);
1711 if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
1713 Repo *ref = repo_create(pool, "@System.old");
1714 if (!repo_add_solv(ref, ofp))
1716 repo_add_rpmdb(repo, ref, 0, REPO_REUSE_REPODATA);
1723 repo_add_rpmdb(repo, 0, 0, REPO_REUSE_REPODATA);
1725 repo_add_debdb(repo, REPO_REUSE_REPODATA);
1727 writecachedrepo(repo, 0, 0, installedcookie);
1729 pool_set_installed(pool, repo);
1731 for (i = 0; i < nrepoinfos; i++)
1733 cinfo = repoinfos + i;
1734 if (!cinfo->enabled)
1737 repo = repo_create(pool, cinfo->alias);
1739 repo->appdata = cinfo;
1740 repo->priority = 99 - cinfo->priority;
1742 dorefresh = cinfo->autorefresh;
1743 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0), &stb) == 0)
1745 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1748 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1750 printf("repo '%s':", cinfo->alias);
1751 printf(" cached\n");
1755 switch (cinfo->type)
1758 printf("rpmmd repo '%s':", cinfo->alias);
1760 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1762 printf(" no repomd.xml file, skipped\n");
1767 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1768 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1770 printf(" cached\n");
1774 if (cinfo->repo_gpgcheck)
1776 sigfp = curlfopen(cinfo, "repodata/repomd.xml.asc", 0, 0, 0, 0);
1779 printf(" unsigned, skipped\n");
1784 sigpool = read_sigs();
1785 if (!checksig(sigpool, fp, sigfp))
1787 printf(" checksig failed, skipped\n");
1794 repo_add_repomdxml(repo, fp, 0);
1796 printf(" fetching\n");
1797 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1798 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1800 repo_add_rpmmd(repo, fp, 0, 0);
1804 break; /* hopeless */
1806 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1807 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1809 repo_add_updateinfoxml(repo, fp, 0);
1813 data = repo_add_repodata(repo, 0);
1814 if (!repomd_add_ext(repo, data, "deltainfo"))
1815 repomd_add_ext(repo, data, "prestodelta");
1816 repomd_add_ext(repo, data, "filelists");
1817 repodata_internalize(data);
1819 writecachedrepo(repo, 0, 0, cinfo->cookie);
1820 repodata_create_stubs(repo_last_repodata(repo));
1824 printf("susetags repo '%s':", cinfo->alias);
1828 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1830 printf(" no content file, skipped\n");
1835 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1836 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1838 printf(" cached\n");
1842 if (cinfo->repo_gpgcheck)
1844 sigfp = curlfopen(cinfo, "content.asc", 0, 0, 0, 0);
1847 printf(" unsigned, skipped\n");
1854 sigpool = read_sigs();
1855 if (!checksig(sigpool, fp, sigfp))
1857 printf(" checksig failed, skipped\n");
1865 repo_add_content(repo, fp, 0);
1867 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1868 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1870 descrdir = "suse/setup/descr";
1871 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1873 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1876 printf(" no packages file entry, skipped\n");
1879 printf(" fetching\n");
1880 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) == 0)
1881 break; /* hopeless */
1882 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE);
1884 /* add default language */
1885 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1887 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1890 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1892 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES);
1896 repo_internalize(repo);
1897 data = repo_add_repodata(repo, 0);
1898 susetags_add_ext(repo, data);
1899 repodata_internalize(data);
1901 writecachedrepo(repo, 0, 0, cinfo->cookie);
1902 repodata_create_stubs(repo_last_repodata(repo));
1907 printf("debian repo '%s':", cinfo->alias);
1909 filename = sat_dupjoin("dists/", cinfo->name, "/Release");
1910 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
1912 printf(" no Release file, skipped\n");
1915 free((char *)filename);
1918 sat_free((char *)filename);
1919 if (cinfo->repo_gpgcheck)
1921 filename = sat_dupjoin("dists/", cinfo->name, "/Release.gpg");
1922 sigfp = curlfopen(cinfo, filename, 0, 0, 0, 0);
1923 sat_free((char *)filename);
1926 printf(" unsigned, skipped\n");
1931 sigpool = read_sigs();
1932 if (!checksig(sigpool, fpr, sigfp))
1934 printf(" checksig failed, skipped\n");
1941 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
1942 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1944 printf(" cached\n");
1948 printf(" fetching\n");
1949 for (j = 0; j < cinfo->ncomponents; j++)
1951 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
1953 printf("[component %s not found]\n", cinfo->components[j]);
1956 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1958 repo_add_debpackages(repo, fp, 0);
1961 sat_free((char *)filechksum);
1962 sat_free((char *)filename);
1966 writecachedrepo(repo, 0, 0, cinfo->cookie);
1971 printf("unsupported repo '%s': skipped\n", cinfo->alias);
1983 str2archid(Pool *pool, char *arch)
1988 id = str2id(pool, arch, 0);
1989 if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH)
1991 if (pool->id2arch && (id > pool->lastarch || !pool->id2arch[id]))
1997 #define DEPGLOB_NAME 1
1998 #define DEPGLOB_DEP 2
1999 #define DEPGLOB_NAMEDEP 3
2002 depglob(Pool *pool, char *name, Queue *job, int what)
2005 Id id = str2id(pool, name, 0);
2010 FOR_PROVIDES(p, pp, id)
2012 Solvable *s = pool->solvables + p;
2014 if (s->name == id && (what & DEPGLOB_NAME) != 0)
2016 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
2022 if (what == DEPGLOB_NAMEDEP)
2023 printf("[using capability match for '%s']\n", name);
2024 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
2029 if (strpbrk(name, "[*?") == 0)
2032 if ((what & DEPGLOB_NAME) != 0)
2034 /* looks like a name glob. hard work. */
2035 for (p = 1; p < pool->nsolvables; p++)
2037 Solvable *s = pool->solvables + p;
2038 if (!s->repo || !pool_installable(pool, s))
2041 if (fnmatch(name, id2str(pool, id), 0) == 0)
2043 for (i = 0; i < job->count; i += 2)
2044 if (job->elements[i] == SOLVER_SOLVABLE_NAME && job->elements[i + 1] == id)
2046 if (i == job->count)
2047 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
2054 if ((what & DEPGLOB_DEP))
2056 /* looks like a dep glob. really hard work. */
2057 for (id = 1; id < pool->ss.nstrings; id++)
2059 if (!pool->whatprovides[id])
2061 if (fnmatch(name, id2str(pool, id), 0) == 0)
2063 if (!match && what == DEPGLOB_NAMEDEP)
2064 printf("[using capability match for '%s']\n", name);
2065 for (i = 0; i < job->count; i += 2)
2066 if (job->elements[i] == SOLVER_SOLVABLE_PROVIDES && job->elements[i + 1] == id)
2068 if (i == job->count)
2069 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
2080 limitrelation(Pool *pool, Queue *job, int flags, Id evr)
2084 for (i = j = 0; i < job->count; i += 2)
2086 Id select = job->elements[i] & SOLVER_SELECTMASK;
2087 if (select != SOLVER_SOLVABLE_NAME && select != SOLVER_SOLVABLE_PROVIDES)
2089 fprintf(stderr, "limitrelation only works on name/provides jobs\n");
2092 job->elements[i + 1] = rel2id(pool, job->elements[i + 1], evr, flags, 1);
2093 if (flags == REL_ARCH)
2094 job->elements[i] |= SOLVER_SETARCH;
2095 if (flags == REL_EQ && select == SOLVER_SOLVABLE_NAME && job->elements[i])
2098 const char *evrstr = id2str(pool, evr);
2099 if (!strchr(evrstr, '-'))
2100 job->elements[i] |= SOLVER_SETEV;
2103 job->elements[i] |= SOLVER_SETEVR;
2105 /* make sure we still have matches */
2106 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2110 job->elements[j] = job->elements[i];
2111 job->elements[j + 1] = job->elements[i + 1];
2115 queue_truncate(job, j);
2120 limitrelation_arch(Pool *pool, Queue *job, int flags, char *evr)
2124 if ((r = strrchr(evr, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2127 limitrelation(pool, job, REL_ARCH, archid);
2128 limitrelation(pool, job, flags, str2id(pool, evr, 1));
2132 limitrelation(pool, job, flags, str2id(pool, evr, 1));
2133 return job->count / 2;
2137 limitrepo(Pool *pool, Id repofilter, Queue *job)
2145 for (i = j = 0; i < job->count; i += 2)
2148 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2150 s = pool_id2solvable(pool, p);
2151 if (s->repo && s->repo->repoid == repofilter)
2156 /* here we assume that repo == vendor, so we also set SOLVER_SETVENDOR */
2159 job->elements[j] = SOLVER_SOLVABLE | (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO | SOLVER_NOAUTOSET;
2160 job->elements[j + 1] = mq.elements[0];
2164 job->elements[j] = SOLVER_SOLVABLE_ONE_OF | (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO;
2165 job->elements[j + 1] = pool_queuetowhatprovides(pool, &mq);
2170 queue_truncate(job, j);
2176 mkselect(Pool *pool, int mode, char *name, Queue *job)
2184 int type = strpbrk(name, "[*?") == 0 ? SEARCH_STRING : SEARCH_GLOB;
2187 dataiterator_init(&di, pool, mode == SOLVER_ERASE ? pool->installed : 0, 0, SOLVABLE_FILELIST, name, type|SEARCH_FILES|SEARCH_COMPLETE_FILELIST);
2188 while (dataiterator_step(&di))
2190 Solvable *s = pool->solvables + di.solvid;
2191 if (!s->repo || !pool_installable(pool, s))
2193 queue_push(&q, di.solvid);
2194 dataiterator_skip_solvable(&di);
2196 dataiterator_free(&di);
2199 printf("[using file list match for '%s']\n", name);
2201 queue_push2(job, SOLVER_SOLVABLE_ONE_OF, pool_queuetowhatprovides(pool, &q));
2203 queue_push2(job, SOLVER_SOLVABLE | SOLVER_NOAUTOSET, q.elements[0]);
2205 return job->count / 2;
2208 if ((r = strpbrk(name, "<=>")) != 0)
2210 /* relation case, support:
2215 int nend = r - name;
2228 while (*r && *r == ' ' && *r == '\t')
2230 while (nend && (name[nend - 1] == ' ' || name[nend -1 ] == '\t'))
2234 fprintf(stderr, "bad relation\n");
2237 oldnend = name[nend];
2239 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2241 name[nend] = oldnend;
2242 limitrelation(pool, job, rflags, str2id(pool, r, 1));
2243 return job->count / 2;
2245 if ((r2 = strrchr(name, '.')) != 0 && r2[1] && (archid = str2archid(pool, r2 + 1)) != 0)
2248 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2250 name[nend] = oldnend;
2252 limitrelation(pool, job, REL_ARCH, archid);
2253 limitrelation(pool, job, rflags, str2id(pool, r, 1));
2254 return job->count / 2;
2258 name[nend] = oldnend;
2262 /* no relation case, support:
2266 * nameglob-version.arch
2267 * nameglob-version-release
2268 * nameglob-version-release.arch
2270 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2271 return job->count / 2;
2272 if ((r = strrchr(name, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2275 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2278 limitrelation(pool, job, REL_ARCH, archid);
2279 return job->count / 2;
2283 if ((r = strrchr(name, '-')) != 0)
2286 if (depglob(pool, name, job, DEPGLOB_NAME))
2288 /* have just the version */
2289 limitrelation_arch(pool, job, REL_EQ, r + 1);
2291 return job->count / 2;
2293 if ((r2 = strrchr(name, '-')) != 0)
2298 if (depglob(pool, name, job, DEPGLOB_NAME))
2300 /* have version-release */
2301 limitrelation_arch(pool, job, REL_EQ, r + 1);
2303 return job->count / 2;
2314 yesno(const char *str)
2316 char inbuf[128], *ip;
2323 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2328 while (*ip == ' ' || *ip == '\t')
2335 if (*ip == 'y' || *ip == 'n')
2336 return *ip == 'y' ? 1 : 0;
2350 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2352 struct fcstate *fcstate = cbdata;
2360 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
2363 s = pool_id2solvable(pool, p);
2364 if (pool->installed && s->repo == pool->installed)
2366 if (!s->repo->rpmdbid)
2368 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2371 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
2373 for (i = 0; i < fcstate->newpkgscnt; i++)
2374 if (fcstate->checkq->elements[i] == p)
2376 if (i == fcstate->newpkgscnt)
2378 fp = fcstate->newpkgsfps[i];
2382 return rpm_byfp(fp, solvable2str(pool, s), &fcstate->rpmdbstate);
2387 runrpm(const char *arg, const char *name, int dupfd3)
2392 if ((pid = fork()) == (pid_t)-1)
2399 if (dupfd3 != -1 && dupfd3 != 3)
2405 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2406 if (strcmp(arg, "-e") == 0)
2407 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2409 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2413 while (waitpid(pid, &status, 0) != pid)
2417 printf("rpm failed\n");
2427 rundpkg(const char *arg, const char *name, int dupfd3)
2432 if ((pid = fork()) == (pid_t)-1)
2439 if (dupfd3 != -1 && dupfd3 != 3)
2445 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2446 if (strcmp(arg, "--install") == 0)
2447 execlp("dpkg", "dpkg", "--install", "--force", "all", name, (char *)0);
2449 execlp("dpkg", "dpkg", "--remove", "--force", "all", name, (char *)0);
2453 while (waitpid(pid, &status, 0) != pid)
2457 printf("dpkg failed\n");
2465 nscallback(Pool *pool, void *data, Id name, Id evr)
2467 if (name == NAMESPACE_PRODUCTBUDDY)
2469 /* SUSE specific hack: each product has an associated rpm */
2470 Solvable *s = pool->solvables + evr;
2473 cap = str2id(pool, pool_tmpjoin(pool, "product(", id2str(pool, s->name) + 8, ")"), 0);
2476 cap = rel2id(pool, cap, s->evr, REL_EQ, 0);
2479 FOR_PROVIDES(p, pp, cap)
2481 Solvable *ps = pool->solvables + p;
2482 if (ps->repo == s->repo && ps->arch == s->arch)
2490 #ifdef SOFTLOCKS_PATH
2493 addsoftlocks(Pool *pool, Queue *job)
2497 char *bp, *ep, buf[4096];
2499 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2501 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2503 while (*bp == ' ' || *bp == '\t')
2505 if (!*bp || *bp == '#')
2507 for (ep = bp; *ep; ep++)
2508 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2511 type = SOLVER_SOLVABLE_NAME;
2512 if (!strncmp(bp, "provides:", 9) && bp[9])
2514 type = SOLVER_SOLVABLE_PROVIDES;
2517 id = str2id(pool, bp, 1);
2518 if (pool->installed)
2520 FOR_JOB_SELECT(p, pp, type, id)
2521 if (pool->solvables[p].repo == pool->installed)
2524 continue; /* ignore, as it is already installed */
2526 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2535 rewrite_repos(Pool *pool, Id *addedfileprovides)
2540 Queue fileprovidesq;
2542 int i, j, n, nprovidedids;
2543 struct repoinfo *cinfo;
2545 map_init(&providedids, pool->ss.nstrings);
2546 queue_init(&fileprovidesq);
2547 for (nprovidedids = 0; (id = addedfileprovides[nprovidedids]) != 0; nprovidedids++)
2548 MAPSET(&providedids, id);
2551 /* make sure this repo has just one main repodata */
2552 if (!repo->nrepodata)
2554 cinfo = repo->appdata;
2555 data = repo->repodata + 0;
2556 if (data->store.pagefd == -1)
2558 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2561 for (j = 0; j < fileprovidesq.count; j++)
2562 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2564 if (n == nprovidedids)
2565 continue; /* nothing new added */
2568 for (j = 0; addedfileprovides[j]; j++)
2569 repodata_add_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, addedfileprovides[j]);
2570 repodata_internalize(data);
2571 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2573 queue_free(&fileprovidesq);
2574 map_free(&providedids);
2578 #define MODE_INSTALL 1
2579 #define MODE_ERASE 2
2580 #define MODE_UPDATE 3
2581 #define MODE_DISTUPGRADE 4
2582 #define MODE_VERIFY 5
2583 #define MODE_PATCH 6
2585 #define MODE_REPOLIST 8
2586 #define MODE_SEARCH 9
2587 #define MODE_ERASECLEAN 10
2592 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2593 fprintf(stderr, "\n");
2594 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2595 fprintf(stderr, " versions from the repositories\n");
2596 fprintf(stderr, " erase: erase installed packages\n");
2597 fprintf(stderr, " info: display package information\n");
2598 fprintf(stderr, " install: install packages\n");
2599 fprintf(stderr, " list: list packages\n");
2600 fprintf(stderr, " repos: list enabled repositories\n");
2601 fprintf(stderr, " search: search name/summary/description\n");
2602 fprintf(stderr, " update: update installed packages\n");
2603 fprintf(stderr, " verify: check dependencies of installed packages\n");
2604 fprintf(stderr, "\n");
2609 main(int argc, char **argv)
2612 Repo *commandlinerepo = 0;
2613 Id *commandlinepkgs = 0;
2615 struct repoinfo *repoinfos;
2617 int mainmode = 0, mode = 0;
2622 char inbuf[128], *ip;
2625 Id *addedfileprovides = 0;
2632 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2634 mainmode = MODE_INSTALL;
2635 mode = SOLVER_INSTALL;
2637 else if (!strcmp(argv[0], "patch"))
2639 mainmode = MODE_PATCH;
2640 mode = SOLVER_INSTALL;
2642 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2644 mainmode = MODE_ERASE;
2645 mode = SOLVER_ERASE;
2647 else if (!strcmp(argv[0], "eraseclean") || !strcmp(argv[0], "rmclean"))
2649 mainmode = MODE_ERASECLEAN;
2650 mode = SOLVER_ERASE;
2652 else if (!strcmp(argv[0], "list"))
2654 mainmode = MODE_LIST;
2657 else if (!strcmp(argv[0], "info"))
2659 mainmode = MODE_INFO;
2662 else if (!strcmp(argv[0], "search"))
2664 mainmode = MODE_SEARCH;
2667 else if (!strcmp(argv[0], "verify"))
2669 mainmode = MODE_VERIFY;
2670 mode = SOLVER_VERIFY;
2672 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2674 mainmode = MODE_UPDATE;
2675 mode = SOLVER_UPDATE;
2677 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2679 mainmode = MODE_DISTUPGRADE;
2680 mode = SOLVER_UPDATE;
2682 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2684 mainmode = MODE_REPOLIST;
2690 pool = pool_create();
2694 const char *langs[] = {"de_DE", "de", "en"};
2695 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2700 pool->obsoleteusescolors = 1;
2702 pool_setloadcallback(pool, load_stub, 0);
2703 pool->nscallback = nscallback;
2704 // pool_setdebuglevel(pool, 2);
2706 repoinfos = read_repoinfos(pool, REPOINFO_PATH, &nrepoinfos);
2708 if (mainmode == MODE_REPOLIST)
2711 for (i = 0; i < nrepoinfos; i++)
2713 struct repoinfo *cinfo = repoinfos + i;
2714 if (!cinfo->enabled)
2716 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2721 read_repos(pool, repoinfos, nrepoinfos);
2723 if (argc > 2 && !strcmp(argv[1], "-r"))
2725 const char *rname = argv[2], *rp;
2726 for (rp = rname; *rp; rp++)
2727 if (*rp <= '0' || *rp >= '9')
2731 /* repo specified by number */
2732 int rnum = atoi(rname);
2733 for (i = 0; i < nrepoinfos; i++)
2735 struct repoinfo *cinfo = repoinfos + i;
2736 if (!cinfo->enabled)
2739 repofilter = cinfo->repo->repoid;
2744 /* repo specified by alias */
2748 if (!strcasecmp(rname, repo->name))
2749 repofilter = repo->repoid;
2754 fprintf(stderr, "%s: no such repo\n", rname);
2760 if (mainmode == MODE_SEARCH)
2766 map_init(&m, pool->nsolvables);
2767 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2768 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2769 dataiterator_set_search(&di, 0, 0);
2770 while (dataiterator_step(&di))
2771 MAPSET(&m, di.solvid);
2772 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2773 dataiterator_set_search(&di, 0, 0);
2774 while (dataiterator_step(&di))
2775 MAPSET(&m, di.solvid);
2776 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2777 dataiterator_set_search(&di, 0, 0);
2778 while (dataiterator_step(&di))
2779 MAPSET(&m, di.solvid);
2780 dataiterator_free(&di);
2782 for (p = 1; p < pool->nsolvables; p++)
2784 Solvable *s = pool_id2solvable(pool, p);
2787 printf(" - %s: %s\n", solvable2str(pool, s), solvable_lookup_str(s, SOLVABLE_SUMMARY));
2794 if (mainmode == MODE_LIST || mainmode == MODE_INSTALL)
2796 for (i = 1; i < argc; i++)
2799 l = strlen(argv[i]);
2801 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2804 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2807 if (access(argv[i], R_OK))
2812 if (!commandlinepkgs)
2813 commandlinepkgs = sat_calloc(argc, sizeof(Id));
2814 if (!commandlinerepo)
2815 commandlinerepo = repo_create(pool, "@commandline");
2817 repo_add_rpms(commandlinerepo, (const char **)argv + i, 1, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2819 repo_add_debs(commandlinerepo, (const char **)argv + i, 1, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2821 commandlinepkgs[i] = commandlinerepo->end - 1;
2823 if (commandlinerepo)
2824 repo_internalize(commandlinerepo);
2827 // FOR_REPOS(i, repo)
2828 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2829 addedfileprovides = 0;
2830 pool_addfileprovides_ids(pool, 0, &addedfileprovides);
2831 if (addedfileprovides && *addedfileprovides)
2832 rewrite_repos(pool, addedfileprovides);
2833 sat_free(addedfileprovides);
2834 pool_createwhatprovides(pool);
2837 for (i = 1; i < argc; i++)
2842 if (commandlinepkgs && commandlinepkgs[i])
2844 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2848 if (!mkselect(pool, mode, argv[i], &job2))
2850 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2853 if (repofilter && !limitrepo(pool, repofilter, &job2))
2855 fprintf(stderr, "nothing in repo matches '%s'\n", argv[i]);
2858 for (j = 0; j < job2.count; j++)
2859 queue_push(&job, job2.elements[j]);
2863 if (!job.count && mainmode != MODE_UPDATE && mainmode != MODE_DISTUPGRADE && mainmode != MODE_VERIFY && mainmode != MODE_PATCH)
2865 printf("no package matched\n");
2872 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
2874 /* list mode, no solver needed */
2875 for (i = 0; i < job.count; i += 2)
2877 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
2879 Solvable *s = pool_id2solvable(pool, p);
2880 if (mainmode == MODE_INFO)
2883 printf("Name: %s\n", solvable2str(pool, s));
2884 printf("Repo: %s\n", s->repo->name);
2885 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
2886 str = solvable_lookup_str(s, SOLVABLE_URL);
2888 printf("Url: %s\n", str);
2889 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
2891 printf("License: %s\n", str);
2892 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
2898 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
2900 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
2902 printf(" - %s [%s]\n", solvable2str(pool, s), s->repo->name);
2904 printf(" %s\n", sum);
2910 free_repoinfos(repoinfos, nrepoinfos);
2911 sat_free(commandlinepkgs);
2913 yum_substitute(pool, 0);
2918 if (mainmode == MODE_PATCH)
2924 map_init(&installedmap, pool->nsolvables);
2925 if (pool->installed)
2926 FOR_REPO_SOLVABLES(pool->installed, p, s)
2927 MAPSET(&installedmap, p);
2929 /* install all patches */
2930 for (p = 1; p < pool->nsolvables; p++)
2936 s = pool->solvables + p;
2937 if (strncmp(id2str(pool, s->name), "patch:", 6) != 0)
2939 FOR_PROVIDES(p2, pp, s->name)
2941 Solvable *s2 = pool->solvables + p2;
2942 if (s2->name != s->name)
2944 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2945 if (r < 0 || (r == 0 && p > p2))
2950 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2951 if (type && !strcmp(type, "optional"))
2953 r = solvable_trivial_installable_map(s, &installedmap, 0);
2956 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2963 queue_push2(&job, SOLVER_SOLVABLE, p);
2965 map_free(&installedmap);
2969 for (i = 0; i < job.count; i += 2)
2971 if (mode == SOLVER_UPDATE)
2973 /* make update of not installed packages an install */
2974 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
2975 if (pool->installed && pool->solvables[p].repo == pool->installed)
2979 job.elements[i] |= SOLVER_INSTALL;
2983 job.elements[i] |= mode;
2984 if (mainmode == MODE_ERASECLEAN)
2985 job.elements[i] |= SOLVER_CLEANDEPS;
2988 if (mainmode == MODE_DISTUPGRADE && allpkgs && repofilter)
2989 queue_push2(&job, SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_REPO, repofilter);
2991 // multiversion test
2992 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae", 1));
2993 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-base", 1));
2994 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-extra", 1));
2996 #ifdef SOFTLOCKS_PATH
2997 addsoftlocks(pool, &job);
3005 Id problem, solution;
3008 solv = solver_create(pool);
3009 solv->ignorealreadyrecommended = 1;
3010 solv->updatesystem = allpkgs && !repofilter && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE);
3011 solv->dosplitprovides = solv->updatesystem;
3012 solv->fixsystem = allpkgs && !repofilter && mainmode == MODE_VERIFY;
3013 if (mainmode == MODE_DISTUPGRADE && allpkgs && !repofilter)
3015 solv->distupgrade = 1;
3016 solv->allowdowngrade = 1;
3017 solv->allowarchchange = 1;
3018 solv->allowvendorchange = 1;
3020 if (mainmode == MODE_ERASE || mainmode == MODE_ERASECLEAN)
3021 solv->allowuninstall = 1; /* don't nag */
3023 solver_solve(solv, &job);
3024 if (!solv->problems.count)
3026 pcnt = solver_problem_count(solv);
3027 printf("Found %d problems:\n", pcnt);
3028 for (problem = 1; problem <= pcnt; problem++)
3031 printf("Problem %d:\n", problem);
3032 solver_printprobleminfo(solv, problem);
3034 scnt = solver_solution_count(solv, problem);
3035 for (solution = 1; solution <= scnt; solution++)
3037 printf("Solution %d:\n", solution);
3038 solver_printsolution(solv, problem, solution);
3043 printf("Please choose a solution: ");
3046 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
3051 while (*ip == ' ' || *ip == '\t')
3053 if (*ip >= '0' && *ip <= '9')
3056 if (take >= 1 && take <= scnt)
3072 solver_take_solution(solv, problem, take, &job);
3078 trans = &solv->trans;
3079 if (!trans->steps.count)
3081 printf("Nothing to do.\n");
3085 free_repoinfos(repoinfos, nrepoinfos);
3086 sat_free(commandlinepkgs);
3088 yum_substitute(pool, 0);
3093 printf("Transaction summary:\n\n");
3094 solver_printtransaction(solv);
3096 #if !defined(FEDORA) && !defined(DEBIAN)
3103 duc[1].path = "/usr/share/man";
3104 duc[2].path = "/sbin";
3105 duc[3].path = "/etc";
3106 transaction_calc_duchanges(trans, duc, 4);
3107 for (i = 0; i < 4; i++)
3108 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
3111 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
3114 if (!yesno("OK to continue (y/n)? "))
3120 free_repoinfos(repoinfos, nrepoinfos);
3121 sat_free(commandlinepkgs);
3123 yum_substitute(pool, 0);
3128 queue_init(&checkq);
3129 newpkgs = transaction_installedresult(trans, &checkq);
3134 int downloadsize = 0;
3135 for (i = 0; i < newpkgs; i++)
3139 p = checkq.elements[i];
3140 s = pool_id2solvable(pool, p);
3141 downloadsize += solvable_lookup_num(s, SOLVABLE_DOWNLOADSIZE, 0);
3143 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
3144 newpkgsfps = sat_calloc(newpkgs, sizeof(*newpkgsfps));
3145 for (i = 0; i < newpkgs; i++)
3147 unsigned int medianr;
3150 struct repoinfo *cinfo;
3151 const unsigned char *chksum;
3155 p = checkq.elements[i];
3156 s = pool_id2solvable(pool, p);
3157 if (s->repo == commandlinerepo)
3159 loc = solvable_get_location(s, &medianr);
3160 if (!(newpkgsfps[i] = fopen(loc, "r")))
3168 cinfo = s->repo->appdata;
3171 printf("%s: no repository information\n", s->repo->name);
3174 loc = solvable_get_location(s, &medianr);
3178 if (pool->installed && pool->installed->nsolvables)
3180 /* try a delta first */
3181 char *matchname = strdup(id2str(pool, s->name));
3182 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
3183 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
3184 while (dataiterator_step(&di))
3188 dataiterator_setpos_parent(&di);
3189 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
3190 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
3192 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
3193 FOR_PROVIDES(op, pp, s->name)
3195 Solvable *os = pool->solvables + op;
3196 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
3199 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
3201 /* base is installed, run sequence check */
3202 const char *seqname;
3211 seqname = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME);
3212 seqevr = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR);
3213 seqnum = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM);
3214 seq = pool_tmpjoin(pool, seqname, "-", seqevr);
3215 seq = pool_tmpjoin(pool, seq, "-", seqnum);
3217 sprintf(cmd, "/usr/bin/applydeltarpm -a %s -c -s ", id2str(pool, s->arch));
3219 sprintf(cmd, "/usr/bin/applydeltarpm -c -s ");
3221 if (system(pool_tmpjoin(pool, cmd, seq, 0)) != 0)
3222 continue; /* didn't match */
3223 /* looks good, download delta */
3225 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
3227 continue; /* no way! */
3228 dloc = pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_DIR);
3229 dloc = pool_tmpjoin(pool, dloc, "/", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_NAME));
3230 dloc = pool_tmpjoin(pool, dloc, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_EVR));
3231 dloc = pool_tmpjoin(pool, dloc, ".", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_SUFFIX));
3232 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
3234 /* got it, now reconstruct */
3235 newfd = opentmpfile();
3237 sprintf(cmd, "applydeltarpm -a %s /dev/fd/%d /dev/fd/%d", id2str(pool, s->arch), fileno(fp), newfd);
3239 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
3241 fcntl(fileno(fp), F_SETFD, 0);
3248 lseek(newfd, 0, SEEK_SET);
3250 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3251 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
3257 newpkgsfps[i] = fdopen(newfd, "r");
3262 dataiterator_free(&di);
3263 sat_free(matchname);
3270 continue; /* delta worked! */
3272 if (cinfo->type == TYPE_SUSETAGS)
3274 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3275 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3278 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3279 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3281 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3294 struct fcstate fcstate;
3296 printf("Searching for file conflicts\n");
3297 queue_init(&conflicts);
3298 fcstate.rpmdbstate = 0;
3299 fcstate.newpkgscnt = newpkgs;
3300 fcstate.checkq = &checkq;
3301 fcstate.newpkgsfps = newpkgsfps;
3302 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fileconflict_cb, &fcstate);
3303 if (conflicts.count)
3306 for (i = 0; i < conflicts.count; i += 5)
3307 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]));
3309 if (yesno("Re-run solver (y/n/q)? "))
3311 for (i = 0; i < newpkgs; i++)
3313 fclose(newpkgsfps[i]);
3314 newpkgsfps = sat_free(newpkgsfps);
3316 pool_add_fileconflicts_deps(pool, &conflicts);
3317 pool_createwhatprovides(pool); /* Hmm... */
3321 queue_free(&conflicts);
3325 printf("Committing transaction:\n\n");
3326 transaction_order(trans, 0);
3327 for (i = 0; i < trans->steps.count; i++)
3330 const char *evr, *evrp, *nvra;
3336 p = trans->steps.elements[i];
3337 s = pool_id2solvable(pool, p);
3338 Id type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3341 case SOLVER_TRANSACTION_ERASE:
3342 printf("erase %s\n", solvid2str(pool, p));
3344 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3346 /* strip epoch from evr */
3347 evr = evrp = id2str(pool, s->evr);
3348 while (*evrp >= '0' && *evrp <= '9')
3350 if (evrp > evr && evrp[0] == ':' && evrp[1])
3352 nvra = pool_tmpjoin(pool, id2str(pool, s->name), "-", evr);
3353 nvra = pool_tmpjoin(pool, nvra, ".", id2str(pool, s->arch));
3354 runrpm("-e", nvra, -1); /* too bad that --querybynumber doesn't work */
3356 rundpkg("--remove", id2str(pool, s->name), 0);
3359 case SOLVER_TRANSACTION_INSTALL:
3360 case SOLVER_TRANSACTION_MULTIINSTALL:
3361 printf("install %s\n", solvid2str(pool, p));
3362 for (j = 0; j < newpkgs; j++)
3363 if (checkq.elements[j] == p)
3365 fp = j < newpkgs ? newpkgsfps[j] : 0;
3369 lseek(fileno(fp), 0, SEEK_SET);
3371 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp));
3373 rundpkg("--install", "/dev/fd/3", fileno(fp));
3383 for (i = 0; i < newpkgs; i++)
3385 fclose(newpkgsfps[i]);
3386 sat_free(newpkgsfps);
3387 queue_free(&checkq);
3391 free_repoinfos(repoinfos, nrepoinfos);
3392 sat_free(commandlinepkgs);
3394 yum_substitute(pool, 0);