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"
64 #include "pool_fileconflicts.h"
70 #include "repo_rpmmd.h"
71 #include "repo_repomdxml.h"
72 #include "repo_updateinfoxml.h"
73 #include "repo_deltainfoxml.h"
75 #ifdef ENABLE_SUSEREPO
76 #include "repo_products.h"
77 #include "repo_susetags.h"
78 #include "repo_content.h"
80 #include "solv_xfopen.h"
83 # define REPOINFO_PATH "/etc/yum.repos.d"
85 # define REPOINFO_PATH "/etc/zypp/repos.d"
86 # define PRODUCTS_PATH "/etc/products.d"
87 # define SOFTLOCKS_PATH "/var/lib/zypp/SoftLocks"
90 #define SOLVCACHE_PATH "/var/cache/solv"
92 #define METADATA_EXPIRE (60 * 15)
114 unsigned char cookie[32];
115 unsigned char extcookie[32];
120 yum_substitute(Pool *pool, char *line)
123 static char *releaseevr;
124 static char *basearch;
128 solv_free(releaseevr);
135 while ((p2 = strchr(p, '$')) != 0)
137 if (!strncmp(p2, "$releasever", 11))
144 rpm_installedrpmdbids(0, "Providename", "redhat-release", &q);
147 void *handle, *state = 0;
149 handle = rpm_byrpmdbid(q.elements[0], 0, &state);
150 releaseevr = rpm_query(handle, SOLVABLE_EVR);
151 rpm_byrpmdbid(0, 0, &state);
152 if ((p = strchr(releaseevr, '-')) != 0)
157 releaseevr = strdup("?");
160 p = pool_tmpjoin(pool, line, releaseevr, p2 + 11);
161 p2 = p + (p2 - line);
163 p = p2 + strlen(releaseevr);
166 if (!strncmp(p2, "$basearch", 9))
176 basearch = strdup(un.machine);
177 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
181 p = pool_tmpjoin(pool, line, basearch, p2 + 9);
182 p2 = p + (p2 - line);
184 p = p2 + strlen(basearch);
193 #define TYPE_UNKNOWN 0
194 #define TYPE_SUSETAGS 1
196 #define TYPE_PLAINDIR 3
197 #define TYPE_DEBIAN 4
200 read_repoinfos_sort(const void *ap, const void *bp)
202 const struct repoinfo *a = ap;
203 const struct repoinfo *b = bp;
204 return strcmp(a->alias, b->alias);
210 read_repoinfos(Pool *pool, const char *reposdir, int *nrepoinfosp)
213 char buf2[4096], *kp, *vp, *kpe;
218 struct repoinfo *repoinfos = 0, *cinfo;
221 rdlen = strlen(reposdir);
222 dir = opendir(reposdir);
228 while ((ent = readdir(dir)) != 0)
230 if (ent->d_name[0] == '.')
232 l = strlen(ent->d_name);
233 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
235 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
236 if ((fp = fopen(buf, "r")) == 0)
242 while(fgets(buf2, sizeof(buf2), fp))
247 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
250 while (*kp == ' ' || *kp == '\t')
252 if (!*kp || *kp == '#')
256 kp = yum_substitute(pool, kp);
260 vp = strrchr(kp, ']');
264 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
265 cinfo = repoinfos + nrepoinfos++;
266 memset(cinfo, 0, sizeof(*cinfo));
267 cinfo->alias = strdup(kp + 1);
268 cinfo->type = TYPE_RPMMD;
269 cinfo->autorefresh = 1;
270 cinfo->priority = 99;
272 cinfo->repo_gpgcheck = 1;
274 cinfo->metadata_expire = METADATA_EXPIRE;
279 vp = strchr(kp, '=');
282 for (kpe = vp - 1; kpe >= kp; kpe--)
283 if (*kpe != ' ' && *kpe != '\t')
288 while (*vp == ' ' || *vp == '\t')
291 if (!strcmp(kp, "name"))
292 cinfo->name = strdup(vp);
293 else if (!strcmp(kp, "enabled"))
294 cinfo->enabled = *vp == '0' ? 0 : 1;
295 else if (!strcmp(kp, "autorefresh"))
296 cinfo->autorefresh = *vp == '0' ? 0 : 1;
297 else if (!strcmp(kp, "gpgcheck"))
298 cinfo->pkgs_gpgcheck = *vp == '0' ? 0 : 1;
299 else if (!strcmp(kp, "repo_gpgcheck"))
300 cinfo->repo_gpgcheck = *vp == '0' ? 0 : 1;
301 else if (!strcmp(kp, "baseurl"))
302 cinfo->baseurl = strdup(vp);
303 else if (!strcmp(kp, "mirrorlist"))
305 if (strstr(vp, "metalink"))
306 cinfo->metalink = strdup(vp);
308 cinfo->mirrorlist = strdup(vp);
310 else if (!strcmp(kp, "path"))
312 if (vp && strcmp(vp, "/") != 0)
313 cinfo->path = strdup(vp);
315 else if (!strcmp(kp, "type"))
317 if (!strcmp(vp, "yast2"))
318 cinfo->type = TYPE_SUSETAGS;
319 else if (!strcmp(vp, "rpm-md"))
320 cinfo->type = TYPE_RPMMD;
321 else if (!strcmp(vp, "plaindir"))
322 cinfo->type = TYPE_PLAINDIR;
324 cinfo->type = TYPE_UNKNOWN;
326 else if (!strcmp(kp, "priority"))
327 cinfo->priority = atoi(vp);
328 else if (!strcmp(kp, "keeppackages"))
329 cinfo->keeppackages = *vp == '0' ? 0 : 1;
335 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
336 *nrepoinfosp = nrepoinfos;
343 read_repoinfos(Pool *pool, const char *reposdir, int *nrepoinfosp)
349 char *kp, *url, *distro;
350 struct repoinfo *repoinfos = 0, *cinfo;
355 fp = fopen("/etc/apt/sources.list", "r");
362 dir = opendir("/etc/apt/sources.list.d");
366 if ((ent = readdir(dir)) == 0)
371 if (ent->d_name[0] == '.')
373 l = strlen(ent->d_name);
374 if (l < 5 || strcmp(ent->d_name + l - 5, ".list") != 0)
376 snprintf(buf, sizeof(buf), "%s/%s", "/etc/apt/sources.list.d", ent->d_name);
377 if (!(fp = fopen(buf, "r")))
380 while(fgets(buf2, sizeof(buf2), fp))
385 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
388 while (*kp == ' ' || *kp == '\t')
390 if (!*kp || *kp == '#')
392 if (strncmp(kp, "deb", 3) != 0)
395 if (*kp != ' ' && *kp != '\t')
397 while (*kp == ' ' || *kp == '\t')
402 while (*kp && *kp != ' ' && *kp != '\t')
406 while (*kp == ' ' || *kp == '\t')
411 while (*kp && *kp != ' ' && *kp != '\t')
415 while (*kp == ' ' || *kp == '\t')
419 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
420 cinfo = repoinfos + nrepoinfos++;
421 memset(cinfo, 0, sizeof(*cinfo));
422 cinfo->baseurl = strdup(url);
423 cinfo->alias = solv_dupjoin(url, "/", distro);
424 cinfo->name = strdup(distro);
425 cinfo->type = TYPE_DEBIAN;
427 cinfo->autorefresh = 1;
428 cinfo->repo_gpgcheck = 1;
429 cinfo->metadata_expire = METADATA_EXPIRE;
433 while (*kp == ' ' || *kp == '\t')
438 while (*kp && *kp != ' ' && *kp != '\t')
442 cinfo->components = solv_extend(cinfo->components, cinfo->ncomponents, 1, sizeof(*cinfo->components), 15);
443 cinfo->components[cinfo->ncomponents++] = strdup(compo);
449 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
450 *nrepoinfosp = nrepoinfos;
457 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
460 for (i = 0; i < nrepoinfos; i++)
462 struct repoinfo *cinfo = repoinfos + i;
463 solv_free(cinfo->name);
464 solv_free(cinfo->alias);
465 solv_free(cinfo->path);
466 solv_free(cinfo->metalink);
467 solv_free(cinfo->mirrorlist);
468 solv_free(cinfo->baseurl);
469 for (j = 0; j < cinfo->ncomponents; j++)
470 solv_free(cinfo->components[j]);
471 solv_free(cinfo->components);
473 solv_free(repoinfos);
482 strcpy(tmpl, "/var/tmp/solvXXXXXX");
494 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
497 const unsigned char *sum;
501 h = solv_chksum_create(chksumtype);
504 printf("%s: unknown checksum type\n", file);
507 while ((l = read(fd, buf, sizeof(buf))) > 0)
508 solv_chksum_add(h, buf, l);
509 lseek(fd, 0, SEEK_SET);
511 sum = solv_chksum_get(h, &l);
512 if (memcmp(sum, chksum, l))
514 printf("%s: checksum mismatch\n", file);
515 solv_chksum_free(h, 0);
518 solv_chksum_free(h, 0);
523 findfastest(char **urls, int nurls)
530 struct addrinfo hints, *result;;
532 fds = solv_calloc(nurls, sizeof(*fds));
533 socks = solv_calloc(nurls, sizeof(*socks));
534 for (i = 0; i < nurls; i++)
537 p = strchr(urls[i], '/');
550 if ((p2 = strchr(p, '@')) != 0)
553 if (!strncmp("https:", urls[i], 6))
555 else if (!strncmp("ftp:", urls[i], 4))
557 if ((p2 = strrchr(p, ':')) != 0)
566 sprintf(portstr, "%d", port);
567 memset(&hints, 0, sizeof(struct addrinfo));
568 hints.ai_family = AF_UNSPEC;
569 hints.ai_socktype = SOCK_STREAM;
570 hints.ai_flags = AI_NUMERICSERV;
572 if (!getaddrinfo(p, portstr, &hints, &result))
574 socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
577 fcntl(socks[i], F_SETFL, O_NONBLOCK);
578 if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1)
580 if (errno != EINPROGRESS)
587 freeaddrinfo(result);
594 for (i = j = 0; i < nurls; i++)
598 fds[j].fd = socks[i];
599 fds[j].events = POLLOUT;
607 if (poll(fds, j, 10000) <= 0)
609 i = -1; /* something is wrong */
612 for (i = 0; i < j; i++)
613 if ((fds[i].revents & POLLOUT) != 0)
616 socklen_t soel = sizeof(int);
617 if (getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, &soe, &soel) == -1 || soe != 0)
619 /* connect failed, kill socket */
620 for (j = 0; j < nurls; j++)
621 if (socks[j] == fds[i].fd)
634 i = -1; /* something is wrong, no bit was set */
637 /* now i contains the fastest fd index */
640 for (j = 0; j < nurls; j++)
641 if (socks[j] == fds[i].fd)
645 char *url0 = urls[0];
650 for (i = j = 0; i < nurls; i++)
658 findmetalinkurl(FILE *fp, unsigned char *chksump, Id *chksumtypep)
660 char buf[4096], *bp, *ep;
667 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
669 while (*bp == ' ' || *bp == '\t')
671 if (chksumtypep && !*chksumtypep && !strncmp(bp, "<hash type=\"sha256\">", 20))
674 if (solv_hex2bin((const char **)&bp, chksump, 32) == 32)
675 *chksumtypep = REPOKEY_TYPE_SHA256;
678 if (strncmp(bp, "<url", 4))
680 bp = strchr(bp, '>');
684 ep = strstr(bp, "repodata/repomd.xml</url>");
688 if (strncmp(bp, "http", 4))
690 urls = solv_extend(urls, nurls, 1, sizeof(*urls), 15);
691 urls[nurls++] = strdup(bp);
696 findfastest(urls, nurls > 5 ? 5 : nurls);
699 for (i = 0; i < nurls; i++)
702 ep = strchr(bp, '/');
703 if ((ep = strchr(ep + 2, '/')) != 0)
706 printf("[using mirror %s]\n", bp);
715 findmirrorlisturl(FILE *fp)
717 char buf[4096], *bp, *ep;
722 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
724 while (*bp == ' ' || *bp == '\t')
726 if (!*bp || *bp == '#')
729 while (l > 0 && (bp[l - 1] == ' ' || bp[l - 1] == '\t' || bp[l - 1] == '\n'))
731 urls = solv_extend(urls, nurls, 1, sizeof(*urls), 15);
732 urls[nurls++] = strdup(bp);
737 findfastest(urls, nurls > 5 ? 5 : nurls);
740 for (i = 0; i < nurls; i++)
743 ep = strchr(bp, '/');
744 if ((ep = strchr(ep + 2, '/')) != 0)
747 printf("[using mirror %s]\n", bp);
756 iscompressed(const char *name)
758 int l = strlen(name);
759 return l > 3 && !strcmp(name + l - 3, ".gz") ? 1 : 0;
763 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int *badchecksump)
769 const char *baseurl = cinfo->baseurl;
773 if (!cinfo->metalink && !cinfo->mirrorlist)
775 if (file != cinfo->metalink && file != cinfo->mirrorlist)
777 FILE *fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
778 unsigned char mlchksum[32];
783 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
785 cinfo->baseurl = findmirrorlisturl(fp);
790 if (strchr(cinfo->baseurl, '$'))
792 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
793 free(cinfo->baseurl);
794 cinfo->baseurl = strdup(b);
797 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
799 chksumtype = mlchksumtype;
802 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, badchecksump);
804 snprintf(url, sizeof(url), "%s", file);
809 if (l && baseurl[l - 1] == '/')
810 snprintf(url, sizeof(url), "%s%s", baseurl, file);
812 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
815 // printf("url: %s\n", url);
816 if ((pid = fork()) == (pid_t)-1)
828 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
833 while (waitpid(pid, &status, 0) != pid)
835 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
841 lseek(fd, 0, SEEK_SET);
844 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
850 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
858 return solv_xfopen_fd(".gz", fd, "r");
859 fcntl(fd, F_SETFD, FD_CLOEXEC);
860 return fdopen(fd, "r");
866 cleanupgpg(char *gpgdir)
869 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
871 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
873 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
875 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
877 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
883 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
892 off_t posfp, possigfp;
895 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
898 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
899 if (!(kfp = fopen(keysfile, "w")) )
905 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
909 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
910 if (!pubkey || !*pubkey)
912 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
914 if (fputc('\n', kfp) == EOF) /* Just in case... */
918 if (fclose(kfp) || !nkeys)
923 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
926 fprintf(stderr, "key import error\n");
931 posfp = lseek(fileno(fp), 0, SEEK_CUR);
932 lseek(fileno(fp), 0, SEEK_SET);
933 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
934 lseek(fileno(sigfp), 0, SEEK_SET);
935 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
936 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
937 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
939 lseek(fileno(sigfp), possigfp, SEEK_SET);
940 lseek(fileno(fp), posfp, SEEK_SET);
941 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
942 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
944 return r == 0 ? 1 : 0;
950 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
955 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));
956 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
957 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
959 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
960 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
961 return r == 0 ? 1 : 0;
966 #define CHKSUM_IDENT "1.1"
969 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
972 void *h = solv_chksum_create(chktype);
975 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
976 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
977 solv_chksum_add(h, buf, l);
979 solv_chksum_free(h, out);
983 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *out)
985 void *h = solv_chksum_create(chktype);
986 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
987 solv_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
988 solv_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
989 solv_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
990 solv_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
991 solv_chksum_free(h, out);
1003 pool_setarch(pool, un.machine);
1006 char *calccachepath(Repo *repo, const char *repoext)
1008 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
1011 p = pool_tmpappend(repo->pool, p, "_", repoext);
1012 p = pool_tmpappend(repo->pool, p, ".solvx", 0);
1015 p = pool_tmpappend(repo->pool, p, ".solv", 0);
1016 q = p + strlen(SOLVCACHE_PATH) + 1;
1026 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1029 unsigned char mycookie[32];
1030 unsigned char myextcookie[32];
1031 struct repoinfo *cinfo;
1034 cinfo = repo->appdata;
1035 if (!(fp = fopen(calccachepath(repo, repoext), "r")))
1037 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1042 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1047 if (cinfo && !repoext)
1049 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1060 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1061 if (strcmp(repoext, "DL") != 0)
1062 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1065 if (repo_add_solv(repo, fp, flags))
1070 if (cinfo && !repoext)
1072 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1073 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1076 futimes(fileno(fp), 0); /* try to set modification time */
1082 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1087 struct repoinfo *cinfo;
1090 cinfo = repo->appdata;
1091 mkdir(SOLVCACHE_PATH, 0755);
1092 /* use dupjoin instead of tmpjoin because tmpl must survive repo_write */
1093 tmpl = solv_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
1101 if (!(fp = fdopen(fd, "w")))
1110 for (i = repo->start; i < repo->end; i++)
1111 if (repo->pool->solvables[i].repo != repo)
1117 repo_write(repo, fp);
1119 repodata_write(info, fp);
1122 int oldnrepodata = repo->nrepodata;
1123 repo->nrepodata = oldnrepodata > 2 ? 2 : oldnrepodata; /* XXX: do this right */
1124 repo_write(repo, fp);
1125 repo->nrepodata = oldnrepodata;
1129 if (!repoext && cinfo)
1131 if (!cinfo->extcookie[0])
1133 /* create the ext cookie and append it */
1134 /* we just need some unique ID */
1136 if (!fstat(fileno(fp), &stb))
1140 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cinfo->extcookie);
1141 for (i = 0; i < 32; i++)
1142 cinfo->extcookie[i] ^= cookie[i];
1144 if (cinfo->extcookie[0] == 0)
1145 cinfo->extcookie[0] = 1;
1147 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1155 /* append our cookie describing the metadata state */
1156 if (fwrite(cookie, 32, 1, fp) != 1)
1171 /* switch to just saved repo to activate paging and save memory */
1172 FILE *fp = fopen(tmpl, "r");
1178 repo_empty(repo, 1);
1179 if (repo_add_solv(repo, fp, SOLV_ADD_NO_STUBS))
1181 /* oops, no way to recover from here */
1182 fprintf(stderr, "internal error\n");
1188 /* make sure repodata contains complete repo */
1189 /* (this is how repodata_write saves it) */
1190 repodata_extend_block(info, repo->start, repo->end - repo->start);
1191 info->state = REPODATA_LOADING;
1192 /* no need for LOCALPOOL as pool already contains ids */
1193 repo_add_solv(repo, fp, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1194 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1199 if (!rename(tmpl, calccachepath(repo, repoext)))
1208 Pool *sigpool = pool_create();
1209 #if defined(ENABLE_RPMDB_PUBKEY)
1210 Repo *repo = repo_create(sigpool, "rpmdbkeys");
1211 repo_add_rpmdb_pubkeys(repo, 0, 0);
1218 /* repomd helpers */
1220 static inline const char *
1221 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1223 Pool *pool = repo->pool;
1225 const char *filename;
1230 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1231 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1232 if (dataiterator_step(&di))
1234 dataiterator_setpos_parent(&di);
1235 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1236 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1238 dataiterator_free(&di);
1239 if (filename && !*chksumtypep)
1241 printf("no %s file checksum!\n", what);
1248 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1250 Id chksumtype, handle;
1251 const unsigned char *chksum;
1252 const char *filename;
1254 filename = repomd_find(repo, what, &chksum, &chksumtype);
1257 if (!strcmp(what, "prestodelta"))
1259 handle = repodata_new_handle(data);
1260 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1261 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1262 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1263 if (!strcmp(what, "deltainfo"))
1265 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1266 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1268 if (!strcmp(what, "filelists"))
1270 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1271 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1273 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1278 repomd_load_ext(Repo *repo, Repodata *data)
1280 const char *filename, *repomdtype;
1283 struct repoinfo *cinfo;
1284 const unsigned char *filechksum;
1287 cinfo = repo->appdata;
1288 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1291 if (!strcmp(repomdtype, "filelists"))
1293 else if (!strcmp(repomdtype, "deltainfo"))
1298 printf("[%s:%s", repo->name, ext);
1300 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1302 printf(" cached]\n");fflush(stdout);
1305 printf(" fetching]\n"); fflush(stdout);
1306 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1308 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1309 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1311 if (!strcmp(ext, "FL"))
1312 repo_add_rpmmd(repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1313 else if (!strcmp(ext, "DL"))
1314 repo_add_deltainfoxml(repo, fp, REPO_USE_LOADING);
1316 writecachedrepo(repo, data, ext, cinfo->extcookie);
1323 #ifdef ENABLE_SUSEREPO
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);
1418 susetags_load_ext(Repo *repo, Repodata *data)
1420 const char *filename, *descrdir;
1424 struct repoinfo *cinfo;
1425 const unsigned char *filechksum;
1428 cinfo = repo->appdata;
1429 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1433 ext[0] = filename[9];
1434 ext[1] = filename[10];
1437 printf("[%s:%s", repo->name, ext);
1439 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1441 printf(" cached]\n"); fflush(stdout);
1445 printf(" fetching]\n"); fflush(stdout);
1447 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1448 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1450 descrdir = "suse/setup/descr";
1452 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1453 if ((fp = curlfopen(cinfo, pool_tmpjoin(repo->pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1455 repo_add_susetags(repo, fp, defvendor, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1457 writecachedrepo(repo, data, ext, cinfo->extcookie);
1467 load_stub(Pool *pool, Repodata *data, void *dp)
1469 struct repoinfo *cinfo = data->repo->appdata;
1470 #ifdef ENABLE_SUSEREPO
1471 if (cinfo->type == TYPE_SUSETAGS)
1472 return susetags_load_ext(data->repo, data);
1475 if (cinfo->type == TYPE_RPMMD)
1476 return repomd_load_ext(data->repo, data);
1481 static unsigned char installedcookie[32];
1483 #ifdef ENABLE_DEBIAN
1486 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1490 unsigned char *chksum;
1495 static char *basearch;
1507 basearch = strdup(un.machine);
1508 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
1511 binarydir = solv_dupjoin("binary-", basearch, "/");
1512 lbinarydir = strlen(binarydir);
1513 compl = strlen(comp);
1517 chksum = solv_malloc(32);
1519 while(fgets(buf, sizeof(buf), fp))
1524 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1526 if (!strncasecmp(buf, "MD5Sum:", 7))
1528 curchksumtype = REPOKEY_TYPE_MD5;
1531 if (!strncasecmp(buf, "SHA1:", 5))
1533 curchksumtype = REPOKEY_TYPE_SHA1;
1536 if (!strncasecmp(buf, "SHA256:", 7))
1538 curchksumtype = REPOKEY_TYPE_SHA256;
1550 while (*bp && *bp != ' ' && *bp != '\t')
1555 while (*bp == ' ' || *bp == '\t')
1557 while (*bp && *bp != ' ' && *bp != '\t')
1561 while (*bp == ' ' || *bp == '\t')
1564 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1567 if (strncmp(bp, binarydir, lbinarydir))
1570 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1572 unsigned char curchksum[32];
1574 if (filename && !strcmp(bp, "Packages"))
1576 curl = solv_chksum_len(curchksumtype);
1577 if (!curl || (chksumtype && solv_chksum_len(chksumtype) > curl))
1579 if (solv_hex2bin((const char **)&ch, curchksum, sizeof(curchksum)) != curl)
1581 solv_free(filename);
1582 filename = strdup(fn);
1583 chksumtype = curchksumtype;
1584 memcpy(chksum, curchksum, curl);
1590 fn = solv_dupjoin("/", filename, 0);
1591 solv_free(filename);
1592 filename = solv_dupjoin("dists/", cinfo->name, fn);
1596 chksum = solv_free(chksum);
1598 *chksumtypep = chksumtype;
1604 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1607 struct repoinfo *cinfo;
1611 const char *filename;
1612 const unsigned char *filechksum;
1614 #ifdef ENABLE_SUSEREPO
1615 const char *descrdir;
1623 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1628 repo = repo_create(pool, "@System");
1629 #if defined(ENABLE_RPMDB) && !defined(DEBIAN)
1630 printf("rpm database:");
1631 if (stat("/var/lib/rpm/Packages", &stb))
1632 memset(&stb, 0, sizeof(&stb));
1634 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1635 printf("dpgk database:");
1636 if (stat("/var/lib/dpkg/status", &stb))
1637 memset(&stb, 0, sizeof(&stb));
1639 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, installedcookie);
1640 if (usecachedrepo(repo, 0, installedcookie, 0))
1641 printf(" cached\n");
1644 #if defined(ENABLE_RPMDB) && !defined(DEBIAN)
1648 printf(" reading\n");
1650 #if defined(ENABLE_SUSEREPO) && defined(PRODUCTS_PATH)
1651 repo_add_products(repo, PRODUCTS_PATH, 0, REPO_NO_INTERNALIZE);
1653 #if defined(ENABLE_RPMDB) && !defined(DEBIAN)
1654 if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
1656 Repo *ref = repo_create(pool, "@System.old");
1657 if (!repo_add_solv(ref, ofp, 0))
1659 repo_add_rpmdb(repo, ref, 0, REPO_REUSE_REPODATA);
1666 repo_add_rpmdb(repo, 0, 0, REPO_REUSE_REPODATA);
1668 # if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1669 repo_add_debdb(repo, 0, REPO_REUSE_REPODATA);
1672 writecachedrepo(repo, 0, 0, installedcookie);
1674 pool_set_installed(pool, repo);
1676 for (i = 0; i < nrepoinfos; i++)
1678 cinfo = repoinfos + i;
1679 if (!cinfo->enabled)
1682 repo = repo_create(pool, cinfo->alias);
1684 repo->appdata = cinfo;
1685 repo->priority = 99 - cinfo->priority;
1687 dorefresh = cinfo->autorefresh;
1688 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0), &stb) == 0)
1690 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1693 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1695 printf("repo '%s':", cinfo->alias);
1696 printf(" cached\n");
1700 switch (cinfo->type)
1704 printf("rpmmd repo '%s':", cinfo->alias);
1706 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1708 printf(" no repomd.xml file, skipped\n");
1713 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1714 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1716 printf(" cached\n");
1720 if (cinfo->repo_gpgcheck)
1722 sigfp = curlfopen(cinfo, "repodata/repomd.xml.asc", 0, 0, 0, 0);
1725 printf(" unsigned, skipped\n");
1730 sigpool = read_sigs();
1731 if (!checksig(sigpool, fp, sigfp))
1733 printf(" checksig failed, skipped\n");
1740 repo_add_repomdxml(repo, fp, 0);
1742 printf(" fetching\n");
1743 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1744 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1746 repo_add_rpmmd(repo, fp, 0, 0);
1750 break; /* hopeless */
1752 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1753 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1755 repo_add_updateinfoxml(repo, fp, 0);
1759 data = repo_add_repodata(repo, 0);
1760 if (!repomd_add_ext(repo, data, "deltainfo"))
1761 repomd_add_ext(repo, data, "prestodelta");
1762 repomd_add_ext(repo, data, "filelists");
1763 repodata_internalize(data);
1765 writecachedrepo(repo, 0, 0, cinfo->cookie);
1766 repodata_create_stubs(repo_last_repodata(repo));
1770 #ifdef ENABLE_SUSEREPO
1772 printf("susetags repo '%s':", cinfo->alias);
1776 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1778 printf(" no content file, skipped\n");
1783 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1784 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1786 printf(" cached\n");
1790 if (cinfo->repo_gpgcheck)
1792 sigfp = curlfopen(cinfo, "content.asc", 0, 0, 0, 0);
1795 printf(" unsigned, skipped\n");
1802 sigpool = read_sigs();
1803 if (!checksig(sigpool, fp, sigfp))
1805 printf(" checksig failed, skipped\n");
1813 repo_add_content(repo, fp, 0);
1815 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1816 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1818 descrdir = "suse/setup/descr";
1819 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1821 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1824 printf(" no packages file entry, skipped\n");
1827 printf(" fetching\n");
1828 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) == 0)
1829 break; /* hopeless */
1830 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES);
1832 /* add default language */
1833 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1835 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1838 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1840 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES);
1844 filename = susetags_find(repo, "patterns", &filechksum, &filechksumtype);
1847 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1850 while (fgets(pbuf, sizeof(pbuf), fp))
1852 int l = strlen(pbuf);
1854 if (l && pbuf[l - 1] == '\n')
1856 if (!*pbuf || *pbuf == '.' || strchr(pbuf, '/') != 0)
1858 filename = susetags_find(repo, pbuf, &filechksum, &filechksumtype);
1859 if (filename && (fp2 = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1861 repo_add_susetags(repo, fp2, defvendor, 0, REPO_NO_INTERNALIZE);
1868 repo_internalize(repo);
1869 data = repo_add_repodata(repo, 0);
1870 susetags_add_ext(repo, data);
1871 repodata_internalize(data);
1873 writecachedrepo(repo, 0, 0, cinfo->cookie);
1874 repodata_create_stubs(repo_last_repodata(repo));
1878 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1880 printf("debian repo '%s':", cinfo->alias);
1882 filename = solv_dupjoin("dists/", cinfo->name, "/Release");
1883 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
1885 printf(" no Release file, skipped\n");
1888 free((char *)filename);
1891 solv_free((char *)filename);
1892 if (cinfo->repo_gpgcheck)
1894 filename = solv_dupjoin("dists/", cinfo->name, "/Release.gpg");
1895 sigfp = curlfopen(cinfo, filename, 0, 0, 0, 0);
1896 solv_free((char *)filename);
1899 printf(" unsigned, skipped\n");
1904 sigpool = read_sigs();
1905 if (!checksig(sigpool, fpr, sigfp))
1907 printf(" checksig failed, skipped\n");
1914 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
1915 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1917 printf(" cached\n");
1921 printf(" fetching\n");
1922 for (j = 0; j < cinfo->ncomponents; j++)
1924 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
1926 printf("[component %s not found]\n", cinfo->components[j]);
1929 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1931 repo_add_debpackages(repo, fp, 0);
1934 solv_free((char *)filechksum);
1935 solv_free((char *)filename);
1939 writecachedrepo(repo, 0, 0, cinfo->cookie);
1944 printf("unsupported repo '%s': skipped\n", cinfo->alias);
1956 str2archid(Pool *pool, char *arch)
1961 id = pool_str2id(pool, arch, 0);
1962 if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH)
1964 if (pool->id2arch && (id > pool->lastarch || !pool->id2arch[id]))
1970 #define DEPGLOB_NAME 1
1971 #define DEPGLOB_DEP 2
1972 #define DEPGLOB_NAMEDEP 3
1975 depglob(Pool *pool, char *name, Queue *job, int what)
1978 Id id = pool_str2id(pool, name, 0);
1983 FOR_PROVIDES(p, pp, id)
1985 Solvable *s = pool->solvables + p;
1987 if (s->name == id && (what & DEPGLOB_NAME) != 0)
1989 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
1995 if (what == DEPGLOB_NAMEDEP)
1996 printf("[using capability match for '%s']\n", name);
1997 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
2002 if (strpbrk(name, "[*?") == 0)
2005 if ((what & DEPGLOB_NAME) != 0)
2007 /* looks like a name glob. hard work. */
2008 for (p = 1; p < pool->nsolvables; p++)
2010 Solvable *s = pool->solvables + p;
2011 if (!s->repo || !pool_installable(pool, s))
2014 if (fnmatch(name, pool_id2str(pool, id), 0) == 0)
2016 for (i = 0; i < job->count; i += 2)
2017 if (job->elements[i] == SOLVER_SOLVABLE_NAME && job->elements[i + 1] == id)
2019 if (i == job->count)
2020 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
2027 if ((what & DEPGLOB_DEP))
2029 /* looks like a dep glob. really hard work. */
2030 for (id = 1; id < pool->ss.nstrings; id++)
2032 if (!pool->whatprovides[id])
2034 if (fnmatch(name, pool_id2str(pool, id), 0) == 0)
2036 if (!match && what == DEPGLOB_NAMEDEP)
2037 printf("[using capability match for '%s']\n", name);
2038 for (i = 0; i < job->count; i += 2)
2039 if (job->elements[i] == SOLVER_SOLVABLE_PROVIDES && job->elements[i + 1] == id)
2041 if (i == job->count)
2042 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
2053 limitrelation(Pool *pool, Queue *job, int flags, Id evr)
2057 for (i = j = 0; i < job->count; i += 2)
2059 Id select = job->elements[i] & SOLVER_SELECTMASK;
2060 if (select != SOLVER_SOLVABLE_NAME && select != SOLVER_SOLVABLE_PROVIDES)
2062 fprintf(stderr, "limitrelation only works on name/provides jobs\n");
2065 job->elements[i + 1] = pool_rel2id(pool, job->elements[i + 1], evr, flags, 1);
2066 if (flags == REL_ARCH)
2067 job->elements[i] |= SOLVER_SETARCH;
2068 if (flags == REL_EQ && select == SOLVER_SOLVABLE_NAME && job->elements[i])
2071 const char *evrstr = pool_id2str(pool, evr);
2072 if (!strchr(evrstr, '-'))
2073 job->elements[i] |= SOLVER_SETEV;
2076 job->elements[i] |= SOLVER_SETEVR;
2078 /* make sure we still have matches */
2079 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2083 job->elements[j] = job->elements[i];
2084 job->elements[j + 1] = job->elements[i + 1];
2088 queue_truncate(job, j);
2093 limitrelation_arch(Pool *pool, Queue *job, int flags, char *evr)
2097 if ((r = strrchr(evr, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2100 limitrelation(pool, job, REL_ARCH, archid);
2101 limitrelation(pool, job, flags, pool_str2id(pool, evr, 1));
2105 limitrelation(pool, job, flags, pool_str2id(pool, evr, 1));
2106 return job->count / 2;
2110 limitrepo(Pool *pool, Id repofilter, Queue *job)
2118 for (i = j = 0; i < job->count; i += 2)
2121 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2123 s = pool_id2solvable(pool, p);
2124 if (s->repo && s->repo->repoid == repofilter)
2129 /* here we assume that repo == vendor, so we also set SOLVER_SETVENDOR */
2130 Id flags = (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO;
2131 if ((job->elements[i] & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_NAME)
2132 flags |= SOLVER_SETNAME;
2135 job->elements[j] = SOLVER_SOLVABLE | SOLVER_NOAUTOSET | flags;
2136 job->elements[j + 1] = mq.elements[0];
2140 job->elements[j] = SOLVER_SOLVABLE_ONE_OF | flags;
2141 job->elements[j + 1] = pool_queuetowhatprovides(pool, &mq);
2146 queue_truncate(job, j);
2152 mkselect(Pool *pool, int mode, char *name, Queue *job)
2160 int type = strpbrk(name, "[*?") == 0 ? SEARCH_STRING : SEARCH_GLOB;
2163 dataiterator_init(&di, pool, mode == SOLVER_ERASE ? pool->installed : 0, 0, SOLVABLE_FILELIST, name, type|SEARCH_FILES|SEARCH_COMPLETE_FILELIST);
2164 while (dataiterator_step(&di))
2166 Solvable *s = pool->solvables + di.solvid;
2167 if (!s->repo || !pool_installable(pool, s))
2169 queue_push(&q, di.solvid);
2170 dataiterator_skip_solvable(&di);
2172 dataiterator_free(&di);
2175 printf("[using file list match for '%s']\n", name);
2177 queue_push2(job, SOLVER_SOLVABLE_ONE_OF, pool_queuetowhatprovides(pool, &q));
2179 queue_push2(job, SOLVER_SOLVABLE | SOLVER_NOAUTOSET, q.elements[0]);
2181 return job->count / 2;
2184 if ((r = strpbrk(name, "<=>")) != 0)
2186 /* relation case, support:
2191 int nend = r - name;
2204 while (*r && *r == ' ' && *r == '\t')
2206 while (nend && (name[nend - 1] == ' ' || name[nend -1 ] == '\t'))
2210 fprintf(stderr, "bad relation\n");
2213 oldnend = name[nend];
2215 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2217 name[nend] = oldnend;
2218 limitrelation(pool, job, rflags, pool_str2id(pool, r, 1));
2219 return job->count / 2;
2221 if ((r2 = strrchr(name, '.')) != 0 && r2[1] && (archid = str2archid(pool, r2 + 1)) != 0)
2224 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2226 name[nend] = oldnend;
2228 limitrelation(pool, job, REL_ARCH, archid);
2229 limitrelation(pool, job, rflags, pool_str2id(pool, r, 1));
2230 return job->count / 2;
2234 name[nend] = oldnend;
2238 /* no relation case, support:
2242 * nameglob-version.arch
2243 * nameglob-version-release
2244 * nameglob-version-release.arch
2246 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2247 return job->count / 2;
2248 if ((r = strrchr(name, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2251 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2254 limitrelation(pool, job, REL_ARCH, archid);
2255 return job->count / 2;
2259 if ((r = strrchr(name, '-')) != 0)
2262 if (depglob(pool, name, job, DEPGLOB_NAME))
2264 /* have just the version */
2265 limitrelation_arch(pool, job, REL_EQ, r + 1);
2267 return job->count / 2;
2269 if ((r2 = strrchr(name, '-')) != 0)
2274 if (depglob(pool, name, job, DEPGLOB_NAME))
2276 /* have version-release */
2277 limitrelation_arch(pool, job, REL_EQ, r + 1);
2279 return job->count / 2;
2290 yesno(const char *str)
2292 char inbuf[128], *ip;
2299 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2304 while (*ip == ' ' || *ip == '\t')
2311 if (*ip == 'y' || *ip == 'n')
2312 return *ip == 'y' ? 1 : 0;
2316 #if defined(ENABLE_RPMDB) && !defined(DEBIAN)
2326 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2328 struct fcstate *fcstate = cbdata;
2336 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
2339 s = pool_id2solvable(pool, p);
2340 if (pool->installed && s->repo == pool->installed)
2342 if (!s->repo->rpmdbid)
2344 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2347 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
2349 for (i = 0; i < fcstate->newpkgscnt; i++)
2350 if (fcstate->checkq->elements[i] == p)
2352 if (i == fcstate->newpkgscnt)
2354 fp = fcstate->newpkgsfps[i];
2358 return rpm_byfp(fp, pool_solvable2str(pool, s), &fcstate->rpmdbstate);
2363 runrpm(const char *arg, const char *name, int dupfd3)
2368 if ((pid = fork()) == (pid_t)-1)
2375 if (dupfd3 != -1 && dupfd3 != 3)
2381 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2382 if (strcmp(arg, "-e") == 0)
2383 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2385 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2389 while (waitpid(pid, &status, 0) != pid)
2393 printf("rpm failed\n");
2400 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2403 rundpkg(const char *arg, const char *name, int dupfd3)
2408 if ((pid = fork()) == (pid_t)-1)
2415 if (dupfd3 != -1 && dupfd3 != 3)
2421 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2422 if (strcmp(arg, "--install") == 0)
2423 execlp("dpkg", "dpkg", "--install", "--force", "all", name, (char *)0);
2425 execlp("dpkg", "dpkg", "--remove", "--force", "all", name, (char *)0);
2429 while (waitpid(pid, &status, 0) != pid)
2433 printf("dpkg failed\n");
2441 nscallback(Pool *pool, void *data, Id name, Id evr)
2443 if (name == NAMESPACE_PRODUCTBUDDY)
2445 /* SUSE specific hack: each product has an associated rpm */
2446 Solvable *s = pool->solvables + evr;
2450 cap = pool_str2id(pool, pool_tmpjoin(pool, "product(", pool_id2str(pool, s->name) + 8, ")"), 0);
2453 cap = pool_rel2id(pool, cap, s->evr, REL_EQ, 0);
2456 FOR_PROVIDES(p, pp, cap)
2458 Solvable *ps = pool->solvables + p;
2459 if (ps->repo == s->repo && ps->arch == s->arch)
2460 if (!bestp || pool_evrcmp(pool, pool->solvables[bestp].evr, ps->evr, EVRCMP_COMPARE) < 0)
2468 #ifdef SOFTLOCKS_PATH
2471 addsoftlocks(Pool *pool, Queue *job)
2475 char *bp, *ep, buf[4096];
2477 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2479 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2481 while (*bp == ' ' || *bp == '\t')
2483 if (!*bp || *bp == '#')
2485 for (ep = bp; *ep; ep++)
2486 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2489 type = SOLVER_SOLVABLE_NAME;
2490 if (!strncmp(bp, "provides:", 9) && bp[9])
2492 type = SOLVER_SOLVABLE_PROVIDES;
2495 id = pool_str2id(pool, bp, 1);
2496 if (pool->installed)
2498 FOR_JOB_SELECT(p, pp, type, id)
2499 if (pool->solvables[p].repo == pool->installed)
2502 continue; /* ignore, as it is already installed */
2504 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2513 rewrite_repos(Pool *pool, Queue *addedfileprovides, Queue *addedfileprovides_inst)
2518 Queue fileprovidesq;
2520 struct repoinfo *cinfo;
2522 map_init(&providedids, pool->ss.nstrings);
2523 queue_init(&fileprovidesq);
2524 for (i = 0; i < addedfileprovides->count; i++)
2525 MAPSET(&providedids, addedfileprovides->elements[i]);
2528 /* make sure all repodatas but the first are extensions */
2529 if (repo->nrepodata < 2)
2531 data = repo_id2repodata(repo, 1);
2532 if (data->loadcallback)
2534 for (j = 2; j < repo->nrepodata; j++)
2536 Repodata *edata = repo_id2repodata(repo, j);
2537 if (!edata->loadcallback)
2540 if (j < repo->nrepodata)
2541 continue; /* found a non-externsion repodata, can't rewrite */
2542 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2544 if (repo == pool->installed && addedfileprovides_inst)
2546 for (j = 0; j < addedfileprovides->count; j++)
2547 MAPCLR(&providedids, addedfileprovides->elements[j]);
2548 for (j = 0; j < addedfileprovides_inst->count; j++)
2549 MAPSET(&providedids, addedfileprovides_inst->elements[j]);
2552 for (j = 0; j < fileprovidesq.count; j++)
2553 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2555 if (repo == pool->installed && addedfileprovides_inst)
2557 for (j = 0; j < addedfileprovides_inst->count; j++)
2558 MAPCLR(&providedids, addedfileprovides_inst->elements[j]);
2559 for (j = 0; j < addedfileprovides->count; j++)
2560 MAPSET(&providedids, addedfileprovides->elements[j]);
2561 if (n == addedfileprovides_inst->count)
2562 continue; /* nothing new added */
2564 else if (n == addedfileprovides->count)
2565 continue; /* nothing new added */
2567 repodata_set_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, repo == pool->installed && addedfileprovides_inst ? addedfileprovides_inst : addedfileprovides);
2568 repodata_internalize(data);
2569 cinfo = repo->appdata;
2570 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2572 queue_free(&fileprovidesq);
2573 map_free(&providedids);
2577 select_patches(Pool *pool, Queue *job)
2581 Map installedmap, noobsmap;
2584 map_init(&noobsmap, 0);
2585 map_init(&installedmap, pool->nsolvables);
2586 solver_calculate_noobsmap(pool, job, &noobsmap);
2587 if (pool->installed)
2588 FOR_REPO_SOLVABLES(pool->installed, p, s)
2589 MAPSET(&installedmap, p);
2591 /* install all patches */
2592 for (p = 1; p < pool->nsolvables; p++)
2598 s = pool->solvables + p;
2599 if (strncmp(pool_id2str(pool, s->name), "patch:", 6) != 0)
2601 FOR_PROVIDES(p2, pp, s->name)
2603 Solvable *s2 = pool->solvables + p2;
2604 if (s2->name != s->name)
2606 r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2607 if (r < 0 || (r == 0 && p > p2))
2612 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2613 if (type && !strcmp(type, "optional"))
2615 r = solvable_trivial_installable_map(s, &installedmap, 0, &noobsmap);
2618 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2625 queue_push2(job, SOLVER_SOLVABLE, p);
2627 map_free(&installedmap);
2628 map_free(&noobsmap);
2632 #define MODE_INSTALL 1
2633 #define MODE_ERASE 2
2634 #define MODE_UPDATE 3
2635 #define MODE_DISTUPGRADE 4
2636 #define MODE_VERIFY 5
2637 #define MODE_PATCH 6
2639 #define MODE_REPOLIST 8
2640 #define MODE_SEARCH 9
2645 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2646 fprintf(stderr, "\n");
2647 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2648 fprintf(stderr, " versions from the repositories\n");
2649 fprintf(stderr, " erase: erase installed packages\n");
2650 fprintf(stderr, " info: display package information\n");
2651 fprintf(stderr, " install: install packages\n");
2652 fprintf(stderr, " list: list packages\n");
2653 fprintf(stderr, " repos: list enabled repositories\n");
2654 fprintf(stderr, " search: search name/summary/description\n");
2655 fprintf(stderr, " update: update installed packages\n");
2656 fprintf(stderr, " verify: check dependencies of installed packages\n");
2657 fprintf(stderr, "\n");
2662 main(int argc, char **argv)
2665 Repo *commandlinerepo = 0;
2666 Id *commandlinepkgs = 0;
2668 struct repoinfo *repoinfos;
2670 int mainmode = 0, mode = 0;
2675 char inbuf[128], *ip;
2678 Queue addedfileprovides;
2679 Queue addedfileprovides_inst;
2687 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2689 mainmode = MODE_INSTALL;
2690 mode = SOLVER_INSTALL;
2692 else if (!strcmp(argv[0], "patch"))
2694 mainmode = MODE_PATCH;
2695 mode = SOLVER_INSTALL;
2697 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2699 mainmode = MODE_ERASE;
2700 mode = SOLVER_ERASE;
2702 else if (!strcmp(argv[0], "list"))
2704 mainmode = MODE_LIST;
2707 else if (!strcmp(argv[0], "info"))
2709 mainmode = MODE_INFO;
2712 else if (!strcmp(argv[0], "search"))
2714 mainmode = MODE_SEARCH;
2717 else if (!strcmp(argv[0], "verify"))
2719 mainmode = MODE_VERIFY;
2720 mode = SOLVER_VERIFY;
2722 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2724 mainmode = MODE_UPDATE;
2725 mode = SOLVER_UPDATE;
2727 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2729 mainmode = MODE_DISTUPGRADE;
2730 mode = SOLVER_UPDATE;
2732 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2734 mainmode = MODE_REPOLIST;
2740 if (argc > 1 && !strcmp(argv[1], "--clean"))
2747 pool = pool_create();
2751 const char *langs[] = {"de_DE", "de", "en"};
2752 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2756 pool_setloadcallback(pool, load_stub, 0);
2757 pool->nscallback = nscallback;
2758 // pool_setdebuglevel(pool, 2);
2760 repoinfos = read_repoinfos(pool, REPOINFO_PATH, &nrepoinfos);
2762 if (mainmode == MODE_REPOLIST)
2765 for (i = 0; i < nrepoinfos; i++)
2767 struct repoinfo *cinfo = repoinfos + i;
2768 if (!cinfo->enabled)
2770 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2775 read_repos(pool, repoinfos, nrepoinfos);
2777 if (argc > 2 && !strcmp(argv[1], "-r"))
2779 const char *rname = argv[2], *rp;
2780 for (rp = rname; *rp; rp++)
2781 if (*rp <= '0' || *rp >= '9')
2785 /* repo specified by number */
2786 int rnum = atoi(rname);
2787 for (i = 0; i < nrepoinfos; i++)
2789 struct repoinfo *cinfo = repoinfos + i;
2790 if (!cinfo->enabled)
2793 repofilter = cinfo->repo->repoid;
2798 /* repo specified by alias */
2802 if (!strcasecmp(rname, repo->name))
2803 repofilter = repo->repoid;
2808 fprintf(stderr, "%s: no such repo\n", rname);
2814 if (mainmode == MODE_SEARCH)
2820 map_init(&m, pool->nsolvables);
2821 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2822 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2823 dataiterator_set_search(&di, 0, 0);
2824 while (dataiterator_step(&di))
2825 MAPSET(&m, di.solvid);
2826 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2827 dataiterator_set_search(&di, 0, 0);
2828 while (dataiterator_step(&di))
2829 MAPSET(&m, di.solvid);
2830 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2831 dataiterator_set_search(&di, 0, 0);
2832 while (dataiterator_step(&di))
2833 MAPSET(&m, di.solvid);
2834 dataiterator_free(&di);
2836 for (p = 1; p < pool->nsolvables; p++)
2838 Solvable *s = pool_id2solvable(pool, p);
2841 printf(" - %s: %s\n", pool_solvable2str(pool, s), solvable_lookup_str(s, SOLVABLE_SUMMARY));
2848 if (mainmode == MODE_LIST || mainmode == MODE_INSTALL)
2850 for (i = 1; i < argc; i++)
2853 l = strlen(argv[i]);
2855 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2858 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2861 if (access(argv[i], R_OK))
2866 if (!commandlinepkgs)
2867 commandlinepkgs = solv_calloc(argc, sizeof(Id));
2868 if (!commandlinerepo)
2869 commandlinerepo = repo_create(pool, "@commandline");
2871 #if defined(ENABLE_RPMDB) && !defined(DEBIAN)
2872 p = repo_add_rpm(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2874 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2875 p = repo_add_deb(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2879 fprintf(stderr, "could not add '%s'\n", argv[i]);
2882 commandlinepkgs[i] = p;
2884 if (commandlinerepo)
2885 repo_internalize(commandlinerepo);
2888 // FOR_REPOS(i, repo)
2889 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2890 queue_init(&addedfileprovides);
2891 queue_init(&addedfileprovides_inst);
2892 pool_addfileprovides_queue(pool, &addedfileprovides, &addedfileprovides_inst);
2893 if (addedfileprovides.count || addedfileprovides_inst.count)
2894 rewrite_repos(pool, &addedfileprovides, &addedfileprovides_inst);
2895 queue_free(&addedfileprovides);
2896 queue_free(&addedfileprovides_inst);
2897 pool_createwhatprovides(pool);
2900 for (i = 1; i < argc; i++)
2905 if (commandlinepkgs && commandlinepkgs[i])
2907 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2911 if (!mkselect(pool, mode, argv[i], &job2))
2913 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2916 if (repofilter && !limitrepo(pool, repofilter, &job2))
2918 fprintf(stderr, "nothing in repo matches '%s'\n", argv[i]);
2921 for (j = 0; j < job2.count; j++)
2922 queue_push(&job, job2.elements[j]);
2926 if (!job.count && mainmode != MODE_UPDATE && mainmode != MODE_DISTUPGRADE && mainmode != MODE_VERIFY && mainmode != MODE_PATCH)
2928 printf("no package matched\n");
2935 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
2937 /* list mode, no solver needed */
2938 for (i = 0; i < job.count; i += 2)
2940 Id how = job.elements[i] & SOLVER_SELECTMASK;
2941 FOR_JOB_SELECT(p, pp, how, job.elements[i + 1])
2943 Solvable *s = pool_id2solvable(pool, p);
2944 if (mainmode == MODE_INFO)
2947 printf("Name: %s\n", pool_solvable2str(pool, s));
2948 printf("Repo: %s\n", s->repo->name);
2949 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
2950 str = solvable_lookup_str(s, SOLVABLE_URL);
2952 printf("Url: %s\n", str);
2953 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
2955 printf("License: %s\n", str);
2956 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
2962 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
2964 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
2966 printf(" - %s [%s]\n", pool_solvable2str(pool, s), s->repo->name);
2968 printf(" %s\n", sum);
2974 free_repoinfos(repoinfos, nrepoinfos);
2975 solv_free(commandlinepkgs);
2977 yum_substitute(pool, 0);
2982 if (mainmode == MODE_PATCH)
2983 select_patches(pool, &job);
2986 for (i = 0; i < job.count; i += 2)
2988 if (mode == SOLVER_UPDATE)
2990 /* make update of not installed packages an install */
2991 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
2992 if (pool->installed && pool->solvables[p].repo == pool->installed)
2996 job.elements[i] |= SOLVER_INSTALL;
2998 job.elements[i] |= SOLVER_CLEANDEPS;
3002 job.elements[i] |= mode;
3004 job.elements[i] |= SOLVER_CLEANDEPS;
3007 if (mainmode == MODE_DISTUPGRADE && allpkgs)
3010 queue_push2(&job, SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_REPO, repofilter);
3012 queue_push2(&job, SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL, 0);
3014 if (mainmode == MODE_UPDATE && allpkgs)
3017 queue_push2(&job, SOLVER_UPDATE|SOLVER_SOLVABLE_REPO, repofilter);
3019 queue_push2(&job, SOLVER_UPDATE|SOLVER_SOLVABLE_ALL, 0);
3021 if (mainmode == MODE_VERIFY && allpkgs)
3024 queue_push2(&job, SOLVER_VERIFY|SOLVER_SOLVABLE_REPO, repofilter);
3026 queue_push2(&job, SOLVER_VERIFY|SOLVER_SOLVABLE_ALL, 0);
3029 // multiversion test
3030 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae", 1));
3031 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-base", 1));
3032 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-extra", 1));
3034 #ifdef SOFTLOCKS_PATH
3035 addsoftlocks(pool, &job);
3038 #if defined(ENABLE_RPMDB) && !defined(DEBIAN)
3043 Id problem, solution;
3046 solv = solver_create(pool);
3047 solver_set_flag(solv, SOLVER_FLAG_SPLITPROVIDES, 1);
3048 if (mainmode == MODE_ERASE)
3049 solver_set_flag(solv, SOLVER_FLAG_ALLOW_UNINSTALL, 1); /* don't nag */
3051 if (!solver_solve(solv, &job))
3053 pcnt = solver_problem_count(solv);
3054 printf("Found %d problems:\n", pcnt);
3055 for (problem = 1; problem <= pcnt; problem++)
3058 printf("Problem %d:\n", problem);
3059 solver_printprobleminfo(solv, problem);
3061 scnt = solver_solution_count(solv, problem);
3062 for (solution = 1; solution <= scnt; solution++)
3064 printf("Solution %d:\n", solution);
3065 solver_printsolution(solv, problem, solution);
3070 printf("Please choose a solution: ");
3073 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
3078 while (*ip == ' ' || *ip == '\t')
3080 if (*ip >= '0' && *ip <= '9')
3083 if (take >= 1 && take <= scnt)
3099 solver_take_solution(solv, problem, take, &job);
3105 trans = solver_create_transaction(solv);
3106 if (!trans->steps.count)
3108 printf("Nothing to do.\n");
3109 transaction_free(trans);
3113 free_repoinfos(repoinfos, nrepoinfos);
3114 solv_free(commandlinepkgs);
3116 yum_substitute(pool, 0);
3121 printf("Transaction summary:\n\n");
3122 transaction_print(trans);
3124 #if !defined(FEDORA) && !defined(DEBIAN)
3131 duc[1].path = "/usr/share/man";
3132 duc[2].path = "/sbin";
3133 duc[3].path = "/etc";
3134 transaction_calc_duchanges(trans, duc, 4);
3135 for (i = 0; i < 4; i++)
3136 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
3139 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
3142 if (!yesno("OK to continue (y/n)? "))
3145 transaction_free(trans);
3149 free_repoinfos(repoinfos, nrepoinfos);
3150 solv_free(commandlinepkgs);
3152 yum_substitute(pool, 0);
3157 queue_init(&checkq);
3158 newpkgs = transaction_installedresult(trans, &checkq);
3163 int downloadsize = 0;
3164 for (i = 0; i < newpkgs; i++)
3168 p = checkq.elements[i];
3169 s = pool_id2solvable(pool, p);
3170 downloadsize += solvable_lookup_sizek(s, SOLVABLE_DOWNLOADSIZE, 0);
3172 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
3173 newpkgsfps = solv_calloc(newpkgs, sizeof(*newpkgsfps));
3174 for (i = 0; i < newpkgs; i++)
3176 unsigned int medianr;
3179 struct repoinfo *cinfo;
3180 const unsigned char *chksum;
3184 p = checkq.elements[i];
3185 s = pool_id2solvable(pool, p);
3186 if (s->repo == commandlinerepo)
3188 loc = solvable_get_location(s, &medianr);
3189 if (!(newpkgsfps[i] = fopen(loc, "r")))
3197 cinfo = s->repo->appdata;
3200 printf("%s: no repository information\n", s->repo->name);
3203 loc = solvable_get_location(s, &medianr);
3207 if (pool->installed && pool->installed->nsolvables)
3209 /* try a delta first */
3210 char *matchname = strdup(pool_id2str(pool, s->name));
3211 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
3212 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
3213 while (dataiterator_step(&di))
3217 dataiterator_setpos_parent(&di);
3218 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
3219 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
3221 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
3222 FOR_PROVIDES(op, pp, s->name)
3224 Solvable *os = pool->solvables + op;
3225 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
3228 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
3230 /* base is installed, run sequence check */
3231 const char *seqname;
3236 const char *archstr;
3241 archstr = pool_id2str(pool, s->arch);
3242 if (strlen(archstr) > 10 || strchr(archstr, '\'') != 0)
3245 seqname = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME);
3246 seqevr = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR);
3247 seqnum = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM);
3248 seq = pool_tmpjoin(pool, seqname, "-", seqevr);
3249 seq = pool_tmpappend(pool, seq, "-", seqnum);
3250 if (strchr(seq, '\'') != 0)
3253 sprintf(cmd, "/usr/bin/applydeltarpm -a '%s' -c -s '", archstr);
3255 sprintf(cmd, "/usr/bin/applydeltarpm -c -s '");
3257 if (system(pool_tmpjoin(pool, cmd, seq, "'")) != 0)
3258 continue; /* didn't match */
3259 /* looks good, download delta */
3261 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
3263 continue; /* no way! */
3264 dloc = pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_DIR);
3265 dloc = pool_tmpappend(pool, dloc, "/", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_NAME));
3266 dloc = pool_tmpappend(pool, dloc, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_EVR));
3267 dloc = pool_tmpappend(pool, dloc, ".", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_SUFFIX));
3268 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
3270 /* got it, now reconstruct */
3271 newfd = opentmpfile();
3273 sprintf(cmd, "applydeltarpm -a '%s' /dev/fd/%d /dev/fd/%d", archstr, fileno(fp), newfd);
3275 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
3277 fcntl(fileno(fp), F_SETFD, 0);
3284 lseek(newfd, 0, SEEK_SET);
3286 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3287 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
3293 newpkgsfps[i] = fdopen(newfd, "r");
3298 dataiterator_free(&di);
3299 solv_free(matchname);
3306 continue; /* delta worked! */
3308 if (cinfo->type == TYPE_SUSETAGS)
3310 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3311 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3314 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3315 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3317 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3326 #if defined(ENABLE_RPMDB) && !defined(DEBIAN)
3330 struct fcstate fcstate;
3332 printf("Searching for file conflicts\n");
3333 queue_init(&conflicts);
3334 fcstate.rpmdbstate = 0;
3335 fcstate.newpkgscnt = newpkgs;
3336 fcstate.checkq = &checkq;
3337 fcstate.newpkgsfps = newpkgsfps;
3338 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fileconflict_cb, &fcstate);
3339 if (conflicts.count)
3342 for (i = 0; i < conflicts.count; i += 5)
3343 printf("file %s of package %s conflicts with package %s\n", pool_id2str(pool, conflicts.elements[i]), pool_solvid2str(pool, conflicts.elements[i + 1]), pool_solvid2str(pool, conflicts.elements[i + 3]));
3345 if (yesno("Re-run solver (y/n/q)? "))
3347 for (i = 0; i < newpkgs; i++)
3349 fclose(newpkgsfps[i]);
3350 newpkgsfps = solv_free(newpkgsfps);
3352 pool_add_fileconflicts_deps(pool, &conflicts);
3353 pool_createwhatprovides(pool); /* Hmm... */
3357 queue_free(&conflicts);
3361 printf("Committing transaction:\n\n");
3362 transaction_order(trans, 0);
3363 for (i = 0; i < trans->steps.count; i++)
3365 #if defined(ENABLE_RPMDB) && !defined(DEBIAN)
3366 const char *evr, *evrp, *nvra;
3372 p = trans->steps.elements[i];
3373 s = pool_id2solvable(pool, p);
3374 Id type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3377 case SOLVER_TRANSACTION_ERASE:
3378 printf("erase %s\n", pool_solvid2str(pool, p));
3379 #if defined(ENABLE_RPMDB) && !defined(DEBIAN)
3380 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3382 /* strip epoch from evr */
3383 evr = evrp = pool_id2str(pool, s->evr);
3384 while (*evrp >= '0' && *evrp <= '9')
3386 if (evrp > evr && evrp[0] == ':' && evrp[1])
3388 nvra = pool_tmpjoin(pool, pool_id2str(pool, s->name), "-", evr);
3389 nvra = pool_tmpappend(pool, nvra, ".", pool_id2str(pool, s->arch));
3390 runrpm("-e", nvra, -1); /* too bad that --querybynumber doesn't work */
3392 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3393 rundpkg("--remove", pool_id2str(pool, s->name), 0);
3396 case SOLVER_TRANSACTION_INSTALL:
3397 case SOLVER_TRANSACTION_MULTIINSTALL:
3398 printf("install %s\n", pool_solvid2str(pool, p));
3399 for (j = 0; j < newpkgs; j++)
3400 if (checkq.elements[j] == p)
3402 fp = j < newpkgs ? newpkgsfps[j] : 0;
3406 lseek(fileno(fp), 0, SEEK_SET);
3407 #if defined(ENABLE_RPMDB) && !defined(DEBIAN)
3408 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp));
3410 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3411 rundpkg("--install", "/dev/fd/3", fileno(fp));
3421 for (i = 0; i < newpkgs; i++)
3423 fclose(newpkgsfps[i]);
3424 solv_free(newpkgsfps);
3425 queue_free(&checkq);
3426 transaction_free(trans);
3430 free_repoinfos(repoinfos, nrepoinfos);
3431 solv_free(commandlinepkgs);
3433 yum_substitute(pool, 0);