2 * Copyright (c) 2009-2013, 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"
60 #include "selection.h"
62 #include "repo_write.h"
64 #include "repo_rpmdb.h"
65 #include "pool_fileconflicts.h"
71 #include "repo_rpmmd.h"
72 #include "repo_repomdxml.h"
73 #include "repo_updateinfoxml.h"
74 #include "repo_deltainfoxml.h"
76 #ifdef ENABLE_SUSEREPO
77 #include "repo_products.h"
78 #include "repo_susetags.h"
79 #include "repo_content.h"
81 #include "solv_xfopen.h"
84 # define REPOINFO_PATH "/etc/yum.repos.d"
87 # define REPOINFO_PATH "/etc/zypp/repos.d"
88 # define PRODUCTS_PATH "/etc/products.d"
89 # define SOFTLOCKS_PATH "/var/lib/zypp/SoftLocks"
92 #define SOLVCACHE_PATH "/var/cache/solv"
94 #define METADATA_EXPIRE (60 * 15)
116 unsigned char cookie[32];
117 unsigned char extcookie[32];
123 yum_substitute(Pool *pool, char *line)
126 static char *releaseevr;
127 static char *basearch;
131 solv_free(releaseevr);
138 while ((p2 = strchr(p, '$')) != 0)
140 if (!strncmp(p2, "$releasever", 11))
148 rpmstate = rpm_state_create(pool_get_rootdir(pool));
149 rpm_installedrpmdbids(rpmstate, "Providename", "redhat-release", &q);
154 handle = rpm_byrpmdbid(rpmstate, q.elements[0]);
155 releaseevr = handle ? rpm_query(handle, SOLVABLE_EVR) : 0;
156 if (releaseevr && (p = strchr(releaseevr, '-')) != 0)
159 rpm_state_free(rpmstate);
163 fprintf(stderr, "no installed package provides 'redhat-release', cannot determine $releasever\n");
168 p = pool_tmpjoin(pool, line, releaseevr, p2 + 11);
169 p2 = p + (p2 - line);
171 p = p2 + strlen(releaseevr);
174 if (!strncmp(p2, "$basearch", 9))
184 basearch = strdup(un.machine);
185 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
189 p = pool_tmpjoin(pool, line, basearch, p2 + 9);
190 p2 = p + (p2 - line);
192 p = p2 + strlen(basearch);
201 #define TYPE_UNKNOWN 0
202 #define TYPE_SUSETAGS 1
204 #define TYPE_PLAINDIR 3
205 #define TYPE_DEBIAN 4
209 read_repoinfos_sort(const void *ap, const void *bp)
211 const struct repoinfo *a = ap;
212 const struct repoinfo *b = bp;
213 return strcmp(a->alias, b->alias);
217 #if defined(SUSE) || defined(FEDORA)
220 read_repoinfos(Pool *pool, int *nrepoinfosp)
222 const char *reposdir = REPOINFO_PATH;
224 char buf2[4096], *kp, *vp, *kpe;
229 struct repoinfo *repoinfos = 0, *cinfo;
232 rdlen = strlen(reposdir);
233 dir = opendir(reposdir);
239 while ((ent = readdir(dir)) != 0)
241 if (ent->d_name[0] == '.')
243 l = strlen(ent->d_name);
244 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
246 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
247 if ((fp = fopen(buf, "r")) == 0)
253 while(fgets(buf2, sizeof(buf2), fp))
258 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
261 while (*kp == ' ' || *kp == '\t')
263 if (!*kp || *kp == '#')
267 kp = yum_substitute(pool, kp);
271 vp = strrchr(kp, ']');
275 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
276 cinfo = repoinfos + nrepoinfos++;
277 memset(cinfo, 0, sizeof(*cinfo));
278 cinfo->alias = strdup(kp + 1);
279 cinfo->type = TYPE_RPMMD;
280 cinfo->autorefresh = 1;
281 cinfo->priority = 99;
283 cinfo->repo_gpgcheck = 1;
285 cinfo->metadata_expire = METADATA_EXPIRE;
290 vp = strchr(kp, '=');
293 for (kpe = vp - 1; kpe >= kp; kpe--)
294 if (*kpe != ' ' && *kpe != '\t')
299 while (*vp == ' ' || *vp == '\t')
302 if (!strcmp(kp, "name"))
303 cinfo->name = strdup(vp);
304 else if (!strcmp(kp, "enabled"))
305 cinfo->enabled = *vp == '0' ? 0 : 1;
306 else if (!strcmp(kp, "autorefresh"))
307 cinfo->autorefresh = *vp == '0' ? 0 : 1;
308 else if (!strcmp(kp, "gpgcheck"))
309 cinfo->pkgs_gpgcheck = *vp == '0' ? 0 : 1;
310 else if (!strcmp(kp, "repo_gpgcheck"))
311 cinfo->repo_gpgcheck = *vp == '0' ? 0 : 1;
312 else if (!strcmp(kp, "baseurl"))
313 cinfo->baseurl = strdup(vp);
314 else if (!strcmp(kp, "mirrorlist"))
316 if (strstr(vp, "metalink"))
317 cinfo->metalink = strdup(vp);
319 cinfo->mirrorlist = strdup(vp);
321 else if (!strcmp(kp, "path"))
323 if (vp && strcmp(vp, "/") != 0)
324 cinfo->path = strdup(vp);
326 else if (!strcmp(kp, "type"))
328 if (!strcmp(vp, "yast2"))
329 cinfo->type = TYPE_SUSETAGS;
330 else if (!strcmp(vp, "rpm-md"))
331 cinfo->type = TYPE_RPMMD;
332 else if (!strcmp(vp, "plaindir"))
333 cinfo->type = TYPE_PLAINDIR;
335 cinfo->type = TYPE_UNKNOWN;
337 else if (!strcmp(kp, "priority"))
338 cinfo->priority = atoi(vp);
339 else if (!strcmp(kp, "keeppackages"))
340 cinfo->keeppackages = *vp == '0' ? 0 : 1;
346 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
347 *nrepoinfosp = nrepoinfos;
356 read_repoinfos(Pool *pool, int *nrepoinfosp)
362 char *kp, *url, *distro;
363 struct repoinfo *repoinfos = 0, *cinfo;
368 fp = fopen("/etc/apt/sources.list", "r");
375 dir = opendir("/etc/apt/sources.list.d");
379 if ((ent = readdir(dir)) == 0)
384 if (ent->d_name[0] == '.')
386 l = strlen(ent->d_name);
387 if (l < 5 || strcmp(ent->d_name + l - 5, ".list") != 0)
389 snprintf(buf, sizeof(buf), "%s/%s", "/etc/apt/sources.list.d", ent->d_name);
390 if (!(fp = fopen(buf, "r")))
393 while(fgets(buf2, sizeof(buf2), fp))
398 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
401 while (*kp == ' ' || *kp == '\t')
403 if (!*kp || *kp == '#')
405 if (strncmp(kp, "deb", 3) != 0)
408 if (*kp != ' ' && *kp != '\t')
410 while (*kp == ' ' || *kp == '\t')
415 while (*kp && *kp != ' ' && *kp != '\t')
419 while (*kp == ' ' || *kp == '\t')
424 while (*kp && *kp != ' ' && *kp != '\t')
428 while (*kp == ' ' || *kp == '\t')
432 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
433 cinfo = repoinfos + nrepoinfos++;
434 memset(cinfo, 0, sizeof(*cinfo));
435 cinfo->baseurl = strdup(url);
436 cinfo->alias = solv_dupjoin(url, "/", distro);
437 cinfo->name = strdup(distro);
438 cinfo->type = TYPE_DEBIAN;
440 cinfo->autorefresh = 1;
441 cinfo->repo_gpgcheck = 1;
442 cinfo->metadata_expire = METADATA_EXPIRE;
446 while (*kp == ' ' || *kp == '\t')
451 while (*kp && *kp != ' ' && *kp != '\t')
455 cinfo->components = solv_extend(cinfo->components, cinfo->ncomponents, 1, sizeof(*cinfo->components), 15);
456 cinfo->components[cinfo->ncomponents++] = strdup(compo);
462 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
463 *nrepoinfosp = nrepoinfos;
471 read_repoinfos(Pool *pool, int *nrepoinfosp)
480 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
483 for (i = 0; i < nrepoinfos; i++)
485 struct repoinfo *cinfo = repoinfos + i;
486 solv_free(cinfo->name);
487 solv_free(cinfo->alias);
488 solv_free(cinfo->path);
489 solv_free(cinfo->metalink);
490 solv_free(cinfo->mirrorlist);
491 solv_free(cinfo->baseurl);
492 for (j = 0; j < cinfo->ncomponents; j++)
493 solv_free(cinfo->components[j]);
494 solv_free(cinfo->components);
496 solv_free(repoinfos);
505 strcpy(tmpl, "/var/tmp/solvXXXXXX");
517 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
520 const unsigned char *sum;
524 h = solv_chksum_create(chksumtype);
527 printf("%s: unknown checksum type\n", file);
530 while ((l = read(fd, buf, sizeof(buf))) > 0)
531 solv_chksum_add(h, buf, l);
532 lseek(fd, 0, SEEK_SET);
534 sum = solv_chksum_get(h, &l);
535 if (memcmp(sum, chksum, l))
537 printf("%s: checksum mismatch\n", file);
538 solv_chksum_free(h, 0);
541 solv_chksum_free(h, 0);
546 findfastest(char **urls, int nurls)
553 struct addrinfo hints, *result;;
555 fds = solv_calloc(nurls, sizeof(*fds));
556 socks = solv_calloc(nurls, sizeof(*socks));
557 for (i = 0; i < nurls; i++)
560 p = strchr(urls[i], '/');
573 if ((p2 = strchr(p, '@')) != 0)
576 if (!strncmp("https:", urls[i], 6))
578 else if (!strncmp("ftp:", urls[i], 4))
580 if ((p2 = strrchr(p, ':')) != 0)
589 sprintf(portstr, "%d", port);
590 memset(&hints, 0, sizeof(struct addrinfo));
591 hints.ai_family = AF_UNSPEC;
592 hints.ai_socktype = SOCK_STREAM;
593 hints.ai_flags = AI_NUMERICSERV;
595 if (!getaddrinfo(p, portstr, &hints, &result))
597 socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
600 fcntl(socks[i], F_SETFL, O_NONBLOCK);
601 if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1)
603 if (errno != EINPROGRESS)
610 freeaddrinfo(result);
617 for (i = j = 0; i < nurls; i++)
621 fds[j].fd = socks[i];
622 fds[j].events = POLLOUT;
630 if (poll(fds, j, 10000) <= 0)
632 i = -1; /* something is wrong */
635 for (i = 0; i < j; i++)
636 if ((fds[i].revents & POLLOUT) != 0)
639 socklen_t soel = sizeof(int);
640 if (getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, &soe, &soel) == -1 || soe != 0)
642 /* connect failed, kill socket */
643 for (j = 0; j < nurls; j++)
644 if (socks[j] == fds[i].fd)
657 i = -1; /* something is wrong, no bit was set */
660 /* now i contains the fastest fd index */
663 for (j = 0; j < nurls; j++)
664 if (socks[j] == fds[i].fd)
668 char *url0 = urls[0];
673 for (i = j = 0; i < nurls; i++)
681 findmetalinkurl(FILE *fp, unsigned char *chksump, Id *chksumtypep)
683 char buf[4096], *bp, *ep;
690 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
692 while (*bp == ' ' || *bp == '\t')
694 if (chksumtypep && !*chksumtypep && !strncmp(bp, "<hash type=\"sha256\">", 20))
697 if (solv_hex2bin((const char **)&bp, chksump, 32) == 32)
698 *chksumtypep = REPOKEY_TYPE_SHA256;
701 if (strncmp(bp, "<url", 4))
703 bp = strchr(bp, '>');
707 ep = strstr(bp, "repodata/repomd.xml</url>");
711 if (strncmp(bp, "http", 4))
713 urls = solv_extend(urls, nurls, 1, sizeof(*urls), 15);
714 urls[nurls++] = strdup(bp);
719 findfastest(urls, nurls > 5 ? 5 : nurls);
722 for (i = 0; i < nurls; i++)
725 ep = strchr(bp, '/');
726 if ((ep = strchr(ep + 2, '/')) != 0)
729 printf("[using mirror %s]\n", bp);
738 findmirrorlisturl(FILE *fp)
740 char buf[4096], *bp, *ep;
745 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
747 while (*bp == ' ' || *bp == '\t')
749 if (!*bp || *bp == '#')
752 while (l > 0 && (bp[l - 1] == ' ' || bp[l - 1] == '\t' || bp[l - 1] == '\n'))
754 urls = solv_extend(urls, nurls, 1, sizeof(*urls), 15);
755 urls[nurls++] = strdup(bp);
760 findfastest(urls, nurls > 5 ? 5 : nurls);
763 for (i = 0; i < nurls; i++)
766 ep = strchr(bp, '/');
767 if ((ep = strchr(ep + 2, '/')) != 0)
770 printf("[using mirror %s]\n", bp);
779 iscompressed(const char *name)
781 return solv_xfopen_iscompressed(name) != 0;
785 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int markincomplete)
792 const char *baseurl = cinfo->baseurl;
796 if (!cinfo->metalink && !cinfo->mirrorlist)
798 if (file != cinfo->metalink && file != cinfo->mirrorlist)
800 unsigned char mlchksum[32];
802 fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
807 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
809 cinfo->baseurl = findmirrorlisturl(fp);
814 if (strchr(cinfo->baseurl, '$'))
816 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
817 free(cinfo->baseurl);
818 cinfo->baseurl = strdup(b);
821 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
823 chksumtype = mlchksumtype;
826 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, markincomplete);
828 snprintf(url, sizeof(url), "%s", file);
833 if (l && baseurl[l - 1] == '/')
834 snprintf(url, sizeof(url), "%s%s", baseurl, file);
836 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
839 // printf("url: %s\n", url);
840 if ((pid = fork()) == (pid_t)-1)
852 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
857 while (waitpid(pid, &status, 0) != pid)
859 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
865 lseek(fd, 0, SEEK_SET);
868 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
870 cinfo->incomplete = 1;
874 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
877 cinfo->incomplete = 1;
881 fcntl(fd, F_SETFD, FD_CLOEXEC);
884 if (solv_xfopen_iscompressed(file) < 0)
886 printf("%s: unsupported compression\n", file);
888 cinfo->incomplete = 1;
892 fp = solv_xfopen_fd(file, fd, "r");
895 fp = fdopen(fd, "r");
904 cleanupgpg(char *gpgdir)
907 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
909 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
911 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
913 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
915 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
921 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
930 off_t posfp, possigfp;
933 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
936 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
937 if (!(kfp = fopen(keysfile, "w")) )
943 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
947 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
948 if (!pubkey || !*pubkey)
950 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
952 if (fputc('\n', kfp) == EOF) /* Just in case... */
956 if (fclose(kfp) || !nkeys)
961 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
964 fprintf(stderr, "key import error\n");
969 posfp = lseek(fileno(fp), 0, SEEK_CUR);
970 lseek(fileno(fp), 0, SEEK_SET);
971 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
972 lseek(fileno(sigfp), 0, SEEK_SET);
973 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
974 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
975 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
977 lseek(fileno(sigfp), possigfp, SEEK_SET);
978 lseek(fileno(fp), posfp, SEEK_SET);
979 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
980 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
982 return r == 0 ? 1 : 0;
988 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
993 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));
994 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
995 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
997 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
998 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
999 return r == 0 ? 1 : 0;
1007 Pool *sigpool = pool_create();
1008 #if defined(ENABLE_RPMDB_PUBKEY)
1009 Repo *repo = repo_create(sigpool, "rpmdbkeys");
1010 repo_add_rpmdb_pubkeys(repo, 0);
1016 downloadchecksig(struct repoinfo *cinfo, FILE *fp, const char *sigurl, Pool **sigpool)
1019 sigfp = curlfopen(cinfo, sigurl, 0, 0, 0, 0);
1022 printf(" unsigned, skipped\n");
1026 *sigpool = read_sigs();
1027 if (!checksig(*sigpool, fp, sigfp))
1029 printf(" checksig failed, skipped\n");
1037 #define CHKSUM_IDENT "1.1"
1040 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
1043 void *h = solv_chksum_create(chktype);
1046 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1047 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
1048 solv_chksum_add(h, buf, l);
1050 solv_chksum_free(h, out);
1054 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *cookie, unsigned char *out)
1056 void *h = solv_chksum_create(chktype);
1057 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1059 solv_chksum_add(h, cookie, 32);
1060 solv_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
1061 solv_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
1062 solv_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
1063 solv_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
1064 solv_chksum_free(h, out);
1076 pool_setarch(pool, un.machine);
1080 calccachepath(Repo *repo, const char *repoext)
1082 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
1085 p = pool_tmpappend(repo->pool, p, "_", repoext);
1086 p = pool_tmpappend(repo->pool, p, ".solvx", 0);
1089 p = pool_tmpappend(repo->pool, p, ".solv", 0);
1090 q = p + strlen(SOLVCACHE_PATH) + 1;
1100 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1103 unsigned char mycookie[32];
1104 unsigned char myextcookie[32];
1105 struct repoinfo *cinfo;
1108 cinfo = repo->appdata;
1109 if (!(fp = fopen(calccachepath(repo, repoext), "r")))
1111 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1116 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1121 if (cinfo && !repoext)
1123 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1134 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1135 if (strcmp(repoext, "DL") != 0)
1136 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1139 if (repo_add_solv(repo, fp, flags))
1144 if (cinfo && !repoext)
1146 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1147 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1150 futimens(fileno(fp), 0); /* try to set modification time */
1156 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1161 struct repoinfo *cinfo;
1164 cinfo = repo->appdata;
1165 if (cinfo && cinfo->incomplete)
1167 mkdir(SOLVCACHE_PATH, 0755);
1168 /* use dupjoin instead of tmpjoin because tmpl must survive repo_write */
1169 tmpl = solv_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
1177 if (!(fp = fdopen(fd, "w")))
1186 for (i = repo->start; i < repo->end; i++)
1187 if (repo->pool->solvables[i].repo != repo)
1193 repo_write(repo, fp);
1195 repodata_write(info, fp);
1198 int oldnrepodata = repo->nrepodata;
1199 repo->nrepodata = oldnrepodata > 2 ? 2 : oldnrepodata; /* XXX: do this right */
1200 repo_write(repo, fp);
1201 repo->nrepodata = oldnrepodata;
1205 if (!repoext && cinfo)
1207 if (!cinfo->extcookie[0])
1209 /* create the ext cookie and append it */
1210 /* we just need some unique ID */
1212 if (!fstat(fileno(fp), &stb))
1213 memset(&stb, 0, sizeof(stb));
1214 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cookie, cinfo->extcookie);
1215 if (cinfo->extcookie[0] == 0)
1216 cinfo->extcookie[0] = 1;
1218 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1226 /* append our cookie describing the metadata state */
1227 if (fwrite(cookie, 32, 1, fp) != 1)
1242 /* switch to just saved repo to activate paging and save memory */
1243 FILE *fp = fopen(tmpl, "r");
1249 repo_empty(repo, 1);
1250 if (repo_add_solv(repo, fp, SOLV_ADD_NO_STUBS))
1252 /* oops, no way to recover from here */
1253 fprintf(stderr, "internal error\n");
1259 int flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1260 /* make sure repodata contains complete repo */
1261 /* (this is how repodata_write saves it) */
1262 repodata_extend_block(info, repo->start, repo->end - repo->start);
1263 info->state = REPODATA_LOADING;
1264 if (strcmp(repoext, "DL") != 0)
1265 flags |= REPO_LOCALPOOL;
1266 repo_add_solv(repo, fp, flags);
1267 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1272 if (!rename(tmpl, calccachepath(repo, repoext)))
1279 /* repomd helpers */
1281 static inline const char *
1282 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1284 Pool *pool = repo->pool;
1286 const char *filename;
1291 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1292 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1293 if (dataiterator_step(&di))
1295 dataiterator_setpos_parent(&di);
1296 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1297 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1299 dataiterator_free(&di);
1300 if (filename && !*chksumtypep)
1302 printf("no %s file checksum!\n", what);
1309 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1311 Id chksumtype, handle;
1312 const unsigned char *chksum;
1313 const char *filename;
1315 filename = repomd_find(repo, what, &chksum, &chksumtype);
1318 if (!strcmp(what, "prestodelta"))
1320 handle = repodata_new_handle(data);
1321 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1322 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1323 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1324 if (!strcmp(what, "deltainfo"))
1326 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1327 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1329 if (!strcmp(what, "filelists"))
1331 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1332 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1334 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1339 repomd_load_ext(Repo *repo, Repodata *data)
1341 const char *filename, *repomdtype;
1344 struct repoinfo *cinfo;
1345 const unsigned char *filechksum;
1349 cinfo = repo->appdata;
1350 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1353 if (!strcmp(repomdtype, "filelists"))
1355 else if (!strcmp(repomdtype, "deltainfo"))
1359 printf("[%s:%s", repo->name, ext);
1360 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1362 printf(" cached]\n"); fflush(stdout);
1365 printf(" fetching]\n"); fflush(stdout);
1366 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1368 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1369 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1371 if (!strcmp(ext, "FL"))
1372 r = repo_add_rpmmd(repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES|REPO_LOCALPOOL);
1373 else if (!strcmp(ext, "DL"))
1374 r = repo_add_deltainfoxml(repo, fp, REPO_USE_LOADING);
1378 printf("%s\n", pool_errstr(repo->pool));
1381 writecachedrepo(repo, data, ext, cinfo->extcookie);
1388 #ifdef ENABLE_SUSEREPO
1389 /* susetags helpers */
1391 static inline const char *
1392 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1394 Pool *pool = repo->pool;
1396 const char *filename;
1401 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
1402 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1403 if (dataiterator_step(&di))
1405 dataiterator_setpos_parent(&di);
1406 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
1409 dataiterator_free(&di);
1410 if (filename && !*chksumtypep)
1412 printf("no %s file checksum!\n", what);
1418 static Id susetags_langtags[] = {
1419 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
1420 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
1421 SOLVABLE_EULA, REPOKEY_TYPE_STR,
1422 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
1423 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
1424 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
1429 susetags_add_ext(Repo *repo, Repodata *data)
1431 Pool *pool = repo->pool;
1434 Id handle, filechksumtype;
1435 const unsigned char *filechksum;
1438 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
1439 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1440 while (dataiterator_step(&di))
1442 if (strncmp(di.kv.str, "packages.", 9) != 0)
1444 if (!strcmp(di.kv.str + 9, "gz"))
1446 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
1448 ext[0] = di.kv.str[9];
1449 ext[1] = di.kv.str[10];
1451 if (!strcmp(ext, "en"))
1453 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
1455 handle = repodata_new_handle(data);
1456 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
1458 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
1459 if (!strcmp(ext, "DU"))
1461 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
1462 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
1464 else if (!strcmp(ext, "FL"))
1466 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1467 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1471 for (i = 0; susetags_langtags[i]; i += 2)
1473 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
1474 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
1477 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1479 dataiterator_free(&di);
1483 susetags_load_ext(Repo *repo, Repodata *data)
1485 const char *filename, *descrdir;
1489 struct repoinfo *cinfo;
1490 const unsigned char *filechksum;
1494 cinfo = repo->appdata;
1495 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1499 ext[0] = filename[9];
1500 ext[1] = filename[10];
1502 printf("[%s:%s", repo->name, ext);
1503 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1505 printf(" cached]\n"); fflush(stdout);
1508 printf(" fetching]\n"); fflush(stdout);
1509 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1510 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1512 descrdir = "suse/setup/descr";
1514 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1515 if ((fp = curlfopen(cinfo, pool_tmpjoin(repo->pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1517 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1518 if (strcmp(ext, "DL") != 0)
1519 flags |= REPO_LOCALPOOL;
1520 if (repo_add_susetags(repo, fp, defvendor, ext, flags))
1523 printf("%s\n", pool_errstr(repo->pool));
1527 writecachedrepo(repo, data, ext, cinfo->extcookie);
1537 load_stub(Pool *pool, Repodata *data, void *dp)
1539 struct repoinfo *cinfo = data->repo->appdata;
1540 switch (cinfo->type)
1542 #ifdef ENABLE_SUSEREPO
1544 return susetags_load_ext(data->repo, data);
1548 return repomd_load_ext(data->repo, data);
1555 static unsigned char installedcookie[32];
1557 #ifdef ENABLE_DEBIAN
1560 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1564 unsigned char *chksum;
1569 static char *basearch;
1581 basearch = strdup(un.machine);
1582 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
1585 binarydir = solv_dupjoin("binary-", basearch, "/");
1586 lbinarydir = strlen(binarydir);
1587 compl = strlen(comp);
1591 chksum = solv_malloc(32);
1593 while(fgets(buf, sizeof(buf), fp))
1598 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1600 if (!strncasecmp(buf, "MD5Sum:", 7))
1602 curchksumtype = REPOKEY_TYPE_MD5;
1605 if (!strncasecmp(buf, "SHA1:", 5))
1607 curchksumtype = REPOKEY_TYPE_SHA1;
1610 if (!strncasecmp(buf, "SHA256:", 7))
1612 curchksumtype = REPOKEY_TYPE_SHA256;
1624 while (*bp && *bp != ' ' && *bp != '\t')
1629 while (*bp == ' ' || *bp == '\t')
1631 while (*bp && *bp != ' ' && *bp != '\t')
1635 while (*bp == ' ' || *bp == '\t')
1638 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1641 if (strncmp(bp, binarydir, lbinarydir))
1644 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1646 unsigned char curchksum[32];
1648 if (filename && !strcmp(bp, "Packages"))
1650 curl = solv_chksum_len(curchksumtype);
1651 if (!curl || (chksumtype && solv_chksum_len(chksumtype) > curl))
1653 if (solv_hex2bin((const char **)&ch, curchksum, sizeof(curchksum)) != curl)
1655 solv_free(filename);
1656 filename = strdup(fn);
1657 chksumtype = curchksumtype;
1658 memcpy(chksum, curchksum, curl);
1664 fn = solv_dupjoin("/", filename, 0);
1665 solv_free(filename);
1666 filename = solv_dupjoin("dists/", cinfo->name, fn);
1670 chksum = solv_free(chksum);
1672 *chksumtypep = chksumtype;
1678 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1681 struct repoinfo *cinfo;
1684 const char *filename;
1685 const unsigned char *filechksum;
1687 #ifdef ENABLE_SUSEREPO
1688 const char *descrdir;
1693 #if defined(ENABLE_SUSEREPO) || defined(ENABLE_RPMMD)
1697 #if defined(ENABLE_DEBIAN)
1702 repo = repo_create(pool, "@System");
1703 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1704 printf("rpm database:");
1705 if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/rpm/Packages"), &stb))
1706 memset(&stb, 0, sizeof(stb));
1708 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1709 printf("dpgk database:");
1710 if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/dpkg/status"), &stb))
1711 memset(&stb, 0, sizeof(stb));
1714 printf("no installed database:");
1715 memset(&stb, 0, sizeof(stb));
1717 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, 0, installedcookie);
1718 if (usecachedrepo(repo, 0, installedcookie, 0))
1719 printf(" cached\n");
1722 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1726 printf(" reading\n");
1728 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1729 # if defined(ENABLE_SUSEREPO) && defined(PRODUCTS_PATH)
1730 if (repo_add_products(repo, PRODUCTS_PATH, REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
1732 fprintf(stderr, "product reading failed: %s\n", pool_errstr(pool));
1736 if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
1738 ref = repo_create(pool, "@System.old");
1739 if (repo_add_solv(ref, ofp, 0))
1746 if (repo_add_rpmdb(repo, ref, REPO_REUSE_REPODATA | REPO_USE_ROOTDIR))
1748 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
1754 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1755 if (repo_add_debdb(repo, REPO_REUSE_REPODATA | REPO_USE_ROOTDIR))
1757 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
1761 writecachedrepo(repo, 0, 0, installedcookie);
1763 pool_set_installed(pool, repo);
1765 for (i = 0; i < nrepoinfos; i++)
1767 cinfo = repoinfos + i;
1768 if (!cinfo->enabled)
1771 repo = repo_create(pool, cinfo->alias);
1773 repo->appdata = cinfo;
1774 repo->priority = 99 - cinfo->priority;
1776 dorefresh = cinfo->autorefresh;
1777 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0), &stb) == 0)
1779 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1782 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1784 printf("repo '%s':", cinfo->alias);
1785 printf(" cached\n");
1788 switch (cinfo->type)
1792 printf("rpmmd repo '%s':", cinfo->alias);
1794 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1796 printf(" no repomd.xml file, skipped\n");
1801 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1802 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1804 printf(" cached\n");
1808 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "repodata/repomd.xml.asc", &sigpool))
1813 if (repo_add_repomdxml(repo, fp, 0))
1815 printf("repomd.xml: %s\n", pool_errstr(pool));
1817 break; /* hopeless */
1820 printf(" fetching\n");
1821 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1822 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1824 if (repo_add_rpmmd(repo, fp, 0, 0))
1826 printf("primary: %s\n", pool_errstr(pool));
1827 cinfo->incomplete = 1;
1831 if (cinfo->incomplete)
1832 break; /* hopeless */
1834 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1835 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1837 if (repo_add_updateinfoxml(repo, fp, 0))
1839 printf("updateinfo: %s\n", pool_errstr(pool));
1840 cinfo->incomplete = 1;
1845 data = repo_add_repodata(repo, 0);
1846 if (!repomd_add_ext(repo, data, "deltainfo"))
1847 repomd_add_ext(repo, data, "prestodelta");
1848 repomd_add_ext(repo, data, "filelists");
1849 repodata_internalize(data);
1850 if (!cinfo->incomplete)
1851 writecachedrepo(repo, 0, 0, cinfo->cookie);
1852 repodata_create_stubs(repo_last_repodata(repo));
1856 #ifdef ENABLE_SUSEREPO
1858 printf("susetags repo '%s':", cinfo->alias);
1862 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1864 printf(" no content file, skipped\n");
1869 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1870 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1872 printf(" cached\n");
1876 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "content.asc", &sigpool))
1881 if (repo_add_content(repo, fp, 0))
1883 printf("content: %s\n", pool_errstr(pool));
1885 break; /* hopeless */
1888 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1889 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1891 descrdir = "suse/setup/descr";
1892 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1894 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1897 printf(" no packages file entry, skipped\n");
1900 printf(" fetching\n");
1901 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) == 0)
1902 break; /* hopeless */
1903 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES))
1905 printf("packages: %s\n", pool_errstr(pool));
1907 cinfo->incomplete = 1;
1908 break; /* hopeless */
1911 /* add default language */
1912 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1914 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1917 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1919 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES))
1921 printf("packages.en: %s\n", pool_errstr(pool));
1922 cinfo->incomplete = 1;
1927 filename = susetags_find(repo, "patterns", &filechksum, &filechksumtype);
1930 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1933 while (fgets(pbuf, sizeof(pbuf), fp))
1935 int l = strlen(pbuf);
1937 if (l && pbuf[l - 1] == '\n')
1939 if (!*pbuf || *pbuf == '.' || strchr(pbuf, '/') != 0)
1941 filename = susetags_find(repo, pbuf, &filechksum, &filechksumtype);
1942 if (filename && (fp2 = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1944 if (repo_add_susetags(repo, fp2, defvendor, 0, REPO_NO_INTERNALIZE))
1946 printf("%s: %s\n", pbuf, pool_errstr(pool));
1947 cinfo->incomplete = 1;
1955 repo_internalize(repo);
1956 data = repo_add_repodata(repo, 0);
1957 susetags_add_ext(repo, data);
1958 repodata_internalize(data);
1959 if (!cinfo->incomplete)
1960 writecachedrepo(repo, 0, 0, cinfo->cookie);
1961 repodata_create_stubs(repo_last_repodata(repo));
1965 #if defined(ENABLE_DEBIAN)
1967 printf("debian repo '%s':", cinfo->alias);
1969 filename = solv_dupjoin("dists/", cinfo->name, "/Release");
1970 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
1972 printf(" no Release file, skipped\n");
1975 free((char *)filename);
1978 solv_free((char *)filename);
1979 if (cinfo->repo_gpgcheck)
1981 filename = solv_dupjoin("dists/", cinfo->name, "/Release.gpg");
1982 if (!downloadchecksig(cinfo, fpr, filename, &sigpool))
1985 solv_free((char *)filename);
1988 solv_free((char *)filename);
1990 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
1991 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1993 printf(" cached\n");
1997 printf(" fetching\n");
1998 for (j = 0; j < cinfo->ncomponents; j++)
2000 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
2002 printf("[component %s not found]\n", cinfo->components[j]);
2005 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
2007 if (repo_add_debpackages(repo, fp, 0))
2009 printf("component %s: %s\n", cinfo->components[j], pool_errstr(pool));
2010 cinfo->incomplete = 1;
2014 solv_free((char *)filechksum);
2015 solv_free((char *)filename);
2018 if (!cinfo->incomplete)
2019 writecachedrepo(repo, 0, 0, cinfo->cookie);
2024 printf("unsupported repo '%s': skipped\n", cinfo->alias);
2035 yesno(const char *str)
2037 char inbuf[128], *ip;
2044 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2049 while (*ip == ' ' || *ip == '\t')
2056 if (*ip == 'y' || *ip == 'n')
2057 return *ip == 'y' ? 1 : 0;
2061 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2071 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2073 struct fcstate *fcstate = cbdata;
2079 s = pool_id2solvable(pool, p);
2080 if (pool->installed && s->repo == pool->installed)
2082 if (!s->repo->rpmdbid)
2084 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2087 return rpm_byrpmdbid(fcstate->rpmstate, rpmdbid);
2089 for (i = 0; i < fcstate->newpkgscnt; i++)
2090 if (fcstate->checkq->elements[i] == p)
2092 if (i == fcstate->newpkgscnt)
2094 fp = fcstate->newpkgsfps[i];
2098 return rpm_byfp(fcstate->rpmstate, fp, pool_solvable2str(pool, s));
2103 runrpm(const char *arg, const char *name, int dupfd3, const char *rootdir)
2108 if ((pid = fork()) == (pid_t)-1)
2117 if (dupfd3 != -1 && dupfd3 != 3)
2123 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2124 if (strcmp(arg, "-e") == 0)
2125 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2127 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2131 while (waitpid(pid, &status, 0) != pid)
2135 printf("rpm failed\n");
2142 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2145 rundpkg(const char *arg, const char *name, int dupfd3, const char *rootdir)
2150 if ((pid = fork()) == (pid_t)-1)
2159 if (dupfd3 != -1 && dupfd3 != 3)
2165 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2166 if (strcmp(arg, "--install") == 0)
2167 execlp("dpkg", "dpkg", "--install", "--root", rootdir, "--force", "all", name, (char *)0);
2169 execlp("dpkg", "dpkg", "--remove", "--root", rootdir, "--force", "all", name, (char *)0);
2173 while (waitpid(pid, &status, 0) != pid)
2177 printf("dpkg failed\n");
2186 nscallback(Pool *pool, void *data, Id name, Id evr)
2188 if (name == NAMESPACE_PRODUCTBUDDY)
2190 /* SUSE specific hack: each product has an associated rpm */
2191 Solvable *s = pool->solvables + evr;
2195 cap = pool_str2id(pool, pool_tmpjoin(pool, "product(", pool_id2str(pool, s->name) + 8, ")"), 0);
2198 cap = pool_rel2id(pool, cap, s->evr, REL_EQ, 0);
2201 FOR_PROVIDES(p, pp, cap)
2203 Solvable *ps = pool->solvables + p;
2204 if (ps->repo == s->repo && ps->arch == s->arch)
2205 if (!bestp || pool_evrcmp(pool, pool->solvables[bestp].evr, ps->evr, EVRCMP_COMPARE) < 0)
2211 if (name == NAMESPACE_LANGUAGE)
2213 if (!strcmp(pool_id2str(pool, evr), "ja"))
2215 if (!strcmp(pool_id2str(pool, evr), "de"))
2217 if (!strcmp(pool_id2str(pool, evr), "en"))
2219 if (!strcmp(pool_id2str(pool, evr), "en_US"))
2227 #ifdef SOFTLOCKS_PATH
2229 addsoftlocks(Pool *pool, Queue *job)
2233 char *bp, *ep, buf[4096];
2235 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2237 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2239 while (*bp == ' ' || *bp == '\t')
2241 if (!*bp || *bp == '#')
2243 for (ep = bp; *ep; ep++)
2244 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2247 type = SOLVER_SOLVABLE_NAME;
2248 if (!strncmp(bp, "provides:", 9) && bp[9])
2250 type = SOLVER_SOLVABLE_PROVIDES;
2253 id = pool_str2id(pool, bp, 1);
2254 if (pool->installed)
2256 FOR_JOB_SELECT(p, pp, type, id)
2257 if (pool->solvables[p].repo == pool->installed)
2260 continue; /* ignore, as it is already installed */
2262 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2269 #if defined(ENABLE_RPMDB)
2272 rewrite_repos(Pool *pool, Queue *addedfileprovides, Queue *addedfileprovides_inst)
2277 Queue fileprovidesq;
2279 struct repoinfo *cinfo;
2281 map_init(&providedids, pool->ss.nstrings);
2282 queue_init(&fileprovidesq);
2283 for (i = 0; i < addedfileprovides->count; i++)
2284 MAPSET(&providedids, addedfileprovides->elements[i]);
2287 /* make sure all repodatas but the first are extensions */
2288 if (repo->nrepodata < 2)
2290 cinfo = repo->appdata;
2291 if (cinfo && cinfo->incomplete)
2293 data = repo_id2repodata(repo, 1);
2294 if (data->loadcallback)
2296 for (j = 2; j < repo->nrepodata; j++)
2298 Repodata *edata = repo_id2repodata(repo, j);
2299 if (!edata->loadcallback)
2302 if (j < repo->nrepodata)
2303 continue; /* found a non-externsion repodata, can't rewrite */
2304 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2306 if (repo == pool->installed && addedfileprovides_inst)
2308 for (j = 0; j < addedfileprovides->count; j++)
2309 MAPCLR(&providedids, addedfileprovides->elements[j]);
2310 for (j = 0; j < addedfileprovides_inst->count; j++)
2311 MAPSET(&providedids, addedfileprovides_inst->elements[j]);
2314 for (j = 0; j < fileprovidesq.count; j++)
2315 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2317 if (repo == pool->installed && addedfileprovides_inst)
2319 for (j = 0; j < addedfileprovides_inst->count; j++)
2320 MAPCLR(&providedids, addedfileprovides_inst->elements[j]);
2321 for (j = 0; j < addedfileprovides->count; j++)
2322 MAPSET(&providedids, addedfileprovides->elements[j]);
2323 if (n == addedfileprovides_inst->count)
2324 continue; /* nothing new added */
2326 else if (n == addedfileprovides->count)
2327 continue; /* nothing new added */
2329 repodata_set_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, repo == pool->installed && addedfileprovides_inst ? addedfileprovides_inst : addedfileprovides);
2330 repodata_internalize(data);
2331 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2333 queue_free(&fileprovidesq);
2334 map_free(&providedids);
2338 addfileprovides(Pool *pool)
2340 Queue addedfileprovides;
2341 Queue addedfileprovides_inst;
2343 queue_init(&addedfileprovides);
2344 queue_init(&addedfileprovides_inst);
2345 pool_addfileprovides_queue(pool, &addedfileprovides, &addedfileprovides_inst);
2346 if (addedfileprovides.count || addedfileprovides_inst.count)
2347 rewrite_repos(pool, &addedfileprovides, &addedfileprovides_inst);
2348 queue_free(&addedfileprovides);
2349 queue_free(&addedfileprovides_inst);
2354 #if defined(SUSE) || defined(FEDORA)
2356 add_patchjobs(Pool *pool, Queue *job)
2360 Map installedmap, multiversionmap;
2363 map_init(&multiversionmap, 0);
2364 map_init(&installedmap, pool->nsolvables);
2365 solver_calculate_multiversionmap(pool, job, &multiversionmap);
2366 if (pool->installed)
2367 FOR_REPO_SOLVABLES(pool->installed, p, s)
2368 MAPSET(&installedmap, p);
2370 /* install all patches */
2371 for (p = 1; p < pool->nsolvables; p++)
2377 s = pool->solvables + p;
2378 if (strncmp(pool_id2str(pool, s->name), "patch:", 6) != 0)
2380 FOR_PROVIDES(p2, pp, s->name)
2382 Solvable *s2 = pool->solvables + p2;
2383 if (s2->name != s->name)
2385 r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2386 if (r < 0 || (r == 0 && p > p2))
2391 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2392 if (type && !strcmp(type, "optional"))
2394 r = solvable_trivial_installable_map(s, &installedmap, 0, &multiversionmap);
2397 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2404 queue_push2(job, SOLVER_SOLVABLE, p);
2406 map_free(&installedmap);
2407 map_free(&multiversionmap);
2413 showdiskusagechanges(Transaction *trans)
2418 /* XXX: use mountpoints here */
2420 duc[1].path = "/usr/share/man";
2421 duc[2].path = "/sbin";
2422 duc[3].path = "/etc";
2423 transaction_calc_duchanges(trans, duc, 4);
2424 for (i = 0; i < 4; i++)
2425 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
2429 #if defined(ENABLE_RPMDB)
2431 trydeltadownload(Solvable *s, struct repoinfo *cinfo, const char *loc)
2433 Pool *pool = s->repo->pool;
2436 const unsigned char *chksum;
2439 char *matchname = strdup(pool_id2str(pool, s->name));
2441 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
2442 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
2443 while (dataiterator_step(&di))
2447 dataiterator_setpos_parent(&di);
2448 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
2449 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
2451 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
2452 FOR_PROVIDES(op, pp, s->name)
2454 Solvable *os = pool->solvables + op;
2455 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
2458 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
2460 /* base is installed, run sequence check */
2463 const char *archstr;
2468 archstr = pool_id2str(pool, s->arch);
2469 if (strlen(archstr) > 10 || strchr(archstr, '\'') != 0)
2472 seq = pool_tmpjoin(pool, pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME), "-", pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR));
2473 seq = pool_tmpappend(pool, seq, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM));
2474 if (strchr(seq, '\'') != 0)
2477 sprintf(cmd, "/usr/bin/applydeltarpm -a '%s' -c -s '", archstr);
2479 sprintf(cmd, "/usr/bin/applydeltarpm -c -s '");
2481 if (system(pool_tmpjoin(pool, cmd, seq, "'")) != 0)
2482 continue; /* didn't match */
2483 /* looks good, download delta */
2485 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
2487 continue; /* no way! */
2488 dloc = pool_lookup_deltalocation(pool, SOLVID_POS, 0);
2491 #ifdef ENABLE_SUSEREPO
2492 if (cinfo->type == TYPE_SUSETAGS)
2494 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
2495 dloc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", dloc);
2498 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
2500 /* got it, now reconstruct */
2501 newfd = opentmpfile();
2503 sprintf(cmd, "applydeltarpm -a '%s' /dev/fd/%d /dev/fd/%d", archstr, fileno(fp), newfd);
2505 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
2507 fcntl(fileno(fp), F_SETFD, 0);
2514 lseek(newfd, 0, SEEK_SET);
2516 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
2517 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
2523 retfp = fdopen(newfd, "r");
2528 dataiterator_free(&di);
2529 solv_free(matchname);
2536 #define MODE_INSTALL 1
2537 #define MODE_ERASE 2
2538 #define MODE_UPDATE 3
2539 #define MODE_DISTUPGRADE 4
2540 #define MODE_VERIFY 5
2541 #define MODE_PATCH 6
2543 #define MODE_REPOLIST 8
2544 #define MODE_SEARCH 9
2549 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2550 fprintf(stderr, "\n");
2551 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2552 fprintf(stderr, " versions from the repositories\n");
2553 fprintf(stderr, " erase: erase installed packages\n");
2554 fprintf(stderr, " info: display package information\n");
2555 fprintf(stderr, " install: install packages\n");
2556 fprintf(stderr, " list: list packages\n");
2557 fprintf(stderr, " repos: list enabled repositories\n");
2558 fprintf(stderr, " search: search name/summary/description\n");
2559 fprintf(stderr, " update: update installed packages\n");
2560 fprintf(stderr, " verify: check dependencies of installed packages\n");
2561 #if defined(SUSE) || defined(FEDORA)
2562 fprintf(stderr, " patch: install newest patches\n");
2564 fprintf(stderr, "\n");
2569 main(int argc, char **argv)
2572 Repo *commandlinerepo = 0;
2573 Id *commandlinepkgs = 0;
2575 struct repoinfo *repoinfos;
2577 int mainmode = 0, mode = 0;
2592 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2594 mainmode = MODE_INSTALL;
2595 mode = SOLVER_INSTALL;
2597 #if defined(SUSE) || defined(FEDORA)
2598 else if (!strcmp(argv[0], "patch"))
2600 mainmode = MODE_PATCH;
2601 mode = SOLVER_INSTALL;
2604 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2606 mainmode = MODE_ERASE;
2607 mode = SOLVER_ERASE;
2609 else if (!strcmp(argv[0], "list"))
2611 mainmode = MODE_LIST;
2614 else if (!strcmp(argv[0], "info"))
2616 mainmode = MODE_INFO;
2619 else if (!strcmp(argv[0], "search") || !strcmp(argv[0], "se"))
2621 mainmode = MODE_SEARCH;
2624 else if (!strcmp(argv[0], "verify"))
2626 mainmode = MODE_VERIFY;
2627 mode = SOLVER_VERIFY;
2629 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2631 mainmode = MODE_UPDATE;
2632 mode = SOLVER_UPDATE;
2634 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2636 mainmode = MODE_DISTUPGRADE;
2637 mode = SOLVER_DISTUPGRADE;
2639 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2641 mainmode = MODE_REPOLIST;
2649 if (argc > 2 && !strcmp(argv[1], "--root"))
2656 else if (argc > 1 && !strcmp(argv[1], "--clean"))
2662 else if (argc > 1 && !strcmp(argv[1], "--best"))
2672 pool = pool_create();
2673 pool_set_rootdir(pool, rootdir);
2677 const char *langs[] = {"de_DE", "de", "en"};
2678 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2682 pool_setloadcallback(pool, load_stub, 0);
2684 pool->nscallback = nscallback;
2686 // pool_setdebuglevel(pool, 2);
2688 repoinfos = read_repoinfos(pool, &nrepoinfos);
2690 if (mainmode == MODE_REPOLIST)
2693 for (i = 0; i < nrepoinfos; i++)
2695 struct repoinfo *cinfo = repoinfos + i;
2696 if (!cinfo->enabled)
2698 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2703 read_repos(pool, repoinfos, nrepoinfos);
2705 /* setup repofilter */
2706 queue_init(&repofilter);
2707 while (argc > 2 && !strcmp(argv[1], "-r"))
2709 const char *rname = argv[2], *rp;
2711 for (rp = rname; *rp; rp++)
2712 if (*rp <= '0' || *rp >= '9')
2716 /* repo specified by number */
2717 int rnum = atoi(rname);
2718 for (i = 0; i < nrepoinfos; i++)
2720 struct repoinfo *cinfo = repoinfos + i;
2721 if (!cinfo->enabled)
2724 repoid = cinfo->repo->repoid;
2729 /* repo specified by alias */
2733 if (!strcasecmp(rname, repo->name))
2734 repoid = repo->repoid;
2739 fprintf(stderr, "%s: no such repo\n", rname);
2742 /* SETVENDOR is actually wrong but useful */
2743 queue_push2(&repofilter, SOLVER_SOLVABLE_REPO | SOLVER_SETREPO | SOLVER_SETVENDOR, repoid);
2748 if (mainmode == MODE_SEARCH)
2754 pool_createwhatprovides(pool);
2756 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2757 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2758 dataiterator_set_search(&di, 0, 0);
2759 while (dataiterator_step(&di))
2760 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2761 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2762 dataiterator_set_search(&di, 0, 0);
2763 while (dataiterator_step(&di))
2764 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2765 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2766 dataiterator_set_search(&di, 0, 0);
2767 while (dataiterator_step(&di))
2768 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2769 dataiterator_free(&di);
2770 if (repofilter.count)
2771 selection_filter(pool, &sel, &repofilter);
2774 selection_solvables(pool, &sel, &q);
2776 for (i = 0; i < q.count; i++)
2778 Solvable *s = pool_id2solvable(pool, q.elements[i]);
2779 printf(" - %s [%s]: %s\n", pool_solvable2str(pool, s), s->repo->name, solvable_lookup_str(s, SOLVABLE_SUMMARY));
2785 /* process command line packages */
2786 if (mainmode == MODE_LIST || mainmode == MODE_INSTALL)
2788 for (i = 1; i < argc; i++)
2791 l = strlen(argv[i]);
2792 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2793 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2796 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2797 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2800 if (access(argv[i], R_OK))
2805 if (!commandlinepkgs)
2806 commandlinepkgs = solv_calloc(argc, sizeof(Id));
2807 if (!commandlinerepo)
2808 commandlinerepo = repo_create(pool, "@commandline");
2810 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2811 p = repo_add_rpm(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2813 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2814 p = repo_add_deb(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2818 fprintf(stderr, "could not add '%s'\n", argv[i]);
2821 commandlinepkgs[i] = p;
2823 if (commandlinerepo)
2824 repo_internalize(commandlinerepo);
2827 // FOR_REPOS(i, repo)
2828 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2830 #if defined(ENABLE_RPMDB)
2831 addfileprovides(pool);
2833 pool_createwhatprovides(pool);
2836 for (i = 1; i < argc; i++)
2839 int j, flags, rflags;
2841 if (commandlinepkgs && commandlinepkgs[i])
2843 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2847 flags = SELECTION_NAME|SELECTION_PROVIDES|SELECTION_GLOB;
2848 flags |= SELECTION_CANON|SELECTION_DOTARCH|SELECTION_REL;
2849 if (mode == MODE_LIST)
2850 flags |= SELECTION_WITH_SOURCE;
2851 if (argv[i][0] == '/')
2852 flags |= SELECTION_FILELIST | (mode == MODE_ERASE ? SELECTION_INSTALLED_ONLY : 0);
2853 rflags = selection_make(pool, &job2, argv[i], flags);
2854 if (repofilter.count)
2855 selection_filter(pool, &job2, &repofilter);
2858 flags |= SELECTION_NOCASE;
2859 rflags = selection_make(pool, &job2, argv[i], flags);
2860 if (repofilter.count)
2861 selection_filter(pool, &job2, &repofilter);
2863 printf("[ignoring case for '%s']\n", argv[i]);
2867 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2870 if (rflags & SELECTION_FILELIST)
2871 printf("[using file list match for '%s']\n", argv[i]);
2872 if (rflags & SELECTION_PROVIDES)
2873 printf("[using capability match for '%s']\n", argv[i]);
2874 for (j = 0; j < job2.count; j++)
2875 queue_push(&job, job2.elements[j]);
2879 if (!job.count && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE || mainmode == MODE_VERIFY || repofilter.count))
2881 queue_push2(&job, SOLVER_SOLVABLE_ALL, 0);
2882 if (repofilter.count)
2883 selection_filter(pool, &job, &repofilter);
2885 queue_free(&repofilter);
2887 if (!job.count && mainmode != MODE_PATCH)
2889 printf("no package matched\n");
2893 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
2895 /* list mode, no solver needed */
2898 for (i = 0; i < job.count; i += 2)
2902 pool_job2solvables(pool, &q, job.elements[i], job.elements[i + 1]);
2903 for (j = 0; j < q.count; j++)
2905 Solvable *s = pool_id2solvable(pool, q.elements[j]);
2906 if (mainmode == MODE_INFO)
2909 printf("Name: %s\n", pool_solvable2str(pool, s));
2910 printf("Repo: %s\n", s->repo->name);
2911 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
2912 str = solvable_lookup_str(s, SOLVABLE_URL);
2914 printf("Url: %s\n", str);
2915 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
2917 printf("License: %s\n", str);
2918 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
2924 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
2926 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
2928 printf(" - %s [%s]\n", pool_solvable2str(pool, s), s->repo->name);
2930 printf(" %s\n", sum);
2937 free_repoinfos(repoinfos, nrepoinfos);
2938 solv_free(commandlinepkgs);
2940 yum_substitute(pool, 0);
2945 #if defined(SUSE) || defined(FEDORA)
2946 if (mainmode == MODE_PATCH)
2947 add_patchjobs(pool, &job);
2951 for (i = 0; i < job.count; i += 2)
2953 job.elements[i] |= mode;
2954 if (mode == SOLVER_UPDATE && pool_isemptyupdatejob(pool, job.elements[i], job.elements[i + 1]))
2955 job.elements[i] ^= SOLVER_UPDATE ^ SOLVER_INSTALL;
2957 job.elements[i] |= SOLVER_CLEANDEPS;
2959 job.elements[i] |= SOLVER_FORCEBEST;
2962 // multiversion test
2963 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae", 1));
2964 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-base", 1));
2965 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-extra", 1));
2967 queue_push2(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, NAMESPACE_LANGUAGE, 0, REL_NAMESPACE, 1));
2968 queue_push2(&job, SOLVER_ERASE|SOLVER_CLEANDEPS|SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, NAMESPACE_LANGUAGE, 0, REL_NAMESPACE, 1));
2971 #ifdef SOFTLOCKS_PATH
2972 addsoftlocks(pool, &job);
2975 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2978 solv = solver_create(pool);
2979 solver_set_flag(solv, SOLVER_FLAG_SPLITPROVIDES, 1);
2981 solver_set_flag(solv, SOLVER_FLAG_ALLOW_VENDORCHANGE, 1);
2983 if (mainmode == MODE_ERASE)
2984 solver_set_flag(solv, SOLVER_FLAG_ALLOW_UNINSTALL, 1); /* don't nag */
2985 solver_set_flag(solv, SOLVER_FLAG_BEST_OBEY_POLICY, 1);
2989 Id problem, solution;
2992 if (!solver_solve(solv, &job))
2994 pcnt = solver_problem_count(solv);
2995 printf("Found %d problems:\n", pcnt);
2996 for (problem = 1; problem <= pcnt; problem++)
2999 printf("Problem %d/%d:\n", problem, pcnt);
3000 solver_printprobleminfo(solv, problem);
3002 scnt = solver_solution_count(solv, problem);
3003 for (solution = 1; solution <= scnt; solution++)
3005 printf("Solution %d:\n", solution);
3006 solver_printsolution(solv, problem, solution);
3011 char inbuf[128], *ip;
3012 printf("Please choose a solution: ");
3015 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
3020 while (*ip == ' ' || *ip == '\t')
3022 if (*ip >= '0' && *ip <= '9')
3025 if (take >= 1 && take <= scnt)
3041 solver_take_solution(solv, problem, take, &job);
3045 trans = solver_create_transaction(solv);
3046 if (!trans->steps.count)
3048 printf("Nothing to do.\n");
3049 transaction_free(trans);
3053 free_repoinfos(repoinfos, nrepoinfos);
3054 solv_free(commandlinepkgs);
3056 yum_substitute(pool, 0);
3061 /* display transaction to the user and ask for confirmation */
3063 printf("Transaction summary:\n\n");
3064 transaction_print(trans);
3066 showdiskusagechanges(trans);
3068 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
3071 if (!yesno("OK to continue (y/n)? "))
3074 transaction_free(trans);
3078 free_repoinfos(repoinfos, nrepoinfos);
3079 solv_free(commandlinepkgs);
3081 yum_substitute(pool, 0);
3086 /* download all new packages */
3087 queue_init(&checkq);
3088 newpkgs = transaction_installedresult(trans, &checkq);
3092 int downloadsize = 0;
3093 for (i = 0; i < newpkgs; i++)
3097 p = checkq.elements[i];
3098 s = pool_id2solvable(pool, p);
3099 downloadsize += solvable_lookup_sizek(s, SOLVABLE_DOWNLOADSIZE, 0);
3101 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
3102 newpkgsfps = solv_calloc(newpkgs, sizeof(*newpkgsfps));
3103 for (i = 0; i < newpkgs; i++)
3105 unsigned int medianr;
3108 struct repoinfo *cinfo;
3109 const unsigned char *chksum;
3112 p = checkq.elements[i];
3113 s = pool_id2solvable(pool, p);
3114 if (s->repo == commandlinerepo)
3116 loc = solvable_lookup_location(s, &medianr);
3117 if (!(newpkgsfps[i] = fopen(loc, "r")))
3125 cinfo = s->repo->appdata;
3128 printf("%s: no repository information\n", s->repo->name);
3131 loc = solvable_lookup_location(s, &medianr);
3134 #if defined(ENABLE_RPMDB)
3135 if (pool->installed && pool->installed->nsolvables)
3137 if ((newpkgsfps[i] = trydeltadownload(s, cinfo, loc)) != 0)
3141 continue; /* delta worked! */
3145 #ifdef ENABLE_SUSEREPO
3146 if (cinfo->type == TYPE_SUSETAGS)
3148 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3149 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3153 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3154 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3156 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3165 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3166 /* check for file conflicts */
3170 struct fcstate fcstate;
3172 printf("Searching for file conflicts\n");
3173 queue_init(&conflicts);
3174 fcstate.rpmstate = rpm_state_create(rootdir);
3175 fcstate.newpkgscnt = newpkgs;
3176 fcstate.checkq = &checkq;
3177 fcstate.newpkgsfps = newpkgsfps;
3178 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, FINDFILECONFLICTS_USE_SOLVABLEFILELIST | FINDFILECONFLICTS_CHECK_DIRALIASING | FINDFILECONFLICTS_USE_ROOTDIR, &fileconflict_cb, &fcstate);
3179 fcstate.rpmstate = rpm_state_free(fcstate.rpmstate);
3180 if (conflicts.count)
3183 for (i = 0; i < conflicts.count; i += 6)
3184 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 + 4]));
3186 if (yesno("Re-run solver (y/n/q)? "))
3188 for (i = 0; i < newpkgs; i++)
3190 fclose(newpkgsfps[i]);
3191 newpkgsfps = solv_free(newpkgsfps);
3194 pool_add_fileconflicts_deps(pool, &conflicts);
3198 queue_free(&conflicts);
3202 /* and finally commit the transaction */
3203 printf("Committing transaction:\n\n");
3204 transaction_order(trans, 0);
3205 for (i = 0; i < trans->steps.count; i++)
3207 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3208 const char *evr, *evrp, *nvra;
3215 p = trans->steps.elements[i];
3216 s = pool_id2solvable(pool, p);
3217 type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3220 case SOLVER_TRANSACTION_ERASE:
3221 printf("erase %s\n", pool_solvid2str(pool, p));
3222 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3223 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3225 /* strip epoch from evr */
3226 evr = evrp = pool_id2str(pool, s->evr);
3227 while (*evrp >= '0' && *evrp <= '9')
3229 if (evrp > evr && evrp[0] == ':' && evrp[1])
3231 nvra = pool_tmpjoin(pool, pool_id2str(pool, s->name), "-", evr);
3232 nvra = pool_tmpappend(pool, nvra, ".", pool_id2str(pool, s->arch));
3233 runrpm("-e", nvra, -1, rootdir); /* too bad that --querybynumber doesn't work */
3235 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3236 rundpkg("--remove", pool_id2str(pool, s->name), 0, rootdir);
3239 case SOLVER_TRANSACTION_INSTALL:
3240 case SOLVER_TRANSACTION_MULTIINSTALL:
3241 printf("install %s\n", pool_solvid2str(pool, p));
3242 for (j = 0; j < newpkgs; j++)
3243 if (checkq.elements[j] == p)
3245 fp = j < newpkgs ? newpkgsfps[j] : 0;
3249 lseek(fileno(fp), 0, SEEK_SET);
3250 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3251 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp), rootdir);
3253 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3254 rundpkg("--install", "/dev/fd/3", fileno(fp), rootdir);
3264 for (i = 0; i < newpkgs; i++)
3266 fclose(newpkgsfps[i]);
3267 solv_free(newpkgsfps);
3268 queue_free(&checkq);
3269 transaction_free(trans);
3273 free_repoinfos(repoinfos, nrepoinfos);
3274 solv_free(commandlinepkgs);
3276 yum_substitute(pool, 0);