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 if (ent->d_name[0] == '.')
225 l = strlen(ent->d_name);
226 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
228 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
229 if ((fp = fopen(buf, "r")) == 0)
235 while(fgets(buf2, sizeof(buf2), fp))
240 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
243 while (*kp == ' ' || *kp == '\t')
245 if (!*kp || *kp == '#')
249 kp = yum_substitute(pool, kp);
253 vp = strrchr(kp, ']');
257 repoinfos = sat_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
258 cinfo = repoinfos + nrepoinfos++;
259 memset(cinfo, 0, sizeof(*cinfo));
260 cinfo->alias = strdup(kp + 1);
261 cinfo->type = TYPE_RPMMD;
262 cinfo->autorefresh = 1;
263 cinfo->priority = 99;
265 cinfo->repo_gpgcheck = 1;
267 cinfo->metadata_expire = METADATA_EXPIRE;
272 vp = strchr(kp, '=');
275 for (kpe = vp - 1; kpe >= kp; kpe--)
276 if (*kpe != ' ' && *kpe != '\t')
281 while (*vp == ' ' || *vp == '\t')
284 if (!strcmp(kp, "name"))
285 cinfo->name = strdup(vp);
286 else if (!strcmp(kp, "enabled"))
287 cinfo->enabled = *vp == '0' ? 0 : 1;
288 else if (!strcmp(kp, "autorefresh"))
289 cinfo->autorefresh = *vp == '0' ? 0 : 1;
290 else if (!strcmp(kp, "gpgcheck"))
291 cinfo->pkgs_gpgcheck = *vp == '0' ? 0 : 1;
292 else if (!strcmp(kp, "repo_gpgcheck"))
293 cinfo->repo_gpgcheck = *vp == '0' ? 0 : 1;
294 else if (!strcmp(kp, "baseurl"))
295 cinfo->baseurl = strdup(vp);
296 else if (!strcmp(kp, "mirrorlist"))
298 if (strstr(vp, "metalink"))
299 cinfo->metalink = strdup(vp);
301 cinfo->mirrorlist = strdup(vp);
303 else if (!strcmp(kp, "path"))
305 if (vp && strcmp(vp, "/") != 0)
306 cinfo->path = strdup(vp);
308 else if (!strcmp(kp, "type"))
310 if (!strcmp(vp, "yast2"))
311 cinfo->type = TYPE_SUSETAGS;
312 else if (!strcmp(vp, "rpm-md"))
313 cinfo->type = TYPE_RPMMD;
314 else if (!strcmp(vp, "plaindir"))
315 cinfo->type = TYPE_PLAINDIR;
317 cinfo->type = TYPE_UNKNOWN;
319 else if (!strcmp(kp, "priority"))
320 cinfo->priority = atoi(vp);
321 else if (!strcmp(kp, "keeppackages"))
322 cinfo->keeppackages = *vp == '0' ? 0 : 1;
328 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
329 *nrepoinfosp = nrepoinfos;
336 read_repoinfos(Pool *pool, const char *reposdir, int *nrepoinfosp)
342 char *kp, *url, *distro;
343 struct repoinfo *repoinfos = 0, *cinfo;
348 fp = fopen("/etc/apt/sources.list", "r");
355 dir = opendir("/etc/apt/sources.list.d");
359 if ((ent = readdir(dir)) == 0)
364 if (ent->d_name[0] == '.')
366 l = strlen(ent->d_name);
367 if (l < 5 || strcmp(ent->d_name + l - 5, ".list") != 0)
369 snprintf(buf, sizeof(buf), "%s/%s", "/etc/apt/sources.list.d", ent->d_name);
370 if (!(fp = fopen(buf, "r")))
373 while(fgets(buf2, sizeof(buf2), fp))
378 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
381 while (*kp == ' ' || *kp == '\t')
383 if (!*kp || *kp == '#')
385 if (strncmp(kp, "deb", 3) != 0)
388 if (*kp != ' ' && *kp != '\t')
390 while (*kp == ' ' || *kp == '\t')
395 while (*kp && *kp != ' ' && *kp != '\t')
399 while (*kp == ' ' || *kp == '\t')
404 while (*kp && *kp != ' ' && *kp != '\t')
408 while (*kp == ' ' || *kp == '\t')
412 repoinfos = sat_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
413 cinfo = repoinfos + nrepoinfos++;
414 memset(cinfo, 0, sizeof(*cinfo));
415 cinfo->baseurl = strdup(url);
416 cinfo->alias = sat_dupjoin(url, "/", distro);
417 cinfo->name = strdup(distro);
418 cinfo->type = TYPE_DEBIAN;
420 cinfo->autorefresh = 1;
421 cinfo->repo_gpgcheck = 1;
422 cinfo->metadata_expire = METADATA_EXPIRE;
426 while (*kp == ' ' || *kp == '\t')
431 while (*kp && *kp != ' ' && *kp != '\t')
435 cinfo->components = sat_extend(cinfo->components, cinfo->ncomponents, 1, sizeof(*cinfo->components), 15);
436 cinfo->components[cinfo->ncomponents++] = strdup(compo);
442 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
443 *nrepoinfosp = nrepoinfos;
450 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
453 for (i = 0; i < nrepoinfos; i++)
455 struct repoinfo *cinfo = repoinfos + i;
456 sat_free(cinfo->name);
457 sat_free(cinfo->alias);
458 sat_free(cinfo->path);
459 sat_free(cinfo->metalink);
460 sat_free(cinfo->mirrorlist);
461 sat_free(cinfo->baseurl);
462 for (j = 0; j < cinfo->ncomponents; j++)
463 sat_free(cinfo->components[j]);
464 sat_free(cinfo->components);
475 strcpy(tmpl, "/var/tmp/solvXXXXXX");
487 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
494 h = sat_chksum_create(chksumtype);
497 printf("%s: unknown checksum type\n", file);
500 while ((l = read(fd, buf, sizeof(buf))) > 0)
501 sat_chksum_add(h, buf, l);
502 lseek(fd, 0, SEEK_SET);
504 sum = sat_chksum_get(h, &l);
505 if (memcmp(sum, chksum, l))
507 printf("%s: checksum mismatch\n", file);
508 sat_chksum_free(h, 0);
511 sat_chksum_free(h, 0);
516 findfastest(char **urls, int nurls)
523 struct addrinfo hints, *result;;
525 fds = sat_calloc(nurls, sizeof(*fds));
526 socks = sat_calloc(nurls, sizeof(*socks));
527 for (i = 0; i < nurls; i++)
530 p = strchr(urls[i], '/');
543 if ((p2 = strchr(p, '@')) != 0)
546 if (!strncmp("https:", urls[i], 6))
548 else if (!strncmp("ftp:", urls[i], 4))
550 if ((p2 = strrchr(p, ':')) != 0)
559 sprintf(portstr, "%d", port);
560 memset(&hints, 0, sizeof(struct addrinfo));
561 hints.ai_family = AF_UNSPEC;
562 hints.ai_socktype = SOCK_STREAM;
563 hints.ai_flags = AI_NUMERICSERV;
565 if (!getaddrinfo(p, portstr, &hints, &result))
567 socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
570 fcntl(socks[i], F_SETFL, O_NONBLOCK);
571 if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1)
573 if (errno != EINPROGRESS)
580 freeaddrinfo(result);
587 for (i = j = 0; i < nurls; i++)
591 fds[j].fd = socks[i];
592 fds[j].events = POLLOUT;
600 if (poll(fds, j, 10000) <= 0)
602 i = -1; /* something is wrong */
605 for (i = 0; i < j; i++)
606 if ((fds[i].revents & POLLOUT) != 0)
609 socklen_t soel = sizeof(int);
610 if (getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, &soe, &soel) == -1 || soe != 0)
612 /* connect failed, kill socket */
613 for (j = 0; j < nurls; j++)
614 if (socks[j] == fds[i].fd)
627 i = -1; /* something is wrong, no bit was set */
630 /* now i contains the fastest fd index */
633 for (j = 0; j < nurls; j++)
634 if (socks[j] == fds[i].fd)
638 char *url0 = urls[0];
643 for (i = j = 0; i < nurls; i++)
651 findmetalinkurl(FILE *fp, unsigned char *chksump, Id *chksumtypep)
653 char buf[4096], *bp, *ep;
660 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
662 while (*bp == ' ' || *bp == '\t')
664 if (chksumtypep && !*chksumtypep && !strncmp(bp, "<hash type=\"sha256\">", 20))
669 memset(chksump, 0, 32);
670 for (i = 0; i < 64; i++)
673 if (c >= '0' && c <= '9')
674 chksump[i / 2] = chksump[i / 2] * 16 + (c - '0');
675 else if (c >= 'a' && c <= 'f')
676 chksump[i / 2] = chksump[i / 2] * 16 + (c - ('a' - 10));
677 else if (c >= 'A' && c <= 'F')
678 chksump[i / 2] = chksump[i / 2] * 16 + (c - ('A' - 10));
683 *chksumtypep = REPOKEY_TYPE_SHA256;
686 if (strncmp(bp, "<url", 4))
688 bp = strchr(bp, '>');
692 ep = strstr(bp, "repodata/repomd.xml</url>");
696 if (strncmp(bp, "http", 4))
698 urls = sat_extend(urls, nurls, 1, sizeof(*urls), 15);
699 urls[nurls++] = strdup(bp);
704 findfastest(urls, nurls > 5 ? 5 : nurls);
707 for (i = 0; i < nurls; i++)
710 ep = strchr(bp, '/');
711 if ((ep = strchr(ep + 2, '/')) != 0)
714 printf("[using mirror %s]\n", bp);
723 findmirrorlisturl(FILE *fp)
725 char buf[4096], *bp, *ep;
730 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
732 while (*bp == ' ' || *bp == '\t')
734 if (!*bp || *bp == '#')
737 while (l > 0 && (bp[l - 1] == ' ' || bp[l - 1] == '\t' || bp[l - 1] == '\n'))
739 urls = sat_extend(urls, nurls, 1, sizeof(*urls), 15);
740 urls[nurls++] = strdup(bp);
745 findfastest(urls, nurls > 5 ? 5 : nurls);
748 for (i = 0; i < nurls; i++)
751 ep = strchr(bp, '/');
752 if ((ep = strchr(ep + 2, '/')) != 0)
755 printf("[using mirror %s]\n", bp);
764 cookie_gzread(void *cookie, char *buf, size_t nbytes)
766 return gzread((gzFile *)cookie, buf, nbytes);
770 cookie_gzclose(void *cookie)
772 return gzclose((gzFile *)cookie);
776 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int *badchecksump)
782 const char *baseurl = cinfo->baseurl;
786 if (!cinfo->metalink && !cinfo->mirrorlist)
788 if (file != cinfo->metalink && file != cinfo->mirrorlist)
790 FILE *fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
791 unsigned char mlchksum[32];
796 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
798 cinfo->baseurl = findmirrorlisturl(fp);
803 if (strchr(cinfo->baseurl, '$'))
805 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
806 free(cinfo->baseurl);
807 cinfo->baseurl = strdup(b);
810 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
812 chksumtype = mlchksumtype;
815 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, badchecksump);
817 snprintf(url, sizeof(url), "%s", file);
822 if (l && baseurl[l - 1] == '/')
823 snprintf(url, sizeof(url), "%s%s", baseurl, file);
825 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
828 // printf("url: %s\n", url);
829 if ((pid = fork()) == (pid_t)-1)
841 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
846 while (waitpid(pid, &status, 0) != pid)
848 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
854 lseek(fd, 0, SEEK_SET);
857 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
863 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
873 cookie_io_functions_t cio;
876 sprintf(tmpl, "/dev/fd/%d", fd);
877 gzf = gzopen(tmpl, "r");
881 fprintf(stderr, "could not open /dev/fd/%d, /proc not mounted?\n", fd);
884 memset(&cio, 0, sizeof(cio));
885 cio.read = cookie_gzread;
886 cio.close = cookie_gzclose;
887 return fopencookie(gzf, "r", cio);
889 fcntl(fd, F_SETFD, FD_CLOEXEC);
890 return fdopen(fd, "r");
896 cleanupgpg(char *gpgdir)
899 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
901 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
903 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
905 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
907 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
913 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
922 off_t posfp, possigfp;
925 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
928 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
929 if (!(kfp = fopen(keysfile, "w")) )
935 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
939 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
940 if (!pubkey || !*pubkey)
942 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
944 if (fputc('\n', kfp) == EOF) /* Just in case... */
948 if (fclose(kfp) || !nkeys)
953 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
956 fprintf(stderr, "key import error\n");
961 posfp = lseek(fileno(fp), 0, SEEK_CUR);
962 lseek(fileno(fp), 0, SEEK_SET);
963 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
964 lseek(fileno(sigfp), 0, SEEK_SET);
965 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
966 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
967 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
969 lseek(fileno(sigfp), possigfp, SEEK_SET);
970 lseek(fileno(fp), posfp, SEEK_SET);
971 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
972 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
974 return r == 0 ? 1 : 0;
980 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
985 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));
986 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
987 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
989 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
990 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
991 return r == 0 ? 1 : 0;
996 #define CHKSUM_IDENT "1.1"
999 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
1002 void *h = sat_chksum_create(chktype);
1005 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1006 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
1007 sat_chksum_add(h, buf, l);
1009 sat_chksum_free(h, out);
1013 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *out)
1015 void *h = sat_chksum_create(chktype);
1016 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1017 sat_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
1018 sat_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
1019 sat_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
1020 sat_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
1021 sat_chksum_free(h, out);
1033 pool_setarch(pool, un.machine);
1036 char *calccachepath(Repo *repo, const char *repoext)
1038 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
1041 p = pool_tmpjoin(repo->pool, p, "_", repoext);
1042 p = pool_tmpjoin(repo->pool, p, ".solvx", 0);
1045 p = pool_tmpjoin(repo->pool, p, ".solv", 0);
1046 q = p + strlen(SOLVCACHE_PATH) + 1;
1056 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1059 unsigned char mycookie[32];
1060 unsigned char myextcookie[32];
1061 struct repoinfo *cinfo;
1064 cinfo = repo->appdata;
1065 if (!(fp = fopen(calccachepath(repo, repoext), "r")))
1067 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1072 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1077 if (cinfo && !repoext)
1079 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1090 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1091 if (strcmp(repoext, "DL") != 0)
1092 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1095 if (repo_add_solv_flags(repo, fp, flags))
1100 if (cinfo && !repoext)
1102 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1103 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1106 futimes(fileno(fp), 0); /* try to set modification time */
1112 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1117 struct repoinfo *cinfo;
1120 cinfo = repo->appdata;
1121 mkdir(SOLVCACHE_PATH, 0755);
1122 tmpl = sat_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
1130 if (!(fp = fdopen(fd, "w")))
1139 for (i = repo->start; i < repo->end; i++)
1140 if (repo->pool->solvables[i].repo != repo)
1146 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
1148 repodata_write(info, fp, repo_write_stdkeyfilter, 0);
1151 int oldnrepodata = repo->nrepodata;
1152 repo->nrepodata = 1; /* XXX: do this right */
1153 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
1154 repo->nrepodata = oldnrepodata;
1158 if (!repoext && cinfo)
1160 if (!cinfo->extcookie[0])
1162 /* create the ext cookie and append it */
1163 /* we just need some unique ID */
1165 if (!fstat(fileno(fp), &stb))
1169 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cinfo->extcookie);
1170 for (i = 0; i < 32; i++)
1171 cinfo->extcookie[i] ^= cookie[i];
1173 if (cinfo->extcookie[0] == 0)
1174 cinfo->extcookie[0] = 1;
1176 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1184 /* append our cookie describing the metadata state */
1185 if (fwrite(cookie, 32, 1, fp) != 1)
1200 /* switch to just saved repo to activate paging and save memory */
1201 FILE *fp = fopen(tmpl, "r");
1207 repo_empty(repo, 1);
1208 if (repo_add_solv_flags(repo, fp, SOLV_ADD_NO_STUBS))
1210 /* oops, no way to recover from here */
1211 fprintf(stderr, "internal error\n");
1217 /* make sure repodata contains complete repo */
1218 /* (this is how repodata_write saves it) */
1219 repodata_extend_block(info, repo->start, repo->end - repo->start);
1220 info->state = REPODATA_LOADING;
1221 /* no need for LOCALPOOL as pool already contains ids */
1222 repo_add_solv_flags(repo, fp, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1223 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1228 if (!rename(tmpl, calccachepath(repo, repoext)))
1237 Pool *sigpool = pool_create();
1239 Repo *repo = repo_create(sigpool, "rpmdbkeys");
1240 repo_add_rpmdb_pubkeys(repo, 0, 0);
1246 /* repomd helpers */
1248 static inline const char *
1249 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1251 Pool *pool = repo->pool;
1253 const char *filename;
1258 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1259 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1260 if (dataiterator_step(&di))
1262 dataiterator_setpos_parent(&di);
1263 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1264 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1266 dataiterator_free(&di);
1267 if (filename && !*chksumtypep)
1269 printf("no %s file checksum!\n", what);
1276 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1278 Pool *pool = repo->pool;
1280 Id chksumtype, handle;
1281 const unsigned char *chksum;
1282 const char *filename;
1284 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1285 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1286 if (!dataiterator_step(&di))
1288 dataiterator_free(&di);
1291 if (!strcmp(what, "prestodelta"))
1293 dataiterator_setpos_parent(&di);
1294 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1295 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, &chksumtype);
1296 if (!filename || !chksum)
1298 dataiterator_free(&di);
1301 handle = repodata_new_handle(data);
1302 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1303 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1305 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1306 if (!strcmp(what, "deltainfo"))
1308 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1309 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1311 if (!strcmp(what, "filelists"))
1313 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1314 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1316 dataiterator_free(&di);
1317 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1322 /* susetags helpers */
1324 static inline const char *
1325 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1327 Pool *pool = repo->pool;
1329 const char *filename;
1334 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
1335 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1336 if (dataiterator_step(&di))
1338 dataiterator_setpos_parent(&di);
1339 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
1342 dataiterator_free(&di);
1343 if (filename && !*chksumtypep)
1345 printf("no %s file checksum!\n", what);
1351 static Id susetags_langtags[] = {
1352 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
1353 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
1354 SOLVABLE_EULA, REPOKEY_TYPE_STR,
1355 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
1356 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
1357 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
1362 susetags_add_ext(Repo *repo, Repodata *data)
1364 Pool *pool = repo->pool;
1367 Id handle, filechksumtype;
1368 const unsigned char *filechksum;
1371 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
1372 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1373 while (dataiterator_step(&di))
1375 if (strncmp(di.kv.str, "packages.", 9) != 0)
1377 if (!strcmp(di.kv.str + 9, "gz"))
1379 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
1381 ext[0] = di.kv.str[9];
1382 ext[1] = di.kv.str[10];
1384 if (!strcmp(ext, "en"))
1386 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
1388 handle = repodata_new_handle(data);
1389 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
1391 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
1392 if (!strcmp(ext, "DU"))
1394 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
1395 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
1397 else if (!strcmp(ext, "FL"))
1399 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1400 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1404 for (i = 0; susetags_langtags[i]; i += 2)
1406 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
1407 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
1410 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1412 dataiterator_free(&di);
1417 iscompressed(const char *name)
1419 int l = strlen(name);
1420 return l > 3 && !strcmp(name + l - 3, ".gz") ? 1 : 0;
1427 load_stub(Pool *pool, Repodata *data, void *dp)
1429 const char *filename, *descrdir, *repomdtype;
1430 const unsigned char *filechksum;
1432 struct repoinfo *cinfo;
1437 cinfo = data->repo->appdata;
1439 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1443 ext[0] = filename[9];
1444 ext[1] = filename[10];
1447 printf("[%s:%s", data->repo->name, ext);
1449 if (usecachedrepo(data->repo, ext, cinfo->extcookie, 0))
1451 printf(" cached]\n"); fflush(stdout);
1455 printf(" fetching]\n"); fflush(stdout);
1457 defvendor = repo_lookup_id(data->repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1458 descrdir = repo_lookup_str(data->repo, SOLVID_META, SUSETAGS_DESCRDIR);
1460 descrdir = "suse/setup/descr";
1462 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1463 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1465 repo_add_susetags(data->repo, fp, defvendor, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1467 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
1471 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1474 if (!strcmp(repomdtype, "filelists"))
1476 else if (!strcmp(repomdtype, "deltainfo"))
1481 printf("[%s:%s", data->repo->name, ext);
1483 if (usecachedrepo(data->repo, ext, cinfo->extcookie, 0))
1485 printf(" cached]\n");fflush(stdout);
1488 printf(" fetching]\n"); fflush(stdout);
1489 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1491 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1492 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1494 if (!strcmp(ext, "FL"))
1495 repo_add_rpmmd(data->repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1496 else if (!strcmp(ext, "DL"))
1497 repo_add_deltainfoxml(data->repo, fp, REPO_USE_LOADING);
1499 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
1506 static unsigned char installedcookie[32];
1510 repo_add_debdb(Repo *repo, int flags)
1513 if ((fp = fopen("/var/lib/dpkg/status", "r")) == 0)
1515 perror("/var/lib/dpkg/status");
1518 repo_add_debpackages(repo, fp, flags);
1523 hexstr2bytes(unsigned char *buf, const char *str, int buflen)
1526 for (i = 0; i < buflen; i++)
1528 #define c2h(c) (((c)>='0' && (c)<='9') ? ((c)-'0') \
1529 : ((c)>='a' && (c)<='f') ? ((c)-('a'-10)) \
1530 : ((c)>='A' && (c)<='F') ? ((c)-('A'-10)) \
1541 buf[i] = (buf[i] << 4) | v;
1548 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1552 unsigned char *chksum;
1557 static char *basearch;
1569 basearch = strdup(un.machine);
1570 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
1573 binarydir = sat_dupjoin("binary-", basearch, "/");
1574 lbinarydir = strlen(binarydir);
1575 compl = strlen(comp);
1579 chksum = sat_malloc(32);
1581 while(fgets(buf, sizeof(buf), fp))
1586 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1588 if (!strncasecmp(buf, "MD5Sum:", 7))
1590 curchksumtype = REPOKEY_TYPE_MD5;
1593 if (!strncasecmp(buf, "SHA1:", 5))
1595 curchksumtype = REPOKEY_TYPE_SHA1;
1598 if (!strncasecmp(buf, "SHA256:", 7))
1600 curchksumtype = REPOKEY_TYPE_SHA256;
1612 while (*bp && *bp != ' ' && *bp != '\t')
1617 while (*bp == ' ' || *bp == '\t')
1619 while (*bp && *bp != ' ' && *bp != '\t')
1623 while (*bp == ' ' || *bp == '\t')
1626 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1629 if (strncmp(bp, binarydir, lbinarydir))
1632 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1634 if (filename && !strcmp(bp, "Packages"))
1636 if (chksumtype && sat_chksum_len(chksumtype) > sat_chksum_len(curchksumtype))
1638 if (!hexstr2bytes(chksum, ch, sat_chksum_len(curchksumtype)))
1641 filename = strdup(fn);
1642 chksumtype = curchksumtype;
1648 fn = sat_dupjoin("/", filename, 0);
1650 filename = sat_dupjoin("dists/", cinfo->name, fn);
1654 chksum = sat_free(chksum);
1656 *chksumtypep = chksumtype;
1662 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1665 struct repoinfo *cinfo;
1669 const char *filename;
1670 const unsigned char *filechksum;
1672 const char *descrdir;
1684 repo = repo_create(pool, "@System");
1686 printf("rpm database:");
1687 if (stat("/var/lib/rpm/Packages", &stb))
1688 memset(&stb, 0, sizeof(&stb));
1690 printf("dpgk database:");
1691 if (stat("/var/lib/dpkg/status", &stb))
1692 memset(&stb, 0, sizeof(&stb));
1694 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, installedcookie);
1695 if (usecachedrepo(repo, 0, installedcookie, 0))
1696 printf(" cached\n");
1703 printf(" reading\n");
1705 #ifdef PRODUCTS_PATH
1706 repo_add_products(repo, PRODUCTS_PATH, 0, REPO_NO_INTERNALIZE);
1709 if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
1711 Repo *ref = repo_create(pool, "@System.old");
1712 if (!repo_add_solv(ref, ofp))
1714 repo_add_rpmdb(repo, ref, 0, REPO_REUSE_REPODATA);
1721 repo_add_rpmdb(repo, 0, 0, REPO_REUSE_REPODATA);
1723 repo_add_debdb(repo, REPO_REUSE_REPODATA);
1725 writecachedrepo(repo, 0, 0, installedcookie);
1727 pool_set_installed(pool, repo);
1729 for (i = 0; i < nrepoinfos; i++)
1731 cinfo = repoinfos + i;
1732 if (!cinfo->enabled)
1735 repo = repo_create(pool, cinfo->alias);
1737 repo->appdata = cinfo;
1738 repo->priority = 99 - cinfo->priority;
1740 dorefresh = cinfo->autorefresh;
1741 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0), &stb) == 0)
1743 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1746 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1748 printf("repo '%s':", cinfo->alias);
1749 printf(" cached\n");
1753 switch (cinfo->type)
1756 printf("rpmmd repo '%s':", cinfo->alias);
1758 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1760 printf(" no repomd.xml file, skipped\n");
1765 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1766 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1768 printf(" cached\n");
1772 if (cinfo->repo_gpgcheck)
1774 sigfp = curlfopen(cinfo, "repodata/repomd.xml.asc", 0, 0, 0, 0);
1777 printf(" unsigned, skipped\n");
1782 sigpool = read_sigs();
1783 if (!checksig(sigpool, fp, sigfp))
1785 printf(" checksig failed, skipped\n");
1792 repo_add_repomdxml(repo, fp, 0);
1794 printf(" fetching\n");
1795 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1796 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1798 repo_add_rpmmd(repo, fp, 0, 0);
1802 break; /* hopeless */
1804 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1805 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1807 repo_add_updateinfoxml(repo, fp, 0);
1811 data = repo_add_repodata(repo, 0);
1812 if (!repomd_add_ext(repo, data, "deltainfo"))
1813 repomd_add_ext(repo, data, "prestodelta");
1814 repomd_add_ext(repo, data, "filelists");
1815 repodata_internalize(data);
1817 writecachedrepo(repo, 0, 0, cinfo->cookie);
1818 repodata_create_stubs(repo_last_repodata(repo));
1822 printf("susetags repo '%s':", cinfo->alias);
1826 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1828 printf(" no content file, skipped\n");
1833 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1834 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1836 printf(" cached\n");
1840 if (cinfo->repo_gpgcheck)
1842 sigfp = curlfopen(cinfo, "content.asc", 0, 0, 0, 0);
1845 printf(" unsigned, skipped\n");
1852 sigpool = read_sigs();
1853 if (!checksig(sigpool, fp, sigfp))
1855 printf(" checksig failed, skipped\n");
1863 repo_add_content(repo, fp, 0);
1865 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1866 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1868 descrdir = "suse/setup/descr";
1869 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1871 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1874 printf(" no packages file entry, skipped\n");
1877 printf(" fetching\n");
1878 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) == 0)
1879 break; /* hopeless */
1880 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE);
1882 /* add default language */
1883 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1885 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1888 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1890 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES);
1894 repo_internalize(repo);
1895 data = repo_add_repodata(repo, 0);
1896 susetags_add_ext(repo, data);
1897 repodata_internalize(data);
1899 writecachedrepo(repo, 0, 0, cinfo->cookie);
1900 repodata_create_stubs(repo_last_repodata(repo));
1905 printf("debian repo '%s':", cinfo->alias);
1907 filename = sat_dupjoin("dists/", cinfo->name, "/Release");
1908 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
1910 printf(" no Release file, skipped\n");
1913 free((char *)filename);
1916 sat_free((char *)filename);
1917 if (cinfo->repo_gpgcheck)
1919 filename = sat_dupjoin("dists/", cinfo->name, "/Release.gpg");
1920 sigfp = curlfopen(cinfo, filename, 0, 0, 0, 0);
1921 sat_free((char *)filename);
1924 printf(" unsigned, skipped\n");
1929 sigpool = read_sigs();
1930 if (!checksig(sigpool, fpr, sigfp))
1932 printf(" checksig failed, skipped\n");
1939 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
1940 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1942 printf(" cached\n");
1946 printf(" fetching\n");
1947 for (j = 0; j < cinfo->ncomponents; j++)
1949 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
1951 printf("[component %s not found]\n", cinfo->components[j]);
1954 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1956 repo_add_debpackages(repo, fp, 0);
1959 sat_free((char *)filechksum);
1960 sat_free((char *)filename);
1964 writecachedrepo(repo, 0, 0, cinfo->cookie);
1969 printf("unsupported repo '%s': skipped\n", cinfo->alias);
1981 str2archid(Pool *pool, char *arch)
1986 id = str2id(pool, arch, 0);
1987 if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH)
1989 if (pool->id2arch && (id > pool->lastarch || !pool->id2arch[id]))
1995 #define DEPGLOB_NAME 1
1996 #define DEPGLOB_DEP 2
1997 #define DEPGLOB_NAMEDEP 3
2000 depglob(Pool *pool, char *name, Queue *job, int what)
2003 Id id = str2id(pool, name, 0);
2008 FOR_PROVIDES(p, pp, id)
2010 Solvable *s = pool->solvables + p;
2012 if (s->name == id && (what & DEPGLOB_NAME) != 0)
2014 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
2020 if (what == DEPGLOB_NAMEDEP)
2021 printf("[using capability match for '%s']\n", name);
2022 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
2027 if (strpbrk(name, "[*?") == 0)
2030 if ((what & DEPGLOB_NAME) != 0)
2032 /* looks like a name glob. hard work. */
2033 for (p = 1; p < pool->nsolvables; p++)
2035 Solvable *s = pool->solvables + p;
2036 if (!s->repo || !pool_installable(pool, s))
2039 if (fnmatch(name, id2str(pool, id), 0) == 0)
2041 for (i = 0; i < job->count; i += 2)
2042 if (job->elements[i] == SOLVER_SOLVABLE_NAME && job->elements[i + 1] == id)
2044 if (i == job->count)
2045 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
2052 if ((what & DEPGLOB_DEP))
2054 /* looks like a dep glob. really hard work. */
2055 for (id = 1; id < pool->ss.nstrings; id++)
2057 if (!pool->whatprovides[id])
2059 if (fnmatch(name, id2str(pool, id), 0) == 0)
2061 if (!match && what == DEPGLOB_NAMEDEP)
2062 printf("[using capability match for '%s']\n", name);
2063 for (i = 0; i < job->count; i += 2)
2064 if (job->elements[i] == SOLVER_SOLVABLE_PROVIDES && job->elements[i + 1] == id)
2066 if (i == job->count)
2067 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
2078 limitrelation(Pool *pool, Queue *job, int flags, Id evr)
2082 for (i = j = 0; i < job->count; i += 2)
2084 Id select = job->elements[i] & SOLVER_SELECTMASK;
2085 if (select != SOLVER_SOLVABLE_NAME && select != SOLVER_SOLVABLE_PROVIDES)
2087 fprintf(stderr, "limitrelation only works on name/provides jobs\n");
2090 job->elements[i + 1] = rel2id(pool, job->elements[i + 1], evr, flags, 1);
2091 if (flags == REL_ARCH)
2092 job->elements[i] |= SOLVER_SETARCH;
2093 if (flags == REL_EQ && select == SOLVER_SOLVABLE_NAME && job->elements[i])
2096 const char *evrstr = id2str(pool, evr);
2097 if (!strchr(evrstr, '-'))
2098 job->elements[i] |= SOLVER_SETEV;
2101 job->elements[i] |= SOLVER_SETEVR;
2103 /* make sure we still have matches */
2104 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2108 job->elements[j] = job->elements[i];
2109 job->elements[j + 1] = job->elements[i + 1];
2113 queue_truncate(job, j);
2118 limitrelation_arch(Pool *pool, Queue *job, int flags, char *evr)
2122 if ((r = strrchr(evr, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2125 limitrelation(pool, job, REL_ARCH, archid);
2126 limitrelation(pool, job, flags, str2id(pool, evr, 1));
2130 limitrelation(pool, job, flags, str2id(pool, evr, 1));
2131 return job->count / 2;
2135 limitrepo(Pool *pool, Id repofilter, Queue *job)
2143 for (i = j = 0; i < job->count; i += 2)
2146 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2148 s = pool_id2solvable(pool, p);
2149 if (s->repo && s->repo->repoid == repofilter)
2154 /* here we assume that repo == vendor, so we also set SOLVER_SETVENDOR */
2157 job->elements[j] = SOLVER_SOLVABLE | (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO | SOLVER_NOAUTOSET;
2158 job->elements[j + 1] = mq.elements[0];
2162 job->elements[j] = SOLVER_SOLVABLE_ONE_OF | (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO;
2163 job->elements[j + 1] = pool_queuetowhatprovides(pool, &mq);
2168 queue_truncate(job, j);
2174 mkselect(Pool *pool, int mode, char *name, Queue *job)
2185 dataiterator_init(&di, pool, mode == SOLVER_ERASE ? pool->installed : 0, 0, SOLVABLE_FILELIST, name, SEARCH_STRING|SEARCH_FILES|SEARCH_COMPLETE_FILELIST);
2186 while (dataiterator_step(&di))
2188 Solvable *s = pool->solvables + di.solvid;
2189 if (!s->repo || !pool_installable(pool, s))
2191 queue_push(&q, di.solvid);
2192 dataiterator_skip_solvable(&di);
2194 dataiterator_free(&di);
2197 printf("[using file list match for '%s']\n", name);
2199 queue_push2(job, SOLVER_SOLVABLE_ONE_OF, pool_queuetowhatprovides(pool, &q));
2201 queue_push2(job, SOLVER_SOLVABLE | SOLVER_NOAUTOSET, q.elements[0]);
2203 return job->count / 2;
2206 if ((r = strpbrk(name, "<=>")) != 0)
2208 /* relation case, support:
2213 int nend = r - name;
2226 while (*r && *r == ' ' && *r == '\t')
2228 while (nend && (name[nend - 1] == ' ' || name[nend -1 ] == '\t'))
2232 fprintf(stderr, "bad relation\n");
2235 oldnend = name[nend];
2237 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2239 name[nend] = oldnend;
2240 limitrelation(pool, job, rflags, str2id(pool, r, 1));
2241 return job->count / 2;
2243 if ((r2 = strrchr(name, '.')) != 0 && r2[1] && (archid = str2archid(pool, r2 + 1)) != 0)
2246 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2248 name[nend] = oldnend;
2250 limitrelation(pool, job, REL_ARCH, archid);
2251 limitrelation(pool, job, rflags, str2id(pool, r, 1));
2252 return job->count / 2;
2256 name[nend] = oldnend;
2260 /* no relation case, support:
2264 * nameglob-version.arch
2265 * nameglob-version-release
2266 * nameglob-version-release.arch
2268 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2269 return job->count / 2;
2270 if ((r = strrchr(name, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2273 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2276 limitrelation(pool, job, REL_ARCH, archid);
2277 return job->count / 2;
2281 if ((r = strrchr(name, '-')) != 0)
2284 if (depglob(pool, name, job, DEPGLOB_NAME))
2286 /* have just the version */
2287 limitrelation_arch(pool, job, REL_EQ, r + 1);
2289 return job->count / 2;
2291 if ((r2 = strrchr(name, '-')) != 0)
2296 if (depglob(pool, name, job, DEPGLOB_NAME))
2298 /* have version-release */
2299 limitrelation_arch(pool, job, REL_EQ, r + 1);
2301 return job->count / 2;
2312 yesno(const char *str)
2314 char inbuf[128], *ip;
2321 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2326 while (*ip == ' ' || *ip == '\t')
2333 if (*ip == 'y' || *ip == 'n')
2334 return *ip == 'y' ? 1 : 0;
2348 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2350 struct fcstate *fcstate = cbdata;
2358 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
2361 s = pool_id2solvable(pool, p);
2362 if (pool->installed && s->repo == pool->installed)
2364 if (!s->repo->rpmdbid)
2366 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2369 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
2371 for (i = 0; i < fcstate->newpkgscnt; i++)
2372 if (fcstate->checkq->elements[i] == p)
2374 if (i == fcstate->newpkgscnt)
2376 fp = fcstate->newpkgsfps[i];
2380 return rpm_byfp(fp, solvable2str(pool, s), &fcstate->rpmdbstate);
2385 runrpm(const char *arg, const char *name, int dupfd3)
2390 if ((pid = fork()) == (pid_t)-1)
2397 if (dupfd3 != -1 && dupfd3 != 3)
2403 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2404 if (strcmp(arg, "-e") == 0)
2405 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2407 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2411 while (waitpid(pid, &status, 0) != pid)
2415 printf("rpm failed\n");
2425 rundpkg(const char *arg, const char *name, int dupfd3)
2430 if ((pid = fork()) == (pid_t)-1)
2437 if (dupfd3 != -1 && dupfd3 != 3)
2443 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2444 if (strcmp(arg, "--install") == 0)
2445 execlp("dpkg", "dpkg", "--install", "--force", "all", name, (char *)0);
2447 execlp("dpkg", "dpkg", "--remove", "--force", "all", name, (char *)0);
2451 while (waitpid(pid, &status, 0) != pid)
2455 printf("dpkg failed\n");
2463 nscallback(Pool *pool, void *data, Id name, Id evr)
2465 if (name == NAMESPACE_PRODUCTBUDDY)
2467 /* SUSE specific hack: each product has an associated rpm */
2468 Solvable *s = pool->solvables + evr;
2471 cap = str2id(pool, pool_tmpjoin(pool, "product(", id2str(pool, s->name) + 8, ")"), 0);
2474 cap = rel2id(pool, cap, s->evr, REL_EQ, 0);
2477 FOR_PROVIDES(p, pp, cap)
2479 Solvable *ps = pool->solvables + p;
2480 if (ps->repo == s->repo && ps->arch == s->arch)
2488 #ifdef SOFTLOCKS_PATH
2491 addsoftlocks(Pool *pool, Queue *job)
2495 char *bp, *ep, buf[4096];
2497 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2499 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2501 while (*bp == ' ' || *bp == '\t')
2503 if (!*bp || *bp == '#')
2505 for (ep = bp; *ep; ep++)
2506 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2509 type = SOLVER_SOLVABLE_NAME;
2510 if (!strncmp(bp, "provides:", 9) && bp[9])
2512 type = SOLVER_SOLVABLE_PROVIDES;
2515 id = str2id(pool, bp, 1);
2516 if (pool->installed)
2518 FOR_JOB_SELECT(p, pp, type, id)
2519 if (pool->solvables[p].repo == pool->installed)
2522 continue; /* ignore, as it is already installed */
2524 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2533 rewrite_repos(Pool *pool, Id *addedfileprovides)
2538 Queue fileprovidesq;
2540 int i, j, n, nprovidedids;
2541 struct repoinfo *cinfo;
2543 map_init(&providedids, pool->ss.nstrings);
2544 queue_init(&fileprovidesq);
2545 for (nprovidedids = 0; (id = addedfileprovides[nprovidedids]) != 0; nprovidedids++)
2546 MAPSET(&providedids, id);
2549 /* make sure this repo has just one main repodata */
2550 if (!repo->nrepodata)
2552 cinfo = repo->appdata;
2553 data = repo->repodata + 0;
2554 if (data->store.pagefd == -1)
2556 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2559 for (j = 0; j < fileprovidesq.count; j++)
2560 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2562 if (n == nprovidedids)
2563 continue; /* nothing new added */
2566 for (j = 0; addedfileprovides[j]; j++)
2567 repodata_add_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, addedfileprovides[j]);
2568 repodata_internalize(data);
2569 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2571 queue_free(&fileprovidesq);
2572 map_free(&providedids);
2576 #define MODE_INSTALL 1
2577 #define MODE_ERASE 2
2578 #define MODE_UPDATE 3
2579 #define MODE_DISTUPGRADE 4
2580 #define MODE_VERIFY 5
2581 #define MODE_PATCH 6
2583 #define MODE_REPOLIST 8
2584 #define MODE_SEARCH 9
2585 #define MODE_ERASECLEAN 10
2590 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2591 fprintf(stderr, "\n");
2592 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2593 fprintf(stderr, " versions from the repositories\n");
2594 fprintf(stderr, " erase: erase installed packages\n");
2595 fprintf(stderr, " info: display package information\n");
2596 fprintf(stderr, " install: install packages\n");
2597 fprintf(stderr, " list: list packages\n");
2598 fprintf(stderr, " repos: list enabled repositories\n");
2599 fprintf(stderr, " search: search name/summary/description\n");
2600 fprintf(stderr, " update: update installed packages\n");
2601 fprintf(stderr, " verify: check dependencies of installed packages\n");
2602 fprintf(stderr, "\n");
2607 main(int argc, char **argv)
2610 Repo *commandlinerepo = 0;
2611 Id *commandlinepkgs = 0;
2613 struct repoinfo *repoinfos;
2615 int mainmode = 0, mode = 0;
2620 char inbuf[128], *ip;
2623 Id *addedfileprovides = 0;
2630 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2632 mainmode = MODE_INSTALL;
2633 mode = SOLVER_INSTALL;
2635 else if (!strcmp(argv[0], "patch"))
2637 mainmode = MODE_PATCH;
2638 mode = SOLVER_INSTALL;
2640 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2642 mainmode = MODE_ERASE;
2643 mode = SOLVER_ERASE;
2645 else if (!strcmp(argv[0], "eraseclean") || !strcmp(argv[0], "rmclean"))
2647 mainmode = MODE_ERASECLEAN;
2648 mode = SOLVER_ERASE;
2650 else if (!strcmp(argv[0], "list"))
2652 mainmode = MODE_LIST;
2655 else if (!strcmp(argv[0], "info"))
2657 mainmode = MODE_INFO;
2660 else if (!strcmp(argv[0], "search"))
2662 mainmode = MODE_SEARCH;
2665 else if (!strcmp(argv[0], "verify"))
2667 mainmode = MODE_VERIFY;
2668 mode = SOLVER_VERIFY;
2670 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2672 mainmode = MODE_UPDATE;
2673 mode = SOLVER_UPDATE;
2675 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2677 mainmode = MODE_DISTUPGRADE;
2678 mode = SOLVER_UPDATE;
2680 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2682 mainmode = MODE_REPOLIST;
2688 pool = pool_create();
2692 const char *langs[] = {"de_DE", "de", "en"};
2693 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2698 pool->obsoleteusescolors = 1;
2700 pool_setloadcallback(pool, load_stub, 0);
2701 pool->nscallback = nscallback;
2702 // pool_setdebuglevel(pool, 2);
2704 repoinfos = read_repoinfos(pool, REPOINFO_PATH, &nrepoinfos);
2706 if (mainmode == MODE_REPOLIST)
2709 for (i = 0; i < nrepoinfos; i++)
2711 struct repoinfo *cinfo = repoinfos + i;
2712 if (!cinfo->enabled)
2714 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2719 read_repos(pool, repoinfos, nrepoinfos);
2721 if (argc > 2 && !strcmp(argv[1], "-r"))
2723 const char *rname = argv[2], *rp;
2724 for (rp = rname; *rp; rp++)
2725 if (*rp <= '0' || *rp >= '9')
2729 /* repo specified by number */
2730 int rnum = atoi(rname);
2731 for (i = 0; i < nrepoinfos; i++)
2733 struct repoinfo *cinfo = repoinfos + i;
2734 if (!cinfo->enabled)
2737 repofilter = cinfo->repo->repoid;
2742 /* repo specified by alias */
2746 if (!strcasecmp(rname, repo->name))
2747 repofilter = repo->repoid;
2752 fprintf(stderr, "%s: no such repo\n", rname);
2758 if (mainmode == MODE_SEARCH)
2764 map_init(&m, pool->nsolvables);
2765 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2766 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2767 dataiterator_set_search(&di, 0, 0);
2768 while (dataiterator_step(&di))
2769 MAPSET(&m, di.solvid);
2770 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2771 dataiterator_set_search(&di, 0, 0);
2772 while (dataiterator_step(&di))
2773 MAPSET(&m, di.solvid);
2774 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2775 dataiterator_set_search(&di, 0, 0);
2776 while (dataiterator_step(&di))
2777 MAPSET(&m, di.solvid);
2778 dataiterator_free(&di);
2780 for (p = 1; p < pool->nsolvables; p++)
2782 Solvable *s = pool_id2solvable(pool, p);
2785 printf(" - %s: %s\n", solvable2str(pool, s), solvable_lookup_str(s, SOLVABLE_SUMMARY));
2792 if (mainmode == MODE_LIST || mainmode == MODE_INSTALL)
2794 for (i = 1; i < argc; i++)
2797 l = strlen(argv[i]);
2799 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2802 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2805 if (access(argv[i], R_OK))
2810 if (!commandlinepkgs)
2811 commandlinepkgs = sat_calloc(argc, sizeof(Id));
2812 if (!commandlinerepo)
2813 commandlinerepo = repo_create(pool, "@commandline");
2815 repo_add_rpms(commandlinerepo, (const char **)argv + i, 1, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2817 repo_add_debs(commandlinerepo, (const char **)argv + i, 1, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2819 commandlinepkgs[i] = commandlinerepo->end - 1;
2821 if (commandlinerepo)
2822 repo_internalize(commandlinerepo);
2825 // FOR_REPOS(i, repo)
2826 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2827 addedfileprovides = 0;
2828 pool_addfileprovides_ids(pool, 0, &addedfileprovides);
2829 if (addedfileprovides && *addedfileprovides)
2830 rewrite_repos(pool, addedfileprovides);
2831 sat_free(addedfileprovides);
2832 pool_createwhatprovides(pool);
2835 for (i = 1; i < argc; i++)
2840 if (commandlinepkgs && commandlinepkgs[i])
2842 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2846 if (!mkselect(pool, mode, argv[i], &job2))
2848 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2851 if (repofilter && !limitrepo(pool, repofilter, &job2))
2853 fprintf(stderr, "nothing in repo matches '%s'\n", argv[i]);
2856 for (j = 0; j < job2.count; j++)
2857 queue_push(&job, job2.elements[j]);
2861 if (!job.count && mainmode != MODE_UPDATE && mainmode != MODE_DISTUPGRADE && mainmode != MODE_VERIFY && mainmode != MODE_PATCH)
2863 printf("no package matched\n");
2870 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
2872 /* list mode, no solver needed */
2873 for (i = 0; i < job.count; i += 2)
2875 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
2877 Solvable *s = pool_id2solvable(pool, p);
2878 if (mainmode == MODE_INFO)
2881 printf("Name: %s\n", solvable2str(pool, s));
2882 printf("Repo: %s\n", s->repo->name);
2883 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
2884 str = solvable_lookup_str(s, SOLVABLE_URL);
2886 printf("Url: %s\n", str);
2887 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
2889 printf("License: %s\n", str);
2890 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
2896 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
2898 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
2900 printf(" - %s [%s]\n", solvable2str(pool, s), s->repo->name);
2902 printf(" %s\n", sum);
2908 free_repoinfos(repoinfos, nrepoinfos);
2909 sat_free(commandlinepkgs);
2911 yum_substitute(pool, 0);
2916 if (mainmode == MODE_PATCH)
2922 map_init(&installedmap, pool->nsolvables);
2923 if (pool->installed)
2924 FOR_REPO_SOLVABLES(pool->installed, p, s)
2925 MAPSET(&installedmap, p);
2927 /* install all patches */
2928 for (p = 1; p < pool->nsolvables; p++)
2934 s = pool->solvables + p;
2935 if (strncmp(id2str(pool, s->name), "patch:", 6) != 0)
2937 FOR_PROVIDES(p2, pp, s->name)
2939 Solvable *s2 = pool->solvables + p2;
2940 if (s2->name != s->name)
2942 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2943 if (r < 0 || (r == 0 && p > p2))
2948 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2949 if (type && !strcmp(type, "optional"))
2951 r = solvable_trivial_installable_map(s, &installedmap, 0);
2954 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2961 queue_push2(&job, SOLVER_SOLVABLE, p);
2963 map_free(&installedmap);
2967 for (i = 0; i < job.count; i += 2)
2969 if (mode == SOLVER_UPDATE)
2971 /* make update of not installed packages an install */
2972 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
2973 if (pool->installed && pool->solvables[p].repo == pool->installed)
2977 job.elements[i] |= SOLVER_INSTALL;
2981 job.elements[i] |= mode;
2982 if (mainmode == MODE_ERASECLEAN)
2983 job.elements[i] |= SOLVER_CLEANDEPS;
2986 if (mainmode == MODE_DISTUPGRADE && allpkgs && repofilter)
2987 queue_push2(&job, SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_REPO, repofilter);
2989 // multiversion test
2990 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae", 1));
2991 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-base", 1));
2992 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-extra", 1));
2994 #ifdef SOFTLOCKS_PATH
2995 addsoftlocks(pool, &job);
3003 Id problem, solution;
3006 solv = solver_create(pool);
3007 solv->ignorealreadyrecommended = 1;
3008 solv->updatesystem = allpkgs && !repofilter && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE);
3009 solv->dosplitprovides = solv->updatesystem;
3010 solv->fixsystem = allpkgs && !repofilter && mainmode == MODE_VERIFY;
3011 if (mainmode == MODE_DISTUPGRADE && allpkgs && !repofilter)
3013 solv->distupgrade = 1;
3014 solv->allowdowngrade = 1;
3015 solv->allowarchchange = 1;
3016 solv->allowvendorchange = 1;
3018 if (mainmode == MODE_ERASE || mainmode == MODE_ERASECLEAN)
3019 solv->allowuninstall = 1; /* don't nag */
3021 solver_solve(solv, &job);
3022 if (!solv->problems.count)
3024 pcnt = solver_problem_count(solv);
3025 printf("Found %d problems:\n", pcnt);
3026 for (problem = 1; problem <= pcnt; problem++)
3029 printf("Problem %d:\n", problem);
3030 solver_printprobleminfo(solv, problem);
3032 scnt = solver_solution_count(solv, problem);
3033 for (solution = 1; solution <= scnt; solution++)
3035 printf("Solution %d:\n", solution);
3036 solver_printsolution(solv, problem, solution);
3041 printf("Please choose a solution: ");
3044 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
3049 while (*ip == ' ' || *ip == '\t')
3051 if (*ip >= '0' && *ip <= '9')
3054 if (take >= 1 && take <= scnt)
3070 solver_take_solution(solv, problem, take, &job);
3076 trans = &solv->trans;
3077 if (!trans->steps.count)
3079 printf("Nothing to do.\n");
3083 free_repoinfos(repoinfos, nrepoinfos);
3084 sat_free(commandlinepkgs);
3086 yum_substitute(pool, 0);
3091 printf("Transaction summary:\n\n");
3092 solver_printtransaction(solv);
3094 #if !defined(FEDORA) && !defined(DEBIAN)
3101 duc[1].path = "/usr/share/man";
3102 duc[2].path = "/sbin";
3103 duc[3].path = "/etc";
3104 transaction_calc_duchanges(trans, duc, 4);
3105 for (i = 0; i < 4; i++)
3106 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
3109 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
3112 if (!yesno("OK to continue (y/n)? "))
3118 free_repoinfos(repoinfos, nrepoinfos);
3119 sat_free(commandlinepkgs);
3121 yum_substitute(pool, 0);
3126 queue_init(&checkq);
3127 newpkgs = transaction_installedresult(trans, &checkq);
3132 int downloadsize = 0;
3133 for (i = 0; i < newpkgs; i++)
3137 p = checkq.elements[i];
3138 s = pool_id2solvable(pool, p);
3139 downloadsize += solvable_lookup_num(s, SOLVABLE_DOWNLOADSIZE, 0);
3141 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
3142 newpkgsfps = sat_calloc(newpkgs, sizeof(*newpkgsfps));
3143 for (i = 0; i < newpkgs; i++)
3145 unsigned int medianr;
3148 struct repoinfo *cinfo;
3149 const unsigned char *chksum;
3153 p = checkq.elements[i];
3154 s = pool_id2solvable(pool, p);
3155 if (s->repo == commandlinerepo)
3157 loc = solvable_get_location(s, &medianr);
3158 if (!(newpkgsfps[i] = fopen(loc, "r")))
3166 cinfo = s->repo->appdata;
3169 printf("%s: no repository information\n", s->repo->name);
3172 loc = solvable_get_location(s, &medianr);
3176 if (pool->installed && pool->installed->nsolvables)
3178 /* try a delta first */
3179 char *matchname = strdup(id2str(pool, s->name));
3180 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
3181 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
3182 while (dataiterator_step(&di))
3186 dataiterator_setpos_parent(&di);
3187 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
3188 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
3190 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
3191 FOR_PROVIDES(op, pp, s->name)
3193 Solvable *os = pool->solvables + op;
3194 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
3197 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
3199 /* base is installed, run sequence check */
3200 const char *seqname;
3209 seqname = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME);
3210 seqevr = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR);
3211 seqnum = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM);
3212 seq = pool_tmpjoin(pool, seqname, "-", seqevr);
3213 seq = pool_tmpjoin(pool, seq, "-", seqnum);
3215 sprintf(cmd, "/usr/bin/applydeltarpm -a %s -c -s ", id2str(pool, s->arch));
3217 sprintf(cmd, "/usr/bin/applydeltarpm -c -s ");
3219 if (system(pool_tmpjoin(pool, cmd, seq, 0)) != 0)
3220 continue; /* didn't match */
3221 /* looks good, download delta */
3223 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
3225 continue; /* no way! */
3226 dloc = pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_DIR);
3227 dloc = pool_tmpjoin(pool, dloc, "/", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_NAME));
3228 dloc = pool_tmpjoin(pool, dloc, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_EVR));
3229 dloc = pool_tmpjoin(pool, dloc, ".", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_SUFFIX));
3230 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
3232 /* got it, now reconstruct */
3233 newfd = opentmpfile();
3235 sprintf(cmd, "applydeltarpm -a %s /dev/fd/%d /dev/fd/%d", id2str(pool, s->arch), fileno(fp), newfd);
3237 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
3239 fcntl(fileno(fp), F_SETFD, 0);
3246 lseek(newfd, 0, SEEK_SET);
3248 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3249 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
3255 newpkgsfps[i] = fdopen(newfd, "r");
3260 dataiterator_free(&di);
3261 sat_free(matchname);
3268 continue; /* delta worked! */
3270 if (cinfo->type == TYPE_SUSETAGS)
3272 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3273 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3276 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3277 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3279 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3292 struct fcstate fcstate;
3294 printf("Searching for file conflicts\n");
3295 queue_init(&conflicts);
3296 fcstate.rpmdbstate = 0;
3297 fcstate.newpkgscnt = newpkgs;
3298 fcstate.checkq = &checkq;
3299 fcstate.newpkgsfps = newpkgsfps;
3300 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fileconflict_cb, &fcstate);
3301 if (conflicts.count)
3304 for (i = 0; i < conflicts.count; i += 5)
3305 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]));
3307 if (yesno("Re-run solver (y/n/q)? "))
3309 for (i = 0; i < newpkgs; i++)
3311 fclose(newpkgsfps[i]);
3312 newpkgsfps = sat_free(newpkgsfps);
3314 pool_add_fileconflicts_deps(pool, &conflicts);
3315 pool_createwhatprovides(pool); /* Hmm... */
3319 queue_free(&conflicts);
3323 printf("Committing transaction:\n\n");
3324 transaction_order(trans, 0);
3325 for (i = 0; i < trans->steps.count; i++)
3328 const char *evr, *evrp, *nvra;
3334 p = trans->steps.elements[i];
3335 s = pool_id2solvable(pool, p);
3336 Id type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3339 case SOLVER_TRANSACTION_ERASE:
3340 printf("erase %s\n", solvid2str(pool, p));
3342 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3344 /* strip epoch from evr */
3345 evr = evrp = id2str(pool, s->evr);
3346 while (*evrp >= '0' && *evrp <= '9')
3348 if (evrp > evr && evrp[0] == ':' && evrp[1])
3350 nvra = pool_tmpjoin(pool, id2str(pool, s->name), "-", evr);
3351 nvra = pool_tmpjoin(pool, nvra, ".", id2str(pool, s->arch));
3352 runrpm("-e", nvra, -1); /* too bad that --querybynumber doesn't work */
3354 rundpkg("--remove", id2str(pool, s->name), 0);
3357 case SOLVER_TRANSACTION_INSTALL:
3358 case SOLVER_TRANSACTION_MULTIINSTALL:
3359 printf("install %s\n", solvid2str(pool, p));
3360 for (j = 0; j < newpkgs; j++)
3361 if (checkq.elements[j] == p)
3363 fp = j < newpkgs ? newpkgsfps[j] : 0;
3367 lseek(fileno(fp), 0, SEEK_SET);
3369 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp));
3371 rundpkg("--install", "/dev/fd/3", fileno(fp));
3381 for (i = 0; i < newpkgs; i++)
3383 fclose(newpkgsfps[i]);
3384 sat_free(newpkgsfps);
3385 queue_free(&checkq);
3389 free_repoinfos(repoinfos, nrepoinfos);
3390 sat_free(commandlinepkgs);
3392 yum_substitute(pool, 0);