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"
67 #ifdef ENABLE_RPMDB_PUBKEY
68 #include "repo_rpmdb_pubkey.h"
74 #include "repo_rpmmd.h"
75 #include "repo_repomdxml.h"
76 #include "repo_updateinfoxml.h"
77 #include "repo_deltainfoxml.h"
79 #ifdef ENABLE_SUSEREPO
80 #include "repo_products.h"
81 #include "repo_susetags.h"
82 #include "repo_content.h"
84 #include "solv_xfopen.h"
87 # define REPOINFO_PATH "/etc/yum.repos.d"
90 # define REPOINFO_PATH "/etc/zypp/repos.d"
91 # define PRODUCTS_PATH "/etc/products.d"
92 # define SOFTLOCKS_PATH "/var/lib/zypp/SoftLocks"
95 #define SOLVCACHE_PATH "/var/cache/solv"
97 #define METADATA_EXPIRE (60 * 15)
119 unsigned char cookie[32];
120 unsigned char extcookie[32];
126 yum_substitute(Pool *pool, char *line)
129 static char *releaseevr;
130 static char *basearch;
134 solv_free(releaseevr);
141 while ((p2 = strchr(p, '$')) != 0)
143 if (!strncmp(p2, "$releasever", 11))
151 rpmstate = rpm_state_create(pool, pool_get_rootdir(pool));
152 rpm_installedrpmdbids(rpmstate, "Providename", "redhat-release", &q);
157 handle = rpm_byrpmdbid(rpmstate, q.elements[0]);
158 releaseevr = handle ? rpm_query(handle, SOLVABLE_EVR) : 0;
159 if (releaseevr && (p = strchr(releaseevr, '-')) != 0)
162 rpm_state_free(rpmstate);
166 fprintf(stderr, "no installed package provides 'redhat-release', cannot determine $releasever\n");
171 p = pool_tmpjoin(pool, line, releaseevr, p2 + 11);
172 p2 = p + (p2 - line);
174 p = p2 + strlen(releaseevr);
177 if (!strncmp(p2, "$basearch", 9))
187 basearch = strdup(un.machine);
188 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
192 p = pool_tmpjoin(pool, line, basearch, p2 + 9);
193 p2 = p + (p2 - line);
195 p = p2 + strlen(basearch);
204 #define TYPE_UNKNOWN 0
205 #define TYPE_SUSETAGS 1
207 #define TYPE_PLAINDIR 3
208 #define TYPE_DEBIAN 4
212 read_repoinfos_sort(const void *ap, const void *bp)
214 const struct repoinfo *a = ap;
215 const struct repoinfo *b = bp;
216 return strcmp(a->alias, b->alias);
220 #if defined(SUSE) || defined(FEDORA)
223 read_repoinfos(Pool *pool, int *nrepoinfosp)
225 const char *reposdir = REPOINFO_PATH;
227 char buf2[4096], *kp, *vp, *kpe;
232 struct repoinfo *repoinfos = 0, *cinfo;
235 rdlen = strlen(reposdir);
236 dir = opendir(reposdir);
242 while ((ent = readdir(dir)) != 0)
244 if (ent->d_name[0] == '.')
246 l = strlen(ent->d_name);
247 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
249 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
250 if ((fp = fopen(buf, "r")) == 0)
256 while(fgets(buf2, sizeof(buf2), fp))
261 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
264 while (*kp == ' ' || *kp == '\t')
266 if (!*kp || *kp == '#')
270 kp = yum_substitute(pool, kp);
274 vp = strrchr(kp, ']');
278 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
279 cinfo = repoinfos + nrepoinfos++;
280 memset(cinfo, 0, sizeof(*cinfo));
281 cinfo->alias = strdup(kp + 1);
282 cinfo->type = TYPE_RPMMD;
283 cinfo->autorefresh = 1;
284 cinfo->priority = 99;
286 cinfo->repo_gpgcheck = 1;
288 cinfo->metadata_expire = METADATA_EXPIRE;
293 vp = strchr(kp, '=');
296 for (kpe = vp - 1; kpe >= kp; kpe--)
297 if (*kpe != ' ' && *kpe != '\t')
302 while (*vp == ' ' || *vp == '\t')
305 if (!strcmp(kp, "name"))
306 cinfo->name = strdup(vp);
307 else if (!strcmp(kp, "enabled"))
308 cinfo->enabled = *vp == '0' ? 0 : 1;
309 else if (!strcmp(kp, "autorefresh"))
310 cinfo->autorefresh = *vp == '0' ? 0 : 1;
311 else if (!strcmp(kp, "gpgcheck"))
312 cinfo->pkgs_gpgcheck = *vp == '0' ? 0 : 1;
313 else if (!strcmp(kp, "repo_gpgcheck"))
314 cinfo->repo_gpgcheck = *vp == '0' ? 0 : 1;
315 else if (!strcmp(kp, "baseurl"))
316 cinfo->baseurl = strdup(vp);
317 else if (!strcmp(kp, "mirrorlist"))
319 if (strstr(vp, "metalink"))
320 cinfo->metalink = strdup(vp);
322 cinfo->mirrorlist = strdup(vp);
324 else if (!strcmp(kp, "path"))
326 if (vp && strcmp(vp, "/") != 0)
327 cinfo->path = strdup(vp);
329 else if (!strcmp(kp, "type"))
331 if (!strcmp(vp, "yast2"))
332 cinfo->type = TYPE_SUSETAGS;
333 else if (!strcmp(vp, "rpm-md"))
334 cinfo->type = TYPE_RPMMD;
335 else if (!strcmp(vp, "plaindir"))
336 cinfo->type = TYPE_PLAINDIR;
338 cinfo->type = TYPE_UNKNOWN;
340 else if (!strcmp(kp, "priority"))
341 cinfo->priority = atoi(vp);
342 else if (!strcmp(kp, "keeppackages"))
343 cinfo->keeppackages = *vp == '0' ? 0 : 1;
349 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
350 *nrepoinfosp = nrepoinfos;
359 read_repoinfos(Pool *pool, int *nrepoinfosp)
365 char *kp, *url, *distro;
366 struct repoinfo *repoinfos = 0, *cinfo;
371 fp = fopen("/etc/apt/sources.list", "r");
378 dir = opendir("/etc/apt/sources.list.d");
382 if ((ent = readdir(dir)) == 0)
387 if (ent->d_name[0] == '.')
389 l = strlen(ent->d_name);
390 if (l < 5 || strcmp(ent->d_name + l - 5, ".list") != 0)
392 snprintf(buf, sizeof(buf), "%s/%s", "/etc/apt/sources.list.d", ent->d_name);
393 if (!(fp = fopen(buf, "r")))
396 while(fgets(buf2, sizeof(buf2), fp))
401 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
404 while (*kp == ' ' || *kp == '\t')
406 if (!*kp || *kp == '#')
408 if (strncmp(kp, "deb", 3) != 0)
411 if (*kp != ' ' && *kp != '\t')
413 while (*kp == ' ' || *kp == '\t')
418 while (*kp && *kp != ' ' && *kp != '\t')
422 while (*kp == ' ' || *kp == '\t')
427 while (*kp && *kp != ' ' && *kp != '\t')
431 while (*kp == ' ' || *kp == '\t')
435 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
436 cinfo = repoinfos + nrepoinfos++;
437 memset(cinfo, 0, sizeof(*cinfo));
438 cinfo->baseurl = strdup(url);
439 cinfo->alias = solv_dupjoin(url, "/", distro);
440 cinfo->name = strdup(distro);
441 cinfo->type = TYPE_DEBIAN;
443 cinfo->autorefresh = 1;
444 cinfo->repo_gpgcheck = 1;
445 cinfo->metadata_expire = METADATA_EXPIRE;
449 while (*kp == ' ' || *kp == '\t')
454 while (*kp && *kp != ' ' && *kp != '\t')
458 cinfo->components = solv_extend(cinfo->components, cinfo->ncomponents, 1, sizeof(*cinfo->components), 15);
459 cinfo->components[cinfo->ncomponents++] = strdup(compo);
465 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
466 *nrepoinfosp = nrepoinfos;
474 read_repoinfos(Pool *pool, int *nrepoinfosp)
483 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
486 for (i = 0; i < nrepoinfos; i++)
488 struct repoinfo *cinfo = repoinfos + i;
489 solv_free(cinfo->name);
490 solv_free(cinfo->alias);
491 solv_free(cinfo->path);
492 solv_free(cinfo->metalink);
493 solv_free(cinfo->mirrorlist);
494 solv_free(cinfo->baseurl);
495 for (j = 0; j < cinfo->ncomponents; j++)
496 solv_free(cinfo->components[j]);
497 solv_free(cinfo->components);
499 solv_free(repoinfos);
508 strcpy(tmpl, "/var/tmp/solvXXXXXX");
520 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
523 const unsigned char *sum;
527 h = solv_chksum_create(chksumtype);
530 printf("%s: unknown checksum type\n", file);
533 while ((l = read(fd, buf, sizeof(buf))) > 0)
534 solv_chksum_add(h, buf, l);
535 lseek(fd, 0, SEEK_SET);
537 sum = solv_chksum_get(h, &l);
538 if (memcmp(sum, chksum, l))
540 printf("%s: checksum mismatch\n", file);
541 solv_chksum_free(h, 0);
544 solv_chksum_free(h, 0);
549 findfastest(char **urls, int nurls)
556 struct addrinfo hints, *result;;
558 fds = solv_calloc(nurls, sizeof(*fds));
559 socks = solv_calloc(nurls, sizeof(*socks));
560 for (i = 0; i < nurls; i++)
563 p = strchr(urls[i], '/');
576 if ((p2 = strchr(p, '@')) != 0)
579 if (!strncmp("https:", urls[i], 6))
581 else if (!strncmp("ftp:", urls[i], 4))
583 if ((p2 = strrchr(p, ':')) != 0)
592 sprintf(portstr, "%d", port);
593 memset(&hints, 0, sizeof(struct addrinfo));
594 hints.ai_family = AF_UNSPEC;
595 hints.ai_socktype = SOCK_STREAM;
596 hints.ai_flags = AI_NUMERICSERV;
598 if (!getaddrinfo(p, portstr, &hints, &result))
600 socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
603 fcntl(socks[i], F_SETFL, O_NONBLOCK);
604 if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1)
606 if (errno != EINPROGRESS)
613 freeaddrinfo(result);
620 for (i = j = 0; i < nurls; i++)
624 fds[j].fd = socks[i];
625 fds[j].events = POLLOUT;
633 if (poll(fds, j, 10000) <= 0)
635 i = -1; /* something is wrong */
638 for (i = 0; i < j; i++)
639 if ((fds[i].revents & POLLOUT) != 0)
642 socklen_t soel = sizeof(int);
643 if (getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, &soe, &soel) == -1 || soe != 0)
645 /* connect failed, kill socket */
646 for (j = 0; j < nurls; j++)
647 if (socks[j] == fds[i].fd)
660 i = -1; /* something is wrong, no bit was set */
663 /* now i contains the fastest fd index */
666 for (j = 0; j < nurls; j++)
667 if (socks[j] == fds[i].fd)
671 char *url0 = urls[0];
676 for (i = j = 0; i < nurls; i++)
684 findmetalinkurl(FILE *fp, unsigned char *chksump, Id *chksumtypep)
686 char buf[4096], *bp, *ep;
693 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
695 while (*bp == ' ' || *bp == '\t')
697 if (chksumtypep && !*chksumtypep && !strncmp(bp, "<hash type=\"sha256\">", 20))
700 if (solv_hex2bin((const char **)&bp, chksump, 32) == 32)
701 *chksumtypep = REPOKEY_TYPE_SHA256;
704 if (strncmp(bp, "<url", 4))
706 bp = strchr(bp, '>');
710 ep = strstr(bp, "repodata/repomd.xml</url>");
714 if (strncmp(bp, "http", 4))
716 urls = solv_extend(urls, nurls, 1, sizeof(*urls), 15);
717 urls[nurls++] = strdup(bp);
722 findfastest(urls, nurls > 5 ? 5 : nurls);
725 for (i = 0; i < nurls; i++)
728 ep = strchr(bp, '/');
729 if ((ep = strchr(ep + 2, '/')) != 0)
732 printf("[using mirror %s]\n", bp);
741 findmirrorlisturl(FILE *fp)
743 char buf[4096], *bp, *ep;
748 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
750 while (*bp == ' ' || *bp == '\t')
752 if (!*bp || *bp == '#')
755 while (l > 0 && (bp[l - 1] == ' ' || bp[l - 1] == '\t' || bp[l - 1] == '\n'))
757 urls = solv_extend(urls, nurls, 1, sizeof(*urls), 15);
758 urls[nurls++] = strdup(bp);
763 findfastest(urls, nurls > 5 ? 5 : nurls);
766 for (i = 0; i < nurls; i++)
769 ep = strchr(bp, '/');
770 if ((ep = strchr(ep + 2, '/')) != 0)
773 printf("[using mirror %s]\n", bp);
782 iscompressed(const char *name)
784 return solv_xfopen_iscompressed(name) != 0;
788 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int markincomplete)
795 const char *baseurl = cinfo->baseurl;
799 if (!cinfo->metalink && !cinfo->mirrorlist)
801 if (file != cinfo->metalink && file != cinfo->mirrorlist)
803 unsigned char mlchksum[32];
805 fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
810 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
812 cinfo->baseurl = findmirrorlisturl(fp);
817 if (strchr(cinfo->baseurl, '$'))
819 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
820 free(cinfo->baseurl);
821 cinfo->baseurl = strdup(b);
824 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
826 chksumtype = mlchksumtype;
829 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, markincomplete);
831 snprintf(url, sizeof(url), "%s", file);
836 if (l && baseurl[l - 1] == '/')
837 snprintf(url, sizeof(url), "%s%s", baseurl, file);
839 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
842 // printf("url: %s\n", url);
843 if ((pid = fork()) == (pid_t)-1)
855 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
860 while (waitpid(pid, &status, 0) != pid)
862 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
868 lseek(fd, 0, SEEK_SET);
871 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
873 cinfo->incomplete = 1;
877 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
880 cinfo->incomplete = 1;
884 fcntl(fd, F_SETFD, FD_CLOEXEC);
887 if (solv_xfopen_iscompressed(file) < 0)
889 printf("%s: unsupported compression\n", file);
891 cinfo->incomplete = 1;
895 fp = solv_xfopen_fd(file, fd, "r");
898 fp = fdopen(fd, "r");
907 cleanupgpg(char *gpgdir)
910 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
912 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
914 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
916 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
918 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
924 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
933 off_t posfp, possigfp;
936 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
939 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
940 if (!(kfp = fopen(keysfile, "w")) )
946 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
950 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
951 if (!pubkey || !*pubkey)
953 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
955 if (fputc('\n', kfp) == EOF) /* Just in case... */
959 if (fclose(kfp) || !nkeys)
964 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
967 fprintf(stderr, "key import error\n");
972 posfp = lseek(fileno(fp), 0, SEEK_CUR);
973 lseek(fileno(fp), 0, SEEK_SET);
974 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
975 lseek(fileno(sigfp), 0, SEEK_SET);
976 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
977 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
978 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
980 lseek(fileno(sigfp), possigfp, SEEK_SET);
981 lseek(fileno(fp), posfp, SEEK_SET);
982 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
983 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
985 return r == 0 ? 1 : 0;
991 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
996 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));
997 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
998 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
1000 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
1001 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
1002 return r == 0 ? 1 : 0;
1010 Pool *sigpool = pool_create();
1011 #if defined(ENABLE_RPMDB_PUBKEY)
1012 Repo *repo = repo_create(sigpool, "rpmdbkeys");
1013 repo_add_rpmdb_pubkeys(repo, 0);
1019 downloadchecksig(struct repoinfo *cinfo, FILE *fp, const char *sigurl, Pool **sigpool)
1022 sigfp = curlfopen(cinfo, sigurl, 0, 0, 0, 0);
1025 printf(" unsigned, skipped\n");
1029 *sigpool = read_sigs();
1030 if (!checksig(*sigpool, fp, sigfp))
1032 printf(" checksig failed, skipped\n");
1040 #define CHKSUM_IDENT "1.1"
1043 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
1046 void *h = solv_chksum_create(chktype);
1049 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1050 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
1051 solv_chksum_add(h, buf, l);
1053 solv_chksum_free(h, out);
1057 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *cookie, unsigned char *out)
1059 void *h = solv_chksum_create(chktype);
1060 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1062 solv_chksum_add(h, cookie, 32);
1063 solv_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
1064 solv_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
1065 solv_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
1066 solv_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
1067 solv_chksum_free(h, out);
1079 pool_setarch(pool, un.machine);
1083 calccachepath(Repo *repo, const char *repoext)
1085 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
1088 p = pool_tmpappend(repo->pool, p, "_", repoext);
1089 p = pool_tmpappend(repo->pool, p, ".solvx", 0);
1092 p = pool_tmpappend(repo->pool, p, ".solv", 0);
1093 q = p + strlen(SOLVCACHE_PATH) + 1;
1103 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1106 unsigned char mycookie[32];
1107 unsigned char myextcookie[32];
1108 struct repoinfo *cinfo;
1111 cinfo = repo->appdata;
1112 if (!(fp = fopen(calccachepath(repo, repoext), "r")))
1114 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1119 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1124 if (cinfo && !repoext)
1126 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1137 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1138 if (strcmp(repoext, "DL") != 0)
1139 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1142 if (repo_add_solv(repo, fp, flags))
1147 if (cinfo && !repoext)
1149 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1150 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1153 futimens(fileno(fp), 0); /* try to set modification time */
1159 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1164 struct repoinfo *cinfo;
1167 cinfo = repo->appdata;
1168 if (cinfo && cinfo->incomplete)
1170 mkdir(SOLVCACHE_PATH, 0755);
1171 /* use dupjoin instead of tmpjoin because tmpl must survive repo_write */
1172 tmpl = solv_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
1180 if (!(fp = fdopen(fd, "w")))
1189 for (i = repo->start; i < repo->end; i++)
1190 if (repo->pool->solvables[i].repo != repo)
1196 repo_write(repo, fp);
1198 repodata_write(info, fp);
1201 int oldnrepodata = repo->nrepodata;
1202 repo->nrepodata = oldnrepodata > 2 ? 2 : oldnrepodata; /* XXX: do this right */
1203 repo_write(repo, fp);
1204 repo->nrepodata = oldnrepodata;
1208 if (!repoext && cinfo)
1210 if (!cinfo->extcookie[0])
1212 /* create the ext cookie and append it */
1213 /* we just need some unique ID */
1215 if (!fstat(fileno(fp), &stb))
1216 memset(&stb, 0, sizeof(stb));
1217 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cookie, cinfo->extcookie);
1218 if (cinfo->extcookie[0] == 0)
1219 cinfo->extcookie[0] = 1;
1221 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1229 /* append our cookie describing the metadata state */
1230 if (fwrite(cookie, 32, 1, fp) != 1)
1245 /* switch to just saved repo to activate paging and save memory */
1246 FILE *fp = fopen(tmpl, "r");
1252 repo_empty(repo, 1);
1253 if (repo_add_solv(repo, fp, SOLV_ADD_NO_STUBS))
1255 /* oops, no way to recover from here */
1256 fprintf(stderr, "internal error\n");
1262 int flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1263 /* make sure repodata contains complete repo */
1264 /* (this is how repodata_write saves it) */
1265 repodata_extend_block(info, repo->start, repo->end - repo->start);
1266 info->state = REPODATA_LOADING;
1267 if (strcmp(repoext, "DL") != 0)
1268 flags |= REPO_LOCALPOOL;
1269 repo_add_solv(repo, fp, flags);
1270 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1275 if (!rename(tmpl, calccachepath(repo, repoext)))
1282 /* repomd helpers */
1284 static inline const char *
1285 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1287 Pool *pool = repo->pool;
1289 const char *filename;
1294 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1295 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1296 if (dataiterator_step(&di))
1298 dataiterator_setpos_parent(&di);
1299 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1300 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1302 dataiterator_free(&di);
1303 if (filename && !*chksumtypep)
1305 printf("no %s file checksum!\n", what);
1312 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1314 Id chksumtype, handle;
1315 const unsigned char *chksum;
1316 const char *filename;
1318 filename = repomd_find(repo, what, &chksum, &chksumtype);
1321 if (!strcmp(what, "prestodelta"))
1323 handle = repodata_new_handle(data);
1324 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1325 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1326 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1327 if (!strcmp(what, "deltainfo"))
1329 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1330 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1332 if (!strcmp(what, "filelists"))
1334 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1335 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1337 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1342 repomd_load_ext(Repo *repo, Repodata *data)
1344 const char *filename, *repomdtype;
1347 struct repoinfo *cinfo;
1348 const unsigned char *filechksum;
1352 cinfo = repo->appdata;
1353 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1356 if (!strcmp(repomdtype, "filelists"))
1358 else if (!strcmp(repomdtype, "deltainfo"))
1362 printf("[%s:%s", repo->name, ext);
1363 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1365 printf(" cached]\n"); fflush(stdout);
1368 printf(" fetching]\n"); fflush(stdout);
1369 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1371 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1372 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1374 if (!strcmp(ext, "FL"))
1375 r = repo_add_rpmmd(repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES|REPO_LOCALPOOL);
1376 else if (!strcmp(ext, "DL"))
1377 r = repo_add_deltainfoxml(repo, fp, REPO_USE_LOADING);
1381 printf("%s\n", pool_errstr(repo->pool));
1384 writecachedrepo(repo, data, ext, cinfo->extcookie);
1391 #ifdef ENABLE_SUSEREPO
1392 /* susetags helpers */
1394 static inline const char *
1395 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1397 Pool *pool = repo->pool;
1399 const char *filename;
1404 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
1405 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1406 if (dataiterator_step(&di))
1408 dataiterator_setpos_parent(&di);
1409 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
1412 dataiterator_free(&di);
1413 if (filename && !*chksumtypep)
1415 printf("no %s file checksum!\n", what);
1421 static Id susetags_langtags[] = {
1422 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
1423 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
1424 SOLVABLE_EULA, REPOKEY_TYPE_STR,
1425 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
1426 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
1427 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
1432 susetags_add_ext(Repo *repo, Repodata *data)
1434 Pool *pool = repo->pool;
1437 Id handle, filechksumtype;
1438 const unsigned char *filechksum;
1441 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
1442 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1443 while (dataiterator_step(&di))
1445 if (strncmp(di.kv.str, "packages.", 9) != 0)
1447 if (!strcmp(di.kv.str + 9, "gz"))
1449 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
1451 ext[0] = di.kv.str[9];
1452 ext[1] = di.kv.str[10];
1454 if (!strcmp(ext, "en"))
1456 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
1458 handle = repodata_new_handle(data);
1459 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
1461 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
1462 if (!strcmp(ext, "DU"))
1464 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
1465 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
1467 else if (!strcmp(ext, "FL"))
1469 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1470 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1474 for (i = 0; susetags_langtags[i]; i += 2)
1476 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
1477 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
1480 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1482 dataiterator_free(&di);
1486 susetags_load_ext(Repo *repo, Repodata *data)
1488 const char *filename, *descrdir;
1492 struct repoinfo *cinfo;
1493 const unsigned char *filechksum;
1497 cinfo = repo->appdata;
1498 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1502 ext[0] = filename[9];
1503 ext[1] = filename[10];
1505 printf("[%s:%s", repo->name, ext);
1506 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1508 printf(" cached]\n"); fflush(stdout);
1511 printf(" fetching]\n"); fflush(stdout);
1512 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1513 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1515 descrdir = "suse/setup/descr";
1517 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1518 if ((fp = curlfopen(cinfo, pool_tmpjoin(repo->pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1520 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1521 if (strcmp(ext, "DL") != 0)
1522 flags |= REPO_LOCALPOOL;
1523 if (repo_add_susetags(repo, fp, defvendor, ext, flags))
1526 printf("%s\n", pool_errstr(repo->pool));
1530 writecachedrepo(repo, data, ext, cinfo->extcookie);
1540 load_stub(Pool *pool, Repodata *data, void *dp)
1542 struct repoinfo *cinfo = data->repo->appdata;
1543 switch (cinfo->type)
1545 #ifdef ENABLE_SUSEREPO
1547 return susetags_load_ext(data->repo, data);
1551 return repomd_load_ext(data->repo, data);
1558 static unsigned char installedcookie[32];
1560 #ifdef ENABLE_DEBIAN
1563 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1567 unsigned char *chksum;
1572 static char *basearch;
1584 basearch = strdup(un.machine);
1585 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
1588 binarydir = solv_dupjoin("binary-", basearch, "/");
1589 lbinarydir = strlen(binarydir);
1590 compl = strlen(comp);
1594 chksum = solv_malloc(32);
1596 while(fgets(buf, sizeof(buf), fp))
1601 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1603 if (!strncasecmp(buf, "MD5Sum:", 7))
1605 curchksumtype = REPOKEY_TYPE_MD5;
1608 if (!strncasecmp(buf, "SHA1:", 5))
1610 curchksumtype = REPOKEY_TYPE_SHA1;
1613 if (!strncasecmp(buf, "SHA256:", 7))
1615 curchksumtype = REPOKEY_TYPE_SHA256;
1627 while (*bp && *bp != ' ' && *bp != '\t')
1632 while (*bp == ' ' || *bp == '\t')
1634 while (*bp && *bp != ' ' && *bp != '\t')
1638 while (*bp == ' ' || *bp == '\t')
1641 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1644 if (strncmp(bp, binarydir, lbinarydir))
1647 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1649 unsigned char curchksum[32];
1651 if (filename && !strcmp(bp, "Packages"))
1653 curl = solv_chksum_len(curchksumtype);
1654 if (!curl || (chksumtype && solv_chksum_len(chksumtype) > curl))
1656 if (solv_hex2bin((const char **)&ch, curchksum, sizeof(curchksum)) != curl)
1658 solv_free(filename);
1659 filename = strdup(fn);
1660 chksumtype = curchksumtype;
1661 memcpy(chksum, curchksum, curl);
1667 fn = solv_dupjoin("/", filename, 0);
1668 solv_free(filename);
1669 filename = solv_dupjoin("dists/", cinfo->name, fn);
1673 chksum = solv_free(chksum);
1675 *chksumtypep = chksumtype;
1681 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1684 struct repoinfo *cinfo;
1687 const char *filename;
1688 const unsigned char *filechksum;
1690 #ifdef ENABLE_SUSEREPO
1691 const char *descrdir;
1696 #if defined(ENABLE_SUSEREPO) || defined(ENABLE_RPMMD)
1700 #if defined(ENABLE_DEBIAN)
1705 repo = repo_create(pool, "@System");
1706 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1707 printf("rpm database:");
1708 if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/rpm/Packages"), &stb))
1709 memset(&stb, 0, sizeof(stb));
1711 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1712 printf("dpgk database:");
1713 if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/dpkg/status"), &stb))
1714 memset(&stb, 0, sizeof(stb));
1717 printf("no installed database:");
1718 memset(&stb, 0, sizeof(stb));
1720 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, 0, installedcookie);
1721 if (usecachedrepo(repo, 0, installedcookie, 0))
1722 printf(" cached\n");
1725 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1729 printf(" reading\n");
1731 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1732 # if defined(ENABLE_SUSEREPO) && defined(PRODUCTS_PATH)
1733 if (repo_add_products(repo, PRODUCTS_PATH, REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
1735 fprintf(stderr, "product reading failed: %s\n", pool_errstr(pool));
1739 if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
1741 ref = repo_create(pool, "@System.old");
1742 if (repo_add_solv(ref, ofp, 0))
1749 if (repo_add_rpmdb(repo, ref, REPO_REUSE_REPODATA | REPO_USE_ROOTDIR))
1751 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
1757 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1758 if (repo_add_debdb(repo, REPO_REUSE_REPODATA | REPO_USE_ROOTDIR))
1760 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
1764 writecachedrepo(repo, 0, 0, installedcookie);
1766 pool_set_installed(pool, repo);
1768 for (i = 0; i < nrepoinfos; i++)
1770 cinfo = repoinfos + i;
1771 if (!cinfo->enabled)
1774 repo = repo_create(pool, cinfo->alias);
1776 repo->appdata = cinfo;
1777 repo->priority = 99 - cinfo->priority;
1779 dorefresh = cinfo->autorefresh;
1780 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0), &stb) == 0)
1782 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1785 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1787 printf("repo '%s':", cinfo->alias);
1788 printf(" cached\n");
1791 switch (cinfo->type)
1795 printf("rpmmd repo '%s':", cinfo->alias);
1797 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1799 printf(" no repomd.xml file, skipped\n");
1804 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1805 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1807 printf(" cached\n");
1811 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "repodata/repomd.xml.asc", &sigpool))
1816 if (repo_add_repomdxml(repo, fp, 0))
1818 printf("repomd.xml: %s\n", pool_errstr(pool));
1820 break; /* hopeless */
1823 printf(" fetching\n");
1824 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1825 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1827 if (repo_add_rpmmd(repo, fp, 0, 0))
1829 printf("primary: %s\n", pool_errstr(pool));
1830 cinfo->incomplete = 1;
1834 if (cinfo->incomplete)
1835 break; /* hopeless */
1837 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1838 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1840 if (repo_add_updateinfoxml(repo, fp, 0))
1842 printf("updateinfo: %s\n", pool_errstr(pool));
1843 cinfo->incomplete = 1;
1848 data = repo_add_repodata(repo, 0);
1849 if (!repomd_add_ext(repo, data, "deltainfo"))
1850 repomd_add_ext(repo, data, "prestodelta");
1851 repomd_add_ext(repo, data, "filelists");
1852 repodata_internalize(data);
1853 if (!cinfo->incomplete)
1854 writecachedrepo(repo, 0, 0, cinfo->cookie);
1855 repodata_create_stubs(repo_last_repodata(repo));
1859 #ifdef ENABLE_SUSEREPO
1861 printf("susetags repo '%s':", cinfo->alias);
1865 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1867 printf(" no content file, skipped\n");
1872 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1873 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1875 printf(" cached\n");
1879 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "content.asc", &sigpool))
1884 if (repo_add_content(repo, fp, 0))
1886 printf("content: %s\n", pool_errstr(pool));
1888 break; /* hopeless */
1891 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1892 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1894 descrdir = "suse/setup/descr";
1895 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1897 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1900 printf(" no packages file entry, skipped\n");
1903 printf(" fetching\n");
1904 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) == 0)
1905 break; /* hopeless */
1906 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES))
1908 printf("packages: %s\n", pool_errstr(pool));
1910 cinfo->incomplete = 1;
1911 break; /* hopeless */
1914 /* add default language */
1915 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1917 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1920 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1922 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES))
1924 printf("packages.en: %s\n", pool_errstr(pool));
1925 cinfo->incomplete = 1;
1930 filename = susetags_find(repo, "patterns", &filechksum, &filechksumtype);
1933 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1936 while (fgets(pbuf, sizeof(pbuf), fp))
1938 int l = strlen(pbuf);
1940 if (l && pbuf[l - 1] == '\n')
1942 if (!*pbuf || *pbuf == '.' || strchr(pbuf, '/') != 0)
1944 filename = susetags_find(repo, pbuf, &filechksum, &filechksumtype);
1945 if (filename && (fp2 = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1947 if (repo_add_susetags(repo, fp2, defvendor, 0, REPO_NO_INTERNALIZE))
1949 printf("%s: %s\n", pbuf, pool_errstr(pool));
1950 cinfo->incomplete = 1;
1958 repo_internalize(repo);
1959 data = repo_add_repodata(repo, 0);
1960 susetags_add_ext(repo, data);
1961 repodata_internalize(data);
1962 if (!cinfo->incomplete)
1963 writecachedrepo(repo, 0, 0, cinfo->cookie);
1964 repodata_create_stubs(repo_last_repodata(repo));
1968 #if defined(ENABLE_DEBIAN)
1970 printf("debian repo '%s':", cinfo->alias);
1972 filename = solv_dupjoin("dists/", cinfo->name, "/Release");
1973 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
1975 printf(" no Release file, skipped\n");
1978 free((char *)filename);
1981 solv_free((char *)filename);
1982 if (cinfo->repo_gpgcheck)
1984 filename = solv_dupjoin("dists/", cinfo->name, "/Release.gpg");
1985 if (!downloadchecksig(cinfo, fpr, filename, &sigpool))
1988 solv_free((char *)filename);
1991 solv_free((char *)filename);
1993 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
1994 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1996 printf(" cached\n");
2000 printf(" fetching\n");
2001 for (j = 0; j < cinfo->ncomponents; j++)
2003 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
2005 printf("[component %s not found]\n", cinfo->components[j]);
2008 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
2010 if (repo_add_debpackages(repo, fp, 0))
2012 printf("component %s: %s\n", cinfo->components[j], pool_errstr(pool));
2013 cinfo->incomplete = 1;
2017 solv_free((char *)filechksum);
2018 solv_free((char *)filename);
2021 if (!cinfo->incomplete)
2022 writecachedrepo(repo, 0, 0, cinfo->cookie);
2027 printf("unsupported repo '%s': skipped\n", cinfo->alias);
2038 yesno(const char *str)
2040 char inbuf[128], *ip;
2047 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2052 while (*ip == ' ' || *ip == '\t')
2059 if (*ip == 'y' || *ip == 'n')
2060 return *ip == 'y' ? 1 : 0;
2064 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2074 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2076 struct fcstate *fcstate = cbdata;
2082 s = pool_id2solvable(pool, p);
2083 if (pool->installed && s->repo == pool->installed)
2085 if (!s->repo->rpmdbid)
2087 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2090 return rpm_byrpmdbid(fcstate->rpmstate, rpmdbid);
2092 for (i = 0; i < fcstate->newpkgscnt; i++)
2093 if (fcstate->checkq->elements[i] == p)
2095 if (i == fcstate->newpkgscnt)
2097 fp = fcstate->newpkgsfps[i];
2101 return rpm_byfp(fcstate->rpmstate, fp, pool_solvable2str(pool, s));
2106 runrpm(const char *arg, const char *name, int dupfd3, const char *rootdir)
2111 if ((pid = fork()) == (pid_t)-1)
2120 if (dupfd3 != -1 && dupfd3 != 3)
2126 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2127 if (strcmp(arg, "-e") == 0)
2128 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2130 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2134 while (waitpid(pid, &status, 0) != pid)
2138 printf("rpm failed\n");
2145 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2148 rundpkg(const char *arg, const char *name, int dupfd3, const char *rootdir)
2153 if ((pid = fork()) == (pid_t)-1)
2162 if (dupfd3 != -1 && dupfd3 != 3)
2168 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2169 if (strcmp(arg, "--install") == 0)
2170 execlp("dpkg", "dpkg", "--install", "--root", rootdir, "--force", "all", name, (char *)0);
2172 execlp("dpkg", "dpkg", "--remove", "--root", rootdir, "--force", "all", name, (char *)0);
2176 while (waitpid(pid, &status, 0) != pid)
2180 printf("dpkg failed\n");
2189 nscallback(Pool *pool, void *data, Id name, Id evr)
2191 if (name == NAMESPACE_PRODUCTBUDDY)
2193 /* SUSE specific hack: each product has an associated rpm */
2194 Solvable *s = pool->solvables + evr;
2198 cap = pool_str2id(pool, pool_tmpjoin(pool, "product(", pool_id2str(pool, s->name) + 8, ")"), 0);
2201 cap = pool_rel2id(pool, cap, s->evr, REL_EQ, 0);
2204 FOR_PROVIDES(p, pp, cap)
2206 Solvable *ps = pool->solvables + p;
2207 if (ps->repo == s->repo && ps->arch == s->arch)
2208 if (!bestp || pool_evrcmp(pool, pool->solvables[bestp].evr, ps->evr, EVRCMP_COMPARE) < 0)
2214 if (name == NAMESPACE_LANGUAGE)
2216 if (!strcmp(pool_id2str(pool, evr), "ja"))
2218 if (!strcmp(pool_id2str(pool, evr), "de"))
2220 if (!strcmp(pool_id2str(pool, evr), "en"))
2222 if (!strcmp(pool_id2str(pool, evr), "en_US"))
2230 #ifdef SOFTLOCKS_PATH
2232 addsoftlocks(Pool *pool, Queue *job)
2236 char *bp, *ep, buf[4096];
2238 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2240 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2242 while (*bp == ' ' || *bp == '\t')
2244 if (!*bp || *bp == '#')
2246 for (ep = bp; *ep; ep++)
2247 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2250 type = SOLVER_SOLVABLE_NAME;
2251 if (!strncmp(bp, "provides:", 9) && bp[9])
2253 type = SOLVER_SOLVABLE_PROVIDES;
2256 id = pool_str2id(pool, bp, 1);
2257 if (pool->installed)
2259 FOR_JOB_SELECT(p, pp, type, id)
2260 if (pool->solvables[p].repo == pool->installed)
2263 continue; /* ignore, as it is already installed */
2265 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2272 #if defined(ENABLE_RPMDB)
2275 rewrite_repos(Pool *pool, Queue *addedfileprovides, Queue *addedfileprovides_inst)
2280 Queue fileprovidesq;
2282 struct repoinfo *cinfo;
2284 map_init(&providedids, pool->ss.nstrings);
2285 queue_init(&fileprovidesq);
2286 for (i = 0; i < addedfileprovides->count; i++)
2287 MAPSET(&providedids, addedfileprovides->elements[i]);
2290 /* make sure all repodatas but the first are extensions */
2291 if (repo->nrepodata < 2)
2293 cinfo = repo->appdata;
2294 if (cinfo && cinfo->incomplete)
2296 data = repo_id2repodata(repo, 1);
2297 if (data->loadcallback)
2299 for (j = 2; j < repo->nrepodata; j++)
2301 Repodata *edata = repo_id2repodata(repo, j);
2302 if (!edata->loadcallback)
2305 if (j < repo->nrepodata)
2306 continue; /* found a non-externsion repodata, can't rewrite */
2307 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2309 if (repo == pool->installed && addedfileprovides_inst)
2311 for (j = 0; j < addedfileprovides->count; j++)
2312 MAPCLR(&providedids, addedfileprovides->elements[j]);
2313 for (j = 0; j < addedfileprovides_inst->count; j++)
2314 MAPSET(&providedids, addedfileprovides_inst->elements[j]);
2317 for (j = 0; j < fileprovidesq.count; j++)
2318 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2320 if (repo == pool->installed && addedfileprovides_inst)
2322 for (j = 0; j < addedfileprovides_inst->count; j++)
2323 MAPCLR(&providedids, addedfileprovides_inst->elements[j]);
2324 for (j = 0; j < addedfileprovides->count; j++)
2325 MAPSET(&providedids, addedfileprovides->elements[j]);
2326 if (n == addedfileprovides_inst->count)
2327 continue; /* nothing new added */
2329 else if (n == addedfileprovides->count)
2330 continue; /* nothing new added */
2332 repodata_set_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, repo == pool->installed && addedfileprovides_inst ? addedfileprovides_inst : addedfileprovides);
2333 repodata_internalize(data);
2334 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2336 queue_free(&fileprovidesq);
2337 map_free(&providedids);
2341 addfileprovides(Pool *pool)
2343 Queue addedfileprovides;
2344 Queue addedfileprovides_inst;
2346 queue_init(&addedfileprovides);
2347 queue_init(&addedfileprovides_inst);
2348 pool_addfileprovides_queue(pool, &addedfileprovides, &addedfileprovides_inst);
2349 if (addedfileprovides.count || addedfileprovides_inst.count)
2350 rewrite_repos(pool, &addedfileprovides, &addedfileprovides_inst);
2351 queue_free(&addedfileprovides);
2352 queue_free(&addedfileprovides_inst);
2357 #if defined(SUSE) || defined(FEDORA)
2359 add_patchjobs(Pool *pool, Queue *job)
2363 Map installedmap, multiversionmap;
2366 map_init(&multiversionmap, 0);
2367 map_init(&installedmap, pool->nsolvables);
2368 solver_calculate_multiversionmap(pool, job, &multiversionmap);
2369 if (pool->installed)
2370 FOR_REPO_SOLVABLES(pool->installed, p, s)
2371 MAPSET(&installedmap, p);
2373 /* install all patches */
2374 for (p = 1; p < pool->nsolvables; p++)
2380 s = pool->solvables + p;
2381 if (strncmp(pool_id2str(pool, s->name), "patch:", 6) != 0)
2383 FOR_PROVIDES(p2, pp, s->name)
2385 Solvable *s2 = pool->solvables + p2;
2386 if (s2->name != s->name)
2388 r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2389 if (r < 0 || (r == 0 && p > p2))
2394 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2395 if (type && !strcmp(type, "optional"))
2397 r = solvable_trivial_installable_map(s, &installedmap, 0, &multiversionmap);
2400 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2407 queue_push2(job, SOLVER_SOLVABLE, p);
2409 map_free(&installedmap);
2410 map_free(&multiversionmap);
2416 showdiskusagechanges(Transaction *trans)
2421 /* XXX: use mountpoints here */
2423 duc[1].path = "/usr/share/man";
2424 duc[2].path = "/sbin";
2425 duc[3].path = "/etc";
2426 transaction_calc_duchanges(trans, duc, 4);
2427 for (i = 0; i < 4; i++)
2428 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
2432 #if defined(ENABLE_RPMDB)
2434 trydeltadownload(Solvable *s, struct repoinfo *cinfo, const char *loc)
2436 Pool *pool = s->repo->pool;
2439 const unsigned char *chksum;
2442 char *matchname = strdup(pool_id2str(pool, s->name));
2444 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
2445 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
2446 while (dataiterator_step(&di))
2450 dataiterator_setpos_parent(&di);
2451 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
2452 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
2454 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
2455 FOR_PROVIDES(op, pp, s->name)
2457 Solvable *os = pool->solvables + op;
2458 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
2461 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
2463 /* base is installed, run sequence check */
2466 const char *archstr;
2471 archstr = pool_id2str(pool, s->arch);
2472 if (strlen(archstr) > 10 || strchr(archstr, '\'') != 0)
2475 seq = pool_tmpjoin(pool, pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME), "-", pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR));
2476 seq = pool_tmpappend(pool, seq, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM));
2477 if (strchr(seq, '\'') != 0)
2480 sprintf(cmd, "/usr/bin/applydeltarpm -a '%s' -c -s '", archstr);
2482 sprintf(cmd, "/usr/bin/applydeltarpm -c -s '");
2484 if (system(pool_tmpjoin(pool, cmd, seq, "'")) != 0)
2485 continue; /* didn't match */
2486 /* looks good, download delta */
2488 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
2490 continue; /* no way! */
2491 dloc = pool_lookup_deltalocation(pool, SOLVID_POS, 0);
2494 #ifdef ENABLE_SUSEREPO
2495 if (cinfo->type == TYPE_SUSETAGS)
2497 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
2498 dloc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", dloc);
2501 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
2503 /* got it, now reconstruct */
2504 newfd = opentmpfile();
2506 sprintf(cmd, "applydeltarpm -a '%s' /dev/fd/%d /dev/fd/%d", archstr, fileno(fp), newfd);
2508 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
2510 fcntl(fileno(fp), F_SETFD, 0);
2517 lseek(newfd, 0, SEEK_SET);
2519 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
2520 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
2526 retfp = fdopen(newfd, "r");
2531 dataiterator_free(&di);
2532 solv_free(matchname);
2539 #define MODE_INSTALL 1
2540 #define MODE_ERASE 2
2541 #define MODE_UPDATE 3
2542 #define MODE_DISTUPGRADE 4
2543 #define MODE_VERIFY 5
2544 #define MODE_PATCH 6
2546 #define MODE_REPOLIST 8
2547 #define MODE_SEARCH 9
2552 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2553 fprintf(stderr, "\n");
2554 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2555 fprintf(stderr, " versions from the repositories\n");
2556 fprintf(stderr, " erase: erase installed packages\n");
2557 fprintf(stderr, " info: display package information\n");
2558 fprintf(stderr, " install: install packages\n");
2559 fprintf(stderr, " list: list packages\n");
2560 fprintf(stderr, " repos: list enabled repositories\n");
2561 fprintf(stderr, " search: search name/summary/description\n");
2562 fprintf(stderr, " update: update installed packages\n");
2563 fprintf(stderr, " verify: check dependencies of installed packages\n");
2564 #if defined(SUSE) || defined(FEDORA)
2565 fprintf(stderr, " patch: install newest patches\n");
2567 fprintf(stderr, "\n");
2572 main(int argc, char **argv)
2575 Repo *commandlinerepo = 0;
2576 Id *commandlinepkgs = 0;
2578 struct repoinfo *repoinfos;
2580 int mainmode = 0, mode = 0;
2595 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2597 mainmode = MODE_INSTALL;
2598 mode = SOLVER_INSTALL;
2600 #if defined(SUSE) || defined(FEDORA)
2601 else if (!strcmp(argv[0], "patch"))
2603 mainmode = MODE_PATCH;
2604 mode = SOLVER_INSTALL;
2607 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2609 mainmode = MODE_ERASE;
2610 mode = SOLVER_ERASE;
2612 else if (!strcmp(argv[0], "list"))
2614 mainmode = MODE_LIST;
2617 else if (!strcmp(argv[0], "info"))
2619 mainmode = MODE_INFO;
2622 else if (!strcmp(argv[0], "search") || !strcmp(argv[0], "se"))
2624 mainmode = MODE_SEARCH;
2627 else if (!strcmp(argv[0], "verify"))
2629 mainmode = MODE_VERIFY;
2630 mode = SOLVER_VERIFY;
2632 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2634 mainmode = MODE_UPDATE;
2635 mode = SOLVER_UPDATE;
2637 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2639 mainmode = MODE_DISTUPGRADE;
2640 mode = SOLVER_DISTUPGRADE;
2642 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2644 mainmode = MODE_REPOLIST;
2652 if (argc > 2 && !strcmp(argv[1], "--root"))
2659 else if (argc > 1 && !strcmp(argv[1], "--clean"))
2665 else if (argc > 1 && !strcmp(argv[1], "--best"))
2675 pool = pool_create();
2676 pool_set_rootdir(pool, rootdir);
2680 const char *langs[] = {"de_DE", "de", "en"};
2681 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2685 pool_setloadcallback(pool, load_stub, 0);
2687 pool->nscallback = nscallback;
2689 // pool_setdebuglevel(pool, 2);
2691 repoinfos = read_repoinfos(pool, &nrepoinfos);
2693 if (mainmode == MODE_REPOLIST)
2696 for (i = 0; i < nrepoinfos; i++)
2698 struct repoinfo *cinfo = repoinfos + i;
2699 if (!cinfo->enabled)
2701 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2706 read_repos(pool, repoinfos, nrepoinfos);
2708 /* setup repofilter */
2709 queue_init(&repofilter);
2710 while (argc > 2 && !strcmp(argv[1], "-r"))
2712 const char *rname = argv[2], *rp;
2714 for (rp = rname; *rp; rp++)
2715 if (*rp <= '0' || *rp >= '9')
2719 /* repo specified by number */
2720 int rnum = atoi(rname);
2721 for (i = 0; i < nrepoinfos; i++)
2723 struct repoinfo *cinfo = repoinfos + i;
2724 if (!cinfo->enabled)
2727 repoid = cinfo->repo->repoid;
2732 /* repo specified by alias */
2736 if (!strcasecmp(rname, repo->name))
2737 repoid = repo->repoid;
2742 fprintf(stderr, "%s: no such repo\n", rname);
2745 /* SETVENDOR is actually wrong but useful */
2746 queue_push2(&repofilter, SOLVER_SOLVABLE_REPO | SOLVER_SETREPO | SOLVER_SETVENDOR, repoid);
2751 if (mainmode == MODE_SEARCH)
2757 pool_createwhatprovides(pool);
2759 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2760 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2761 dataiterator_set_search(&di, 0, 0);
2762 while (dataiterator_step(&di))
2763 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2764 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2765 dataiterator_set_search(&di, 0, 0);
2766 while (dataiterator_step(&di))
2767 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2768 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2769 dataiterator_set_search(&di, 0, 0);
2770 while (dataiterator_step(&di))
2771 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2772 dataiterator_free(&di);
2773 if (repofilter.count)
2774 selection_filter(pool, &sel, &repofilter);
2777 selection_solvables(pool, &sel, &q);
2779 for (i = 0; i < q.count; i++)
2781 Solvable *s = pool_id2solvable(pool, q.elements[i]);
2782 printf(" - %s [%s]: %s\n", pool_solvable2str(pool, s), s->repo->name, solvable_lookup_str(s, SOLVABLE_SUMMARY));
2788 /* process command line packages */
2789 if (mainmode == MODE_LIST || mainmode == MODE_INSTALL)
2791 for (i = 1; i < argc; i++)
2794 l = strlen(argv[i]);
2795 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2796 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2799 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2800 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2803 if (access(argv[i], R_OK))
2808 if (!commandlinepkgs)
2809 commandlinepkgs = solv_calloc(argc, sizeof(Id));
2810 if (!commandlinerepo)
2811 commandlinerepo = repo_create(pool, "@commandline");
2813 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2814 p = repo_add_rpm(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2816 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2817 p = repo_add_deb(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2821 fprintf(stderr, "could not add '%s'\n", argv[i]);
2824 commandlinepkgs[i] = p;
2826 if (commandlinerepo)
2827 repo_internalize(commandlinerepo);
2830 // FOR_REPOS(i, repo)
2831 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2833 #if defined(ENABLE_RPMDB)
2834 addfileprovides(pool);
2836 pool_createwhatprovides(pool);
2839 for (i = 1; i < argc; i++)
2842 int j, flags, rflags;
2844 if (commandlinepkgs && commandlinepkgs[i])
2846 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2850 flags = SELECTION_NAME|SELECTION_PROVIDES|SELECTION_GLOB;
2851 flags |= SELECTION_CANON|SELECTION_DOTARCH|SELECTION_REL;
2852 if (mode == MODE_LIST)
2853 flags |= SELECTION_WITH_SOURCE;
2854 if (argv[i][0] == '/')
2855 flags |= SELECTION_FILELIST | (mode == MODE_ERASE ? SELECTION_INSTALLED_ONLY : 0);
2856 rflags = selection_make(pool, &job2, argv[i], flags);
2857 if (repofilter.count)
2858 selection_filter(pool, &job2, &repofilter);
2861 flags |= SELECTION_NOCASE;
2862 rflags = selection_make(pool, &job2, argv[i], flags);
2863 if (repofilter.count)
2864 selection_filter(pool, &job2, &repofilter);
2866 printf("[ignoring case for '%s']\n", argv[i]);
2870 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2873 if (rflags & SELECTION_FILELIST)
2874 printf("[using file list match for '%s']\n", argv[i]);
2875 if (rflags & SELECTION_PROVIDES)
2876 printf("[using capability match for '%s']\n", argv[i]);
2877 for (j = 0; j < job2.count; j++)
2878 queue_push(&job, job2.elements[j]);
2882 if (!job.count && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE || mainmode == MODE_VERIFY || repofilter.count))
2884 queue_push2(&job, SOLVER_SOLVABLE_ALL, 0);
2885 if (repofilter.count)
2886 selection_filter(pool, &job, &repofilter);
2888 queue_free(&repofilter);
2890 if (!job.count && mainmode != MODE_PATCH)
2892 printf("no package matched\n");
2896 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
2898 /* list mode, no solver needed */
2901 for (i = 0; i < job.count; i += 2)
2905 pool_job2solvables(pool, &q, job.elements[i], job.elements[i + 1]);
2906 for (j = 0; j < q.count; j++)
2908 Solvable *s = pool_id2solvable(pool, q.elements[j]);
2909 if (mainmode == MODE_INFO)
2912 printf("Name: %s\n", pool_solvable2str(pool, s));
2913 printf("Repo: %s\n", s->repo->name);
2914 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
2915 str = solvable_lookup_str(s, SOLVABLE_URL);
2917 printf("Url: %s\n", str);
2918 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
2920 printf("License: %s\n", str);
2921 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
2927 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
2929 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
2931 printf(" - %s [%s]\n", pool_solvable2str(pool, s), s->repo->name);
2933 printf(" %s\n", sum);
2940 free_repoinfos(repoinfos, nrepoinfos);
2941 solv_free(commandlinepkgs);
2943 yum_substitute(pool, 0);
2948 #if defined(SUSE) || defined(FEDORA)
2949 if (mainmode == MODE_PATCH)
2950 add_patchjobs(pool, &job);
2954 for (i = 0; i < job.count; i += 2)
2956 job.elements[i] |= mode;
2957 if (mode == SOLVER_UPDATE && pool_isemptyupdatejob(pool, job.elements[i], job.elements[i + 1]))
2958 job.elements[i] ^= SOLVER_UPDATE ^ SOLVER_INSTALL;
2960 job.elements[i] |= SOLVER_CLEANDEPS;
2962 job.elements[i] |= SOLVER_FORCEBEST;
2965 // multiversion test
2966 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae", 1));
2967 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-base", 1));
2968 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-extra", 1));
2970 queue_push2(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, NAMESPACE_LANGUAGE, 0, REL_NAMESPACE, 1));
2971 queue_push2(&job, SOLVER_ERASE|SOLVER_CLEANDEPS|SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, NAMESPACE_LANGUAGE, 0, REL_NAMESPACE, 1));
2974 #ifdef SOFTLOCKS_PATH
2975 addsoftlocks(pool, &job);
2978 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2981 solv = solver_create(pool);
2982 solver_set_flag(solv, SOLVER_FLAG_SPLITPROVIDES, 1);
2984 solver_set_flag(solv, SOLVER_FLAG_ALLOW_VENDORCHANGE, 1);
2986 if (mainmode == MODE_ERASE)
2987 solver_set_flag(solv, SOLVER_FLAG_ALLOW_UNINSTALL, 1); /* don't nag */
2988 solver_set_flag(solv, SOLVER_FLAG_BEST_OBEY_POLICY, 1);
2992 Id problem, solution;
2995 if (!solver_solve(solv, &job))
2997 pcnt = solver_problem_count(solv);
2998 printf("Found %d problems:\n", pcnt);
2999 for (problem = 1; problem <= pcnt; problem++)
3002 printf("Problem %d/%d:\n", problem, pcnt);
3003 solver_printprobleminfo(solv, problem);
3005 scnt = solver_solution_count(solv, problem);
3006 for (solution = 1; solution <= scnt; solution++)
3008 printf("Solution %d:\n", solution);
3009 solver_printsolution(solv, problem, solution);
3014 char inbuf[128], *ip;
3015 printf("Please choose a solution: ");
3018 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
3023 while (*ip == ' ' || *ip == '\t')
3025 if (*ip >= '0' && *ip <= '9')
3028 if (take >= 1 && take <= scnt)
3044 solver_take_solution(solv, problem, take, &job);
3048 trans = solver_create_transaction(solv);
3049 if (!trans->steps.count)
3051 printf("Nothing to do.\n");
3052 transaction_free(trans);
3056 free_repoinfos(repoinfos, nrepoinfos);
3057 solv_free(commandlinepkgs);
3059 yum_substitute(pool, 0);
3064 /* display transaction to the user and ask for confirmation */
3066 printf("Transaction summary:\n\n");
3067 transaction_print(trans);
3069 showdiskusagechanges(trans);
3071 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
3074 if (!yesno("OK to continue (y/n)? "))
3077 transaction_free(trans);
3081 free_repoinfos(repoinfos, nrepoinfos);
3082 solv_free(commandlinepkgs);
3084 yum_substitute(pool, 0);
3089 /* download all new packages */
3090 queue_init(&checkq);
3091 newpkgs = transaction_installedresult(trans, &checkq);
3095 int downloadsize = 0;
3096 for (i = 0; i < newpkgs; i++)
3100 p = checkq.elements[i];
3101 s = pool_id2solvable(pool, p);
3102 downloadsize += solvable_lookup_sizek(s, SOLVABLE_DOWNLOADSIZE, 0);
3104 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
3105 newpkgsfps = solv_calloc(newpkgs, sizeof(*newpkgsfps));
3106 for (i = 0; i < newpkgs; i++)
3108 unsigned int medianr;
3111 struct repoinfo *cinfo;
3112 const unsigned char *chksum;
3115 p = checkq.elements[i];
3116 s = pool_id2solvable(pool, p);
3117 if (s->repo == commandlinerepo)
3119 loc = solvable_lookup_location(s, &medianr);
3120 if (!(newpkgsfps[i] = fopen(loc, "r")))
3128 cinfo = s->repo->appdata;
3131 printf("%s: no repository information\n", s->repo->name);
3134 loc = solvable_lookup_location(s, &medianr);
3137 #if defined(ENABLE_RPMDB)
3138 if (pool->installed && pool->installed->nsolvables)
3140 if ((newpkgsfps[i] = trydeltadownload(s, cinfo, loc)) != 0)
3144 continue; /* delta worked! */
3148 #ifdef ENABLE_SUSEREPO
3149 if (cinfo->type == TYPE_SUSETAGS)
3151 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3152 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3156 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3157 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3159 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3168 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3169 /* check for file conflicts */
3173 struct fcstate fcstate;
3175 printf("Searching for file conflicts\n");
3176 queue_init(&conflicts);
3177 fcstate.rpmstate = rpm_state_create(pool, rootdir);
3178 fcstate.newpkgscnt = newpkgs;
3179 fcstate.checkq = &checkq;
3180 fcstate.newpkgsfps = newpkgsfps;
3181 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, FINDFILECONFLICTS_USE_SOLVABLEFILELIST | FINDFILECONFLICTS_CHECK_DIRALIASING | FINDFILECONFLICTS_USE_ROOTDIR, &fileconflict_cb, &fcstate);
3182 fcstate.rpmstate = rpm_state_free(fcstate.rpmstate);
3183 if (conflicts.count)
3186 for (i = 0; i < conflicts.count; i += 6)
3187 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]));
3189 if (yesno("Re-run solver (y/n/q)? "))
3191 for (i = 0; i < newpkgs; i++)
3193 fclose(newpkgsfps[i]);
3194 newpkgsfps = solv_free(newpkgsfps);
3197 pool_add_fileconflicts_deps(pool, &conflicts);
3201 queue_free(&conflicts);
3205 /* and finally commit the transaction */
3206 printf("Committing transaction:\n\n");
3207 transaction_order(trans, 0);
3208 for (i = 0; i < trans->steps.count; i++)
3210 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3211 const char *evr, *evrp, *nvra;
3218 p = trans->steps.elements[i];
3219 s = pool_id2solvable(pool, p);
3220 type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3223 case SOLVER_TRANSACTION_ERASE:
3224 printf("erase %s\n", pool_solvid2str(pool, p));
3225 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3226 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3228 /* strip epoch from evr */
3229 evr = evrp = pool_id2str(pool, s->evr);
3230 while (*evrp >= '0' && *evrp <= '9')
3232 if (evrp > evr && evrp[0] == ':' && evrp[1])
3234 nvra = pool_tmpjoin(pool, pool_id2str(pool, s->name), "-", evr);
3235 nvra = pool_tmpappend(pool, nvra, ".", pool_id2str(pool, s->arch));
3236 runrpm("-e", nvra, -1, rootdir); /* too bad that --querybynumber doesn't work */
3238 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3239 rundpkg("--remove", pool_id2str(pool, s->name), 0, rootdir);
3242 case SOLVER_TRANSACTION_INSTALL:
3243 case SOLVER_TRANSACTION_MULTIINSTALL:
3244 printf("install %s\n", pool_solvid2str(pool, p));
3245 for (j = 0; j < newpkgs; j++)
3246 if (checkq.elements[j] == p)
3248 fp = j < newpkgs ? newpkgsfps[j] : 0;
3252 lseek(fileno(fp), 0, SEEK_SET);
3253 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3254 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp), rootdir);
3256 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3257 rundpkg("--install", "/dev/fd/3", fileno(fp), rootdir);
3267 for (i = 0; i < newpkgs; i++)
3269 fclose(newpkgsfps[i]);
3270 solv_free(newpkgsfps);
3271 queue_free(&checkq);
3272 transaction_free(trans);
3276 free_repoinfos(repoinfos, nrepoinfos);
3277 solv_free(commandlinepkgs);
3279 yum_substitute(pool, 0);