2 * Copyright (c) 2009, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
8 /* solv, a little software installer demoing the sat solver library */
11 * - understands globs for package names / dependencies
12 * - understands .arch suffix
13 * - installation of commandline packages
14 * - repository data caching
15 * - on demand loading of secondary repository data
16 * - gpg and checksum verification
19 * - fastestmirror implementation
21 * things available in the library but missing from solv:
22 * - vendor policy loading
23 * - soft locks file handling
24 * - multi version handling
37 #include <sys/utsname.h>
38 #include <sys/types.h>
45 #include <sys/socket.h>
57 #include "solverdebug.h"
59 #include "repo_solv.h"
61 #include "repo_write.h"
63 #include "repo_rpmdb.h"
67 #include "repo_products.h"
68 #include "repo_rpmmd.h"
69 #include "repo_susetags.h"
70 #include "repo_repomdxml.h"
71 #include "repo_updateinfoxml.h"
72 #include "repo_deltainfoxml.h"
73 #include "repo_content.h"
74 #include "pool_fileconflicts.h"
75 #include "sat_xfopen.h"
78 # define REPOINFO_PATH "/etc/yum.repos.d"
80 # define REPOINFO_PATH "/etc/zypp/repos.d"
81 # define PRODUCTS_PATH "/etc/products.d"
82 # define SOFTLOCKS_PATH "/var/lib/zypp/SoftLocks"
85 #define SOLVCACHE_PATH "/var/cache/solv"
87 #define METADATA_EXPIRE (60 * 90)
109 unsigned char cookie[32];
110 unsigned char extcookie[32];
115 yum_substitute(Pool *pool, char *line)
118 static char *releaseevr;
119 static char *basearch;
123 sat_free(releaseevr);
130 while ((p2 = strchr(p, '$')) != 0)
132 if (!strncmp(p2, "$releasever", 11))
139 rpm_installedrpmdbids(0, "Providename", "redhat-release", &q);
142 void *handle, *state = 0;
144 handle = rpm_byrpmdbid(q.elements[0], 0, &state);
145 releaseevr = rpm_query(handle, SOLVABLE_EVR);
146 rpm_byrpmdbid(0, 0, &state);
147 if ((p = strchr(releaseevr, '-')) != 0)
152 releaseevr = strdup("?");
155 p = pool_tmpjoin(pool, line, releaseevr, p2 + 11);
156 p2 = p + (p2 - line);
158 p = p2 + strlen(releaseevr);
161 if (!strncmp(p2, "$basearch", 9))
171 basearch = strdup(un.machine);
172 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
176 p = pool_tmpjoin(pool, line, basearch, p2 + 9);
177 p2 = p + (p2 - line);
179 p = p2 + strlen(basearch);
188 #define TYPE_UNKNOWN 0
189 #define TYPE_SUSETAGS 1
191 #define TYPE_PLAINDIR 3
192 #define TYPE_DEBIAN 4
195 read_repoinfos_sort(const void *ap, const void *bp)
197 const struct repoinfo *a = ap;
198 const struct repoinfo *b = bp;
199 return strcmp(a->alias, b->alias);
205 read_repoinfos(Pool *pool, const char *reposdir, int *nrepoinfosp)
208 char buf2[4096], *kp, *vp, *kpe;
213 struct repoinfo *repoinfos = 0, *cinfo;
216 rdlen = strlen(reposdir);
217 dir = opendir(reposdir);
223 while ((ent = readdir(dir)) != 0)
225 if (ent->d_name[0] == '.')
227 l = strlen(ent->d_name);
228 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
230 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
231 if ((fp = fopen(buf, "r")) == 0)
237 while(fgets(buf2, sizeof(buf2), fp))
242 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
245 while (*kp == ' ' || *kp == '\t')
247 if (!*kp || *kp == '#')
251 kp = yum_substitute(pool, kp);
255 vp = strrchr(kp, ']');
259 repoinfos = sat_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
260 cinfo = repoinfos + nrepoinfos++;
261 memset(cinfo, 0, sizeof(*cinfo));
262 cinfo->alias = strdup(kp + 1);
263 cinfo->type = TYPE_RPMMD;
264 cinfo->autorefresh = 1;
265 cinfo->priority = 99;
267 cinfo->repo_gpgcheck = 1;
269 cinfo->metadata_expire = METADATA_EXPIRE;
274 vp = strchr(kp, '=');
277 for (kpe = vp - 1; kpe >= kp; kpe--)
278 if (*kpe != ' ' && *kpe != '\t')
283 while (*vp == ' ' || *vp == '\t')
286 if (!strcmp(kp, "name"))
287 cinfo->name = strdup(vp);
288 else if (!strcmp(kp, "enabled"))
289 cinfo->enabled = *vp == '0' ? 0 : 1;
290 else if (!strcmp(kp, "autorefresh"))
291 cinfo->autorefresh = *vp == '0' ? 0 : 1;
292 else if (!strcmp(kp, "gpgcheck"))
293 cinfo->pkgs_gpgcheck = *vp == '0' ? 0 : 1;
294 else if (!strcmp(kp, "repo_gpgcheck"))
295 cinfo->repo_gpgcheck = *vp == '0' ? 0 : 1;
296 else if (!strcmp(kp, "baseurl"))
297 cinfo->baseurl = strdup(vp);
298 else if (!strcmp(kp, "mirrorlist"))
300 if (strstr(vp, "metalink"))
301 cinfo->metalink = strdup(vp);
303 cinfo->mirrorlist = strdup(vp);
305 else if (!strcmp(kp, "path"))
307 if (vp && strcmp(vp, "/") != 0)
308 cinfo->path = strdup(vp);
310 else if (!strcmp(kp, "type"))
312 if (!strcmp(vp, "yast2"))
313 cinfo->type = TYPE_SUSETAGS;
314 else if (!strcmp(vp, "rpm-md"))
315 cinfo->type = TYPE_RPMMD;
316 else if (!strcmp(vp, "plaindir"))
317 cinfo->type = TYPE_PLAINDIR;
319 cinfo->type = TYPE_UNKNOWN;
321 else if (!strcmp(kp, "priority"))
322 cinfo->priority = atoi(vp);
323 else if (!strcmp(kp, "keeppackages"))
324 cinfo->keeppackages = *vp == '0' ? 0 : 1;
330 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
331 *nrepoinfosp = nrepoinfos;
338 read_repoinfos(Pool *pool, const char *reposdir, int *nrepoinfosp)
344 char *kp, *url, *distro;
345 struct repoinfo *repoinfos = 0, *cinfo;
350 fp = fopen("/etc/apt/sources.list", "r");
357 dir = opendir("/etc/apt/sources.list.d");
361 if ((ent = readdir(dir)) == 0)
366 if (ent->d_name[0] == '.')
368 l = strlen(ent->d_name);
369 if (l < 5 || strcmp(ent->d_name + l - 5, ".list") != 0)
371 snprintf(buf, sizeof(buf), "%s/%s", "/etc/apt/sources.list.d", ent->d_name);
372 if (!(fp = fopen(buf, "r")))
375 while(fgets(buf2, sizeof(buf2), fp))
380 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
383 while (*kp == ' ' || *kp == '\t')
385 if (!*kp || *kp == '#')
387 if (strncmp(kp, "deb", 3) != 0)
390 if (*kp != ' ' && *kp != '\t')
392 while (*kp == ' ' || *kp == '\t')
397 while (*kp && *kp != ' ' && *kp != '\t')
401 while (*kp == ' ' || *kp == '\t')
406 while (*kp && *kp != ' ' && *kp != '\t')
410 while (*kp == ' ' || *kp == '\t')
414 repoinfos = sat_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
415 cinfo = repoinfos + nrepoinfos++;
416 memset(cinfo, 0, sizeof(*cinfo));
417 cinfo->baseurl = strdup(url);
418 cinfo->alias = sat_dupjoin(url, "/", distro);
419 cinfo->name = strdup(distro);
420 cinfo->type = TYPE_DEBIAN;
422 cinfo->autorefresh = 1;
423 cinfo->repo_gpgcheck = 1;
424 cinfo->metadata_expire = METADATA_EXPIRE;
428 while (*kp == ' ' || *kp == '\t')
433 while (*kp && *kp != ' ' && *kp != '\t')
437 cinfo->components = sat_extend(cinfo->components, cinfo->ncomponents, 1, sizeof(*cinfo->components), 15);
438 cinfo->components[cinfo->ncomponents++] = strdup(compo);
444 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
445 *nrepoinfosp = nrepoinfos;
452 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
455 for (i = 0; i < nrepoinfos; i++)
457 struct repoinfo *cinfo = repoinfos + i;
458 sat_free(cinfo->name);
459 sat_free(cinfo->alias);
460 sat_free(cinfo->path);
461 sat_free(cinfo->metalink);
462 sat_free(cinfo->mirrorlist);
463 sat_free(cinfo->baseurl);
464 for (j = 0; j < cinfo->ncomponents; j++)
465 sat_free(cinfo->components[j]);
466 sat_free(cinfo->components);
477 strcpy(tmpl, "/var/tmp/solvXXXXXX");
489 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
492 const unsigned char *sum;
496 h = sat_chksum_create(chksumtype);
499 printf("%s: unknown checksum type\n", file);
502 while ((l = read(fd, buf, sizeof(buf))) > 0)
503 sat_chksum_add(h, buf, l);
504 lseek(fd, 0, SEEK_SET);
506 sum = sat_chksum_get(h, &l);
507 if (memcmp(sum, chksum, l))
509 printf("%s: checksum mismatch\n", file);
510 sat_chksum_free(h, 0);
513 sat_chksum_free(h, 0);
518 findfastest(char **urls, int nurls)
525 struct addrinfo hints, *result;;
527 fds = sat_calloc(nurls, sizeof(*fds));
528 socks = sat_calloc(nurls, sizeof(*socks));
529 for (i = 0; i < nurls; i++)
532 p = strchr(urls[i], '/');
545 if ((p2 = strchr(p, '@')) != 0)
548 if (!strncmp("https:", urls[i], 6))
550 else if (!strncmp("ftp:", urls[i], 4))
552 if ((p2 = strrchr(p, ':')) != 0)
561 sprintf(portstr, "%d", port);
562 memset(&hints, 0, sizeof(struct addrinfo));
563 hints.ai_family = AF_UNSPEC;
564 hints.ai_socktype = SOCK_STREAM;
565 hints.ai_flags = AI_NUMERICSERV;
567 if (!getaddrinfo(p, portstr, &hints, &result))
569 socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
572 fcntl(socks[i], F_SETFL, O_NONBLOCK);
573 if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1)
575 if (errno != EINPROGRESS)
582 freeaddrinfo(result);
589 for (i = j = 0; i < nurls; i++)
593 fds[j].fd = socks[i];
594 fds[j].events = POLLOUT;
602 if (poll(fds, j, 10000) <= 0)
604 i = -1; /* something is wrong */
607 for (i = 0; i < j; i++)
608 if ((fds[i].revents & POLLOUT) != 0)
611 socklen_t soel = sizeof(int);
612 if (getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, &soe, &soel) == -1 || soe != 0)
614 /* connect failed, kill socket */
615 for (j = 0; j < nurls; j++)
616 if (socks[j] == fds[i].fd)
629 i = -1; /* something is wrong, no bit was set */
632 /* now i contains the fastest fd index */
635 for (j = 0; j < nurls; j++)
636 if (socks[j] == fds[i].fd)
640 char *url0 = urls[0];
645 for (i = j = 0; i < nurls; i++)
653 findmetalinkurl(FILE *fp, unsigned char *chksump, Id *chksumtypep)
655 char buf[4096], *bp, *ep;
662 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
664 while (*bp == ' ' || *bp == '\t')
666 if (chksumtypep && !*chksumtypep && !strncmp(bp, "<hash type=\"sha256\">", 20))
671 memset(chksump, 0, 32);
672 for (i = 0; i < 64; i++)
675 if (c >= '0' && c <= '9')
676 chksump[i / 2] = chksump[i / 2] * 16 + (c - '0');
677 else if (c >= 'a' && c <= 'f')
678 chksump[i / 2] = chksump[i / 2] * 16 + (c - ('a' - 10));
679 else if (c >= 'A' && c <= 'F')
680 chksump[i / 2] = chksump[i / 2] * 16 + (c - ('A' - 10));
685 *chksumtypep = REPOKEY_TYPE_SHA256;
688 if (strncmp(bp, "<url", 4))
690 bp = strchr(bp, '>');
694 ep = strstr(bp, "repodata/repomd.xml</url>");
698 if (strncmp(bp, "http", 4))
700 urls = sat_extend(urls, nurls, 1, sizeof(*urls), 15);
701 urls[nurls++] = strdup(bp);
706 findfastest(urls, nurls > 5 ? 5 : nurls);
709 for (i = 0; i < nurls; i++)
712 ep = strchr(bp, '/');
713 if ((ep = strchr(ep + 2, '/')) != 0)
716 printf("[using mirror %s]\n", bp);
725 findmirrorlisturl(FILE *fp)
727 char buf[4096], *bp, *ep;
732 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
734 while (*bp == ' ' || *bp == '\t')
736 if (!*bp || *bp == '#')
739 while (l > 0 && (bp[l - 1] == ' ' || bp[l - 1] == '\t' || bp[l - 1] == '\n'))
741 urls = sat_extend(urls, nurls, 1, sizeof(*urls), 15);
742 urls[nurls++] = strdup(bp);
747 findfastest(urls, nurls > 5 ? 5 : nurls);
750 for (i = 0; i < nurls; i++)
753 ep = strchr(bp, '/');
754 if ((ep = strchr(ep + 2, '/')) != 0)
757 printf("[using mirror %s]\n", bp);
766 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int *badchecksump)
772 const char *baseurl = cinfo->baseurl;
776 if (!cinfo->metalink && !cinfo->mirrorlist)
778 if (file != cinfo->metalink && file != cinfo->mirrorlist)
780 FILE *fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
781 unsigned char mlchksum[32];
786 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
788 cinfo->baseurl = findmirrorlisturl(fp);
793 if (strchr(cinfo->baseurl, '$'))
795 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
796 free(cinfo->baseurl);
797 cinfo->baseurl = strdup(b);
800 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
802 chksumtype = mlchksumtype;
805 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, badchecksump);
807 snprintf(url, sizeof(url), "%s", file);
812 if (l && baseurl[l - 1] == '/')
813 snprintf(url, sizeof(url), "%s%s", baseurl, file);
815 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
818 // printf("url: %s\n", url);
819 if ((pid = fork()) == (pid_t)-1)
831 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
836 while (waitpid(pid, &status, 0) != pid)
838 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
844 lseek(fd, 0, SEEK_SET);
847 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
853 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
861 return sat_xfopen_fd(".gz", fd);
862 fcntl(fd, F_SETFD, FD_CLOEXEC);
863 return fdopen(fd, "r");
869 cleanupgpg(char *gpgdir)
872 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
874 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
876 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
878 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
880 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
886 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
895 off_t posfp, possigfp;
898 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
901 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
902 if (!(kfp = fopen(keysfile, "w")) )
908 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
912 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
913 if (!pubkey || !*pubkey)
915 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
917 if (fputc('\n', kfp) == EOF) /* Just in case... */
921 if (fclose(kfp) || !nkeys)
926 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
929 fprintf(stderr, "key import error\n");
934 posfp = lseek(fileno(fp), 0, SEEK_CUR);
935 lseek(fileno(fp), 0, SEEK_SET);
936 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
937 lseek(fileno(sigfp), 0, SEEK_SET);
938 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
939 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
940 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
942 lseek(fileno(sigfp), possigfp, SEEK_SET);
943 lseek(fileno(fp), posfp, SEEK_SET);
944 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
945 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
947 return r == 0 ? 1 : 0;
953 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
958 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));
959 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
960 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
962 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
963 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
964 return r == 0 ? 1 : 0;
969 #define CHKSUM_IDENT "1.1"
972 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
975 void *h = sat_chksum_create(chktype);
978 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
979 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
980 sat_chksum_add(h, buf, l);
982 sat_chksum_free(h, out);
986 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *out)
988 void *h = sat_chksum_create(chktype);
989 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
990 sat_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
991 sat_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
992 sat_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
993 sat_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
994 sat_chksum_free(h, out);
1006 pool_setarch(pool, un.machine);
1009 char *calccachepath(Repo *repo, const char *repoext)
1011 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
1014 p = pool_tmpjoin(repo->pool, p, "_", repoext);
1015 p = pool_tmpjoin(repo->pool, p, ".solvx", 0);
1018 p = pool_tmpjoin(repo->pool, p, ".solv", 0);
1019 q = p + strlen(SOLVCACHE_PATH) + 1;
1029 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1032 unsigned char mycookie[32];
1033 unsigned char myextcookie[32];
1034 struct repoinfo *cinfo;
1037 cinfo = repo->appdata;
1038 if (!(fp = fopen(calccachepath(repo, repoext), "r")))
1040 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1045 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1050 if (cinfo && !repoext)
1052 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1063 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1064 if (strcmp(repoext, "DL") != 0)
1065 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1068 if (repo_add_solv_flags(repo, fp, flags))
1073 if (cinfo && !repoext)
1075 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1076 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1079 futimes(fileno(fp), 0); /* try to set modification time */
1085 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1090 struct repoinfo *cinfo;
1093 cinfo = repo->appdata;
1094 mkdir(SOLVCACHE_PATH, 0755);
1095 tmpl = sat_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
1103 if (!(fp = fdopen(fd, "w")))
1112 for (i = repo->start; i < repo->end; i++)
1113 if (repo->pool->solvables[i].repo != repo)
1119 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
1121 repodata_write(info, fp, repo_write_stdkeyfilter, 0);
1124 int oldnrepodata = repo->nrepodata;
1125 repo->nrepodata = 1; /* XXX: do this right */
1126 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
1127 repo->nrepodata = oldnrepodata;
1131 if (!repoext && cinfo)
1133 if (!cinfo->extcookie[0])
1135 /* create the ext cookie and append it */
1136 /* we just need some unique ID */
1138 if (!fstat(fileno(fp), &stb))
1142 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cinfo->extcookie);
1143 for (i = 0; i < 32; i++)
1144 cinfo->extcookie[i] ^= cookie[i];
1146 if (cinfo->extcookie[0] == 0)
1147 cinfo->extcookie[0] = 1;
1149 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1157 /* append our cookie describing the metadata state */
1158 if (fwrite(cookie, 32, 1, fp) != 1)
1173 /* switch to just saved repo to activate paging and save memory */
1174 FILE *fp = fopen(tmpl, "r");
1180 repo_empty(repo, 1);
1181 if (repo_add_solv_flags(repo, fp, SOLV_ADD_NO_STUBS))
1183 /* oops, no way to recover from here */
1184 fprintf(stderr, "internal error\n");
1190 /* make sure repodata contains complete repo */
1191 /* (this is how repodata_write saves it) */
1192 repodata_extend_block(info, repo->start, repo->end - repo->start);
1193 info->state = REPODATA_LOADING;
1194 /* no need for LOCALPOOL as pool already contains ids */
1195 repo_add_solv_flags(repo, fp, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1196 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1201 if (!rename(tmpl, calccachepath(repo, repoext)))
1210 Pool *sigpool = pool_create();
1212 Repo *repo = repo_create(sigpool, "rpmdbkeys");
1213 repo_add_rpmdb_pubkeys(repo, 0, 0);
1219 /* repomd helpers */
1221 static inline const char *
1222 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1224 Pool *pool = repo->pool;
1226 const char *filename;
1231 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1232 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1233 if (dataiterator_step(&di))
1235 dataiterator_setpos_parent(&di);
1236 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1237 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1239 dataiterator_free(&di);
1240 if (filename && !*chksumtypep)
1242 printf("no %s file checksum!\n", what);
1249 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1251 Id chksumtype, handle;
1252 const unsigned char *chksum;
1253 const char *filename;
1255 filename = repomd_find(repo, what, &chksum, &chksumtype);
1258 if (!strcmp(what, "prestodelta"))
1260 handle = repodata_new_handle(data);
1261 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1262 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1263 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1264 if (!strcmp(what, "deltainfo"))
1266 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1267 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1269 if (!strcmp(what, "filelists"))
1271 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1272 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1274 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1279 /* susetags helpers */
1281 static inline const char *
1282 susetags_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, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
1292 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1293 if (dataiterator_step(&di))
1295 dataiterator_setpos_parent(&di);
1296 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
1299 dataiterator_free(&di);
1300 if (filename && !*chksumtypep)
1302 printf("no %s file checksum!\n", what);
1308 static Id susetags_langtags[] = {
1309 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
1310 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
1311 SOLVABLE_EULA, REPOKEY_TYPE_STR,
1312 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
1313 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
1314 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
1319 susetags_add_ext(Repo *repo, Repodata *data)
1321 Pool *pool = repo->pool;
1324 Id handle, filechksumtype;
1325 const unsigned char *filechksum;
1328 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
1329 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1330 while (dataiterator_step(&di))
1332 if (strncmp(di.kv.str, "packages.", 9) != 0)
1334 if (!strcmp(di.kv.str + 9, "gz"))
1336 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
1338 ext[0] = di.kv.str[9];
1339 ext[1] = di.kv.str[10];
1341 if (!strcmp(ext, "en"))
1343 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
1345 handle = repodata_new_handle(data);
1346 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
1348 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
1349 if (!strcmp(ext, "DU"))
1351 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
1352 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
1354 else if (!strcmp(ext, "FL"))
1356 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1357 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1361 for (i = 0; susetags_langtags[i]; i += 2)
1363 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
1364 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
1367 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1369 dataiterator_free(&di);
1374 iscompressed(const char *name)
1376 int l = strlen(name);
1377 return l > 3 && !strcmp(name + l - 3, ".gz") ? 1 : 0;
1384 load_stub(Pool *pool, Repodata *data, void *dp)
1386 const char *filename, *descrdir, *repomdtype;
1387 const unsigned char *filechksum;
1389 struct repoinfo *cinfo;
1394 cinfo = data->repo->appdata;
1396 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1400 ext[0] = filename[9];
1401 ext[1] = filename[10];
1404 printf("[%s:%s", data->repo->name, ext);
1406 if (usecachedrepo(data->repo, ext, cinfo->extcookie, 0))
1408 printf(" cached]\n"); fflush(stdout);
1412 printf(" fetching]\n"); fflush(stdout);
1414 defvendor = repo_lookup_id(data->repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1415 descrdir = repo_lookup_str(data->repo, SOLVID_META, SUSETAGS_DESCRDIR);
1417 descrdir = "suse/setup/descr";
1419 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1420 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1422 repo_add_susetags(data->repo, fp, defvendor, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1424 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
1428 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1431 if (!strcmp(repomdtype, "filelists"))
1433 else if (!strcmp(repomdtype, "deltainfo"))
1438 printf("[%s:%s", data->repo->name, ext);
1440 if (usecachedrepo(data->repo, ext, cinfo->extcookie, 0))
1442 printf(" cached]\n");fflush(stdout);
1445 printf(" fetching]\n"); fflush(stdout);
1446 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1448 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1449 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1451 if (!strcmp(ext, "FL"))
1452 repo_add_rpmmd(data->repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1453 else if (!strcmp(ext, "DL"))
1454 repo_add_deltainfoxml(data->repo, fp, REPO_USE_LOADING);
1456 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
1463 static unsigned char installedcookie[32];
1467 repo_add_debdb(Repo *repo, int flags)
1470 if ((fp = fopen("/var/lib/dpkg/status", "r")) == 0)
1472 perror("/var/lib/dpkg/status");
1475 repo_add_debpackages(repo, fp, flags);
1480 hexstr2bytes(unsigned char *buf, const char *str, int buflen)
1483 for (i = 0; i < buflen; i++)
1485 #define c2h(c) (((c)>='0' && (c)<='9') ? ((c)-'0') \
1486 : ((c)>='a' && (c)<='f') ? ((c)-('a'-10)) \
1487 : ((c)>='A' && (c)<='F') ? ((c)-('A'-10)) \
1498 buf[i] = (buf[i] << 4) | v;
1505 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1509 unsigned char *chksum;
1514 static char *basearch;
1526 basearch = strdup(un.machine);
1527 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
1530 binarydir = sat_dupjoin("binary-", basearch, "/");
1531 lbinarydir = strlen(binarydir);
1532 compl = strlen(comp);
1536 chksum = sat_malloc(32);
1538 while(fgets(buf, sizeof(buf), fp))
1543 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1545 if (!strncasecmp(buf, "MD5Sum:", 7))
1547 curchksumtype = REPOKEY_TYPE_MD5;
1550 if (!strncasecmp(buf, "SHA1:", 5))
1552 curchksumtype = REPOKEY_TYPE_SHA1;
1555 if (!strncasecmp(buf, "SHA256:", 7))
1557 curchksumtype = REPOKEY_TYPE_SHA256;
1569 while (*bp && *bp != ' ' && *bp != '\t')
1574 while (*bp == ' ' || *bp == '\t')
1576 while (*bp && *bp != ' ' && *bp != '\t')
1580 while (*bp == ' ' || *bp == '\t')
1583 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1586 if (strncmp(bp, binarydir, lbinarydir))
1589 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1591 if (filename && !strcmp(bp, "Packages"))
1593 if (chksumtype && sat_chksum_len(chksumtype) > sat_chksum_len(curchksumtype))
1595 if (!hexstr2bytes(chksum, ch, sat_chksum_len(curchksumtype)))
1598 filename = strdup(fn);
1599 chksumtype = curchksumtype;
1605 fn = sat_dupjoin("/", filename, 0);
1607 filename = sat_dupjoin("dists/", cinfo->name, fn);
1611 chksum = sat_free(chksum);
1613 *chksumtypep = chksumtype;
1619 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1622 struct repoinfo *cinfo;
1626 const char *filename;
1627 const unsigned char *filechksum;
1629 const char *descrdir;
1641 repo = repo_create(pool, "@System");
1643 printf("rpm database:");
1644 if (stat("/var/lib/rpm/Packages", &stb))
1645 memset(&stb, 0, sizeof(&stb));
1647 printf("dpgk database:");
1648 if (stat("/var/lib/dpkg/status", &stb))
1649 memset(&stb, 0, sizeof(&stb));
1651 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, installedcookie);
1652 if (usecachedrepo(repo, 0, installedcookie, 0))
1653 printf(" cached\n");
1660 printf(" reading\n");
1662 #ifdef PRODUCTS_PATH
1663 repo_add_products(repo, PRODUCTS_PATH, 0, REPO_NO_INTERNALIZE);
1666 if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
1668 Repo *ref = repo_create(pool, "@System.old");
1669 if (!repo_add_solv(ref, ofp))
1671 repo_add_rpmdb(repo, ref, 0, REPO_REUSE_REPODATA);
1678 repo_add_rpmdb(repo, 0, 0, REPO_REUSE_REPODATA);
1680 repo_add_debdb(repo, REPO_REUSE_REPODATA);
1682 writecachedrepo(repo, 0, 0, installedcookie);
1684 pool_set_installed(pool, repo);
1686 for (i = 0; i < nrepoinfos; i++)
1688 cinfo = repoinfos + i;
1689 if (!cinfo->enabled)
1692 repo = repo_create(pool, cinfo->alias);
1694 repo->appdata = cinfo;
1695 repo->priority = 99 - cinfo->priority;
1697 dorefresh = cinfo->autorefresh;
1698 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0), &stb) == 0)
1700 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1703 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1705 printf("repo '%s':", cinfo->alias);
1706 printf(" cached\n");
1710 switch (cinfo->type)
1713 printf("rpmmd repo '%s':", cinfo->alias);
1715 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1717 printf(" no repomd.xml file, skipped\n");
1722 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1723 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1725 printf(" cached\n");
1729 if (cinfo->repo_gpgcheck)
1731 sigfp = curlfopen(cinfo, "repodata/repomd.xml.asc", 0, 0, 0, 0);
1734 printf(" unsigned, skipped\n");
1739 sigpool = read_sigs();
1740 if (!checksig(sigpool, fp, sigfp))
1742 printf(" checksig failed, skipped\n");
1749 repo_add_repomdxml(repo, fp, 0);
1751 printf(" fetching\n");
1752 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1753 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1755 repo_add_rpmmd(repo, fp, 0, 0);
1759 break; /* hopeless */
1761 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1762 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1764 repo_add_updateinfoxml(repo, fp, 0);
1768 data = repo_add_repodata(repo, 0);
1769 if (!repomd_add_ext(repo, data, "deltainfo"))
1770 repomd_add_ext(repo, data, "prestodelta");
1771 repomd_add_ext(repo, data, "filelists");
1772 repodata_internalize(data);
1774 writecachedrepo(repo, 0, 0, cinfo->cookie);
1775 repodata_create_stubs(repo_last_repodata(repo));
1779 printf("susetags repo '%s':", cinfo->alias);
1783 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1785 printf(" no content file, skipped\n");
1790 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1791 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1793 printf(" cached\n");
1797 if (cinfo->repo_gpgcheck)
1799 sigfp = curlfopen(cinfo, "content.asc", 0, 0, 0, 0);
1802 printf(" unsigned, skipped\n");
1809 sigpool = read_sigs();
1810 if (!checksig(sigpool, fp, sigfp))
1812 printf(" checksig failed, skipped\n");
1820 repo_add_content(repo, fp, 0);
1822 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1823 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1825 descrdir = "suse/setup/descr";
1826 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1828 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1831 printf(" no packages file entry, skipped\n");
1834 printf(" fetching\n");
1835 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) == 0)
1836 break; /* hopeless */
1837 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES);
1839 /* add default language */
1840 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1842 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1845 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1847 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES);
1851 repo_internalize(repo);
1852 data = repo_add_repodata(repo, 0);
1853 susetags_add_ext(repo, data);
1854 repodata_internalize(data);
1856 writecachedrepo(repo, 0, 0, cinfo->cookie);
1857 repodata_create_stubs(repo_last_repodata(repo));
1862 printf("debian repo '%s':", cinfo->alias);
1864 filename = sat_dupjoin("dists/", cinfo->name, "/Release");
1865 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
1867 printf(" no Release file, skipped\n");
1870 free((char *)filename);
1873 sat_free((char *)filename);
1874 if (cinfo->repo_gpgcheck)
1876 filename = sat_dupjoin("dists/", cinfo->name, "/Release.gpg");
1877 sigfp = curlfopen(cinfo, filename, 0, 0, 0, 0);
1878 sat_free((char *)filename);
1881 printf(" unsigned, skipped\n");
1886 sigpool = read_sigs();
1887 if (!checksig(sigpool, fpr, sigfp))
1889 printf(" checksig failed, skipped\n");
1896 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
1897 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1899 printf(" cached\n");
1903 printf(" fetching\n");
1904 for (j = 0; j < cinfo->ncomponents; j++)
1906 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
1908 printf("[component %s not found]\n", cinfo->components[j]);
1911 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1913 repo_add_debpackages(repo, fp, 0);
1916 sat_free((char *)filechksum);
1917 sat_free((char *)filename);
1921 writecachedrepo(repo, 0, 0, cinfo->cookie);
1926 printf("unsupported repo '%s': skipped\n", cinfo->alias);
1938 str2archid(Pool *pool, char *arch)
1943 id = str2id(pool, arch, 0);
1944 if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH)
1946 if (pool->id2arch && (id > pool->lastarch || !pool->id2arch[id]))
1952 #define DEPGLOB_NAME 1
1953 #define DEPGLOB_DEP 2
1954 #define DEPGLOB_NAMEDEP 3
1957 depglob(Pool *pool, char *name, Queue *job, int what)
1960 Id id = str2id(pool, name, 0);
1965 FOR_PROVIDES(p, pp, id)
1967 Solvable *s = pool->solvables + p;
1969 if (s->name == id && (what & DEPGLOB_NAME) != 0)
1971 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
1977 if (what == DEPGLOB_NAMEDEP)
1978 printf("[using capability match for '%s']\n", name);
1979 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
1984 if (strpbrk(name, "[*?") == 0)
1987 if ((what & DEPGLOB_NAME) != 0)
1989 /* looks like a name glob. hard work. */
1990 for (p = 1; p < pool->nsolvables; p++)
1992 Solvable *s = pool->solvables + p;
1993 if (!s->repo || !pool_installable(pool, s))
1996 if (fnmatch(name, id2str(pool, id), 0) == 0)
1998 for (i = 0; i < job->count; i += 2)
1999 if (job->elements[i] == SOLVER_SOLVABLE_NAME && job->elements[i + 1] == id)
2001 if (i == job->count)
2002 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
2009 if ((what & DEPGLOB_DEP))
2011 /* looks like a dep glob. really hard work. */
2012 for (id = 1; id < pool->ss.nstrings; id++)
2014 if (!pool->whatprovides[id])
2016 if (fnmatch(name, id2str(pool, id), 0) == 0)
2018 if (!match && what == DEPGLOB_NAMEDEP)
2019 printf("[using capability match for '%s']\n", name);
2020 for (i = 0; i < job->count; i += 2)
2021 if (job->elements[i] == SOLVER_SOLVABLE_PROVIDES && job->elements[i + 1] == id)
2023 if (i == job->count)
2024 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
2035 limitrelation(Pool *pool, Queue *job, int flags, Id evr)
2039 for (i = j = 0; i < job->count; i += 2)
2041 Id select = job->elements[i] & SOLVER_SELECTMASK;
2042 if (select != SOLVER_SOLVABLE_NAME && select != SOLVER_SOLVABLE_PROVIDES)
2044 fprintf(stderr, "limitrelation only works on name/provides jobs\n");
2047 job->elements[i + 1] = rel2id(pool, job->elements[i + 1], evr, flags, 1);
2048 if (flags == REL_ARCH)
2049 job->elements[i] |= SOLVER_SETARCH;
2050 if (flags == REL_EQ && select == SOLVER_SOLVABLE_NAME && job->elements[i])
2053 const char *evrstr = id2str(pool, evr);
2054 if (!strchr(evrstr, '-'))
2055 job->elements[i] |= SOLVER_SETEV;
2058 job->elements[i] |= SOLVER_SETEVR;
2060 /* make sure we still have matches */
2061 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2065 job->elements[j] = job->elements[i];
2066 job->elements[j + 1] = job->elements[i + 1];
2070 queue_truncate(job, j);
2075 limitrelation_arch(Pool *pool, Queue *job, int flags, char *evr)
2079 if ((r = strrchr(evr, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2082 limitrelation(pool, job, REL_ARCH, archid);
2083 limitrelation(pool, job, flags, str2id(pool, evr, 1));
2087 limitrelation(pool, job, flags, str2id(pool, evr, 1));
2088 return job->count / 2;
2092 limitrepo(Pool *pool, Id repofilter, Queue *job)
2100 for (i = j = 0; i < job->count; i += 2)
2103 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2105 s = pool_id2solvable(pool, p);
2106 if (s->repo && s->repo->repoid == repofilter)
2111 /* here we assume that repo == vendor, so we also set SOLVER_SETVENDOR */
2114 job->elements[j] = SOLVER_SOLVABLE | (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO | SOLVER_NOAUTOSET;
2115 job->elements[j + 1] = mq.elements[0];
2119 job->elements[j] = SOLVER_SOLVABLE_ONE_OF | (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO;
2120 job->elements[j + 1] = pool_queuetowhatprovides(pool, &mq);
2125 queue_truncate(job, j);
2131 mkselect(Pool *pool, int mode, char *name, Queue *job)
2139 int type = strpbrk(name, "[*?") == 0 ? SEARCH_STRING : SEARCH_GLOB;
2142 dataiterator_init(&di, pool, mode == SOLVER_ERASE ? pool->installed : 0, 0, SOLVABLE_FILELIST, name, type|SEARCH_FILES|SEARCH_COMPLETE_FILELIST);
2143 while (dataiterator_step(&di))
2145 Solvable *s = pool->solvables + di.solvid;
2146 if (!s->repo || !pool_installable(pool, s))
2148 queue_push(&q, di.solvid);
2149 dataiterator_skip_solvable(&di);
2151 dataiterator_free(&di);
2154 printf("[using file list match for '%s']\n", name);
2156 queue_push2(job, SOLVER_SOLVABLE_ONE_OF, pool_queuetowhatprovides(pool, &q));
2158 queue_push2(job, SOLVER_SOLVABLE | SOLVER_NOAUTOSET, q.elements[0]);
2160 return job->count / 2;
2163 if ((r = strpbrk(name, "<=>")) != 0)
2165 /* relation case, support:
2170 int nend = r - name;
2183 while (*r && *r == ' ' && *r == '\t')
2185 while (nend && (name[nend - 1] == ' ' || name[nend -1 ] == '\t'))
2189 fprintf(stderr, "bad relation\n");
2192 oldnend = name[nend];
2194 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2196 name[nend] = oldnend;
2197 limitrelation(pool, job, rflags, str2id(pool, r, 1));
2198 return job->count / 2;
2200 if ((r2 = strrchr(name, '.')) != 0 && r2[1] && (archid = str2archid(pool, r2 + 1)) != 0)
2203 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2205 name[nend] = oldnend;
2207 limitrelation(pool, job, REL_ARCH, archid);
2208 limitrelation(pool, job, rflags, str2id(pool, r, 1));
2209 return job->count / 2;
2213 name[nend] = oldnend;
2217 /* no relation case, support:
2221 * nameglob-version.arch
2222 * nameglob-version-release
2223 * nameglob-version-release.arch
2225 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2226 return job->count / 2;
2227 if ((r = strrchr(name, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2230 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2233 limitrelation(pool, job, REL_ARCH, archid);
2234 return job->count / 2;
2238 if ((r = strrchr(name, '-')) != 0)
2241 if (depglob(pool, name, job, DEPGLOB_NAME))
2243 /* have just the version */
2244 limitrelation_arch(pool, job, REL_EQ, r + 1);
2246 return job->count / 2;
2248 if ((r2 = strrchr(name, '-')) != 0)
2253 if (depglob(pool, name, job, DEPGLOB_NAME))
2255 /* have version-release */
2256 limitrelation_arch(pool, job, REL_EQ, r + 1);
2258 return job->count / 2;
2269 yesno(const char *str)
2271 char inbuf[128], *ip;
2278 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2283 while (*ip == ' ' || *ip == '\t')
2290 if (*ip == 'y' || *ip == 'n')
2291 return *ip == 'y' ? 1 : 0;
2305 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2307 struct fcstate *fcstate = cbdata;
2315 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
2318 s = pool_id2solvable(pool, p);
2319 if (pool->installed && s->repo == pool->installed)
2321 if (!s->repo->rpmdbid)
2323 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2326 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
2328 for (i = 0; i < fcstate->newpkgscnt; i++)
2329 if (fcstate->checkq->elements[i] == p)
2331 if (i == fcstate->newpkgscnt)
2333 fp = fcstate->newpkgsfps[i];
2337 return rpm_byfp(fp, solvable2str(pool, s), &fcstate->rpmdbstate);
2342 runrpm(const char *arg, const char *name, int dupfd3)
2347 if ((pid = fork()) == (pid_t)-1)
2354 if (dupfd3 != -1 && dupfd3 != 3)
2360 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2361 if (strcmp(arg, "-e") == 0)
2362 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2364 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2368 while (waitpid(pid, &status, 0) != pid)
2372 printf("rpm failed\n");
2382 rundpkg(const char *arg, const char *name, int dupfd3)
2387 if ((pid = fork()) == (pid_t)-1)
2394 if (dupfd3 != -1 && dupfd3 != 3)
2400 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2401 if (strcmp(arg, "--install") == 0)
2402 execlp("dpkg", "dpkg", "--install", "--force", "all", name, (char *)0);
2404 execlp("dpkg", "dpkg", "--remove", "--force", "all", name, (char *)0);
2408 while (waitpid(pid, &status, 0) != pid)
2412 printf("dpkg failed\n");
2420 nscallback(Pool *pool, void *data, Id name, Id evr)
2422 if (name == NAMESPACE_PRODUCTBUDDY)
2424 /* SUSE specific hack: each product has an associated rpm */
2425 Solvable *s = pool->solvables + evr;
2428 cap = str2id(pool, pool_tmpjoin(pool, "product(", id2str(pool, s->name) + 8, ")"), 0);
2431 cap = rel2id(pool, cap, s->evr, REL_EQ, 0);
2434 FOR_PROVIDES(p, pp, cap)
2436 Solvable *ps = pool->solvables + p;
2437 if (ps->repo == s->repo && ps->arch == s->arch)
2445 #ifdef SOFTLOCKS_PATH
2448 addsoftlocks(Pool *pool, Queue *job)
2452 char *bp, *ep, buf[4096];
2454 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2456 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2458 while (*bp == ' ' || *bp == '\t')
2460 if (!*bp || *bp == '#')
2462 for (ep = bp; *ep; ep++)
2463 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2466 type = SOLVER_SOLVABLE_NAME;
2467 if (!strncmp(bp, "provides:", 9) && bp[9])
2469 type = SOLVER_SOLVABLE_PROVIDES;
2472 id = str2id(pool, bp, 1);
2473 if (pool->installed)
2475 FOR_JOB_SELECT(p, pp, type, id)
2476 if (pool->solvables[p].repo == pool->installed)
2479 continue; /* ignore, as it is already installed */
2481 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2490 rewrite_repos(Pool *pool, Id *addedfileprovides)
2495 Queue fileprovidesq;
2497 int i, j, n, nprovidedids;
2498 struct repoinfo *cinfo;
2500 map_init(&providedids, pool->ss.nstrings);
2501 queue_init(&fileprovidesq);
2502 for (nprovidedids = 0; (id = addedfileprovides[nprovidedids]) != 0; nprovidedids++)
2503 MAPSET(&providedids, id);
2506 /* make sure this repo has just one main repodata */
2507 if (!repo->nrepodata)
2509 cinfo = repo->appdata;
2510 data = repo->repodata + 0;
2511 if (data->store.pagefd == -1)
2513 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2516 for (j = 0; j < fileprovidesq.count; j++)
2517 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2519 if (n == nprovidedids)
2520 continue; /* nothing new added */
2523 for (j = 0; addedfileprovides[j]; j++)
2524 repodata_add_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, addedfileprovides[j]);
2525 repodata_internalize(data);
2526 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2528 queue_free(&fileprovidesq);
2529 map_free(&providedids);
2533 #define MODE_INSTALL 1
2534 #define MODE_ERASE 2
2535 #define MODE_UPDATE 3
2536 #define MODE_DISTUPGRADE 4
2537 #define MODE_VERIFY 5
2538 #define MODE_PATCH 6
2540 #define MODE_REPOLIST 8
2541 #define MODE_SEARCH 9
2542 #define MODE_ERASECLEAN 10
2547 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2548 fprintf(stderr, "\n");
2549 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2550 fprintf(stderr, " versions from the repositories\n");
2551 fprintf(stderr, " erase: erase installed packages\n");
2552 fprintf(stderr, " info: display package information\n");
2553 fprintf(stderr, " install: install packages\n");
2554 fprintf(stderr, " list: list packages\n");
2555 fprintf(stderr, " repos: list enabled repositories\n");
2556 fprintf(stderr, " search: search name/summary/description\n");
2557 fprintf(stderr, " update: update installed packages\n");
2558 fprintf(stderr, " verify: check dependencies of installed packages\n");
2559 fprintf(stderr, "\n");
2564 main(int argc, char **argv)
2567 Repo *commandlinerepo = 0;
2568 Id *commandlinepkgs = 0;
2570 struct repoinfo *repoinfos;
2572 int mainmode = 0, mode = 0;
2577 char inbuf[128], *ip;
2580 Id *addedfileprovides = 0;
2587 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2589 mainmode = MODE_INSTALL;
2590 mode = SOLVER_INSTALL;
2592 else if (!strcmp(argv[0], "patch"))
2594 mainmode = MODE_PATCH;
2595 mode = SOLVER_INSTALL;
2597 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2599 mainmode = MODE_ERASE;
2600 mode = SOLVER_ERASE;
2602 else if (!strcmp(argv[0], "eraseclean") || !strcmp(argv[0], "rmclean"))
2604 mainmode = MODE_ERASECLEAN;
2605 mode = SOLVER_ERASE;
2607 else if (!strcmp(argv[0], "list"))
2609 mainmode = MODE_LIST;
2612 else if (!strcmp(argv[0], "info"))
2614 mainmode = MODE_INFO;
2617 else if (!strcmp(argv[0], "search"))
2619 mainmode = MODE_SEARCH;
2622 else if (!strcmp(argv[0], "verify"))
2624 mainmode = MODE_VERIFY;
2625 mode = SOLVER_VERIFY;
2627 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2629 mainmode = MODE_UPDATE;
2630 mode = SOLVER_UPDATE;
2632 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2634 mainmode = MODE_DISTUPGRADE;
2635 mode = SOLVER_UPDATE;
2637 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2639 mainmode = MODE_REPOLIST;
2645 pool = pool_create();
2649 const char *langs[] = {"de_DE", "de", "en"};
2650 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2655 pool->obsoleteusescolors = 1;
2657 pool_setloadcallback(pool, load_stub, 0);
2658 pool->nscallback = nscallback;
2659 // pool_setdebuglevel(pool, 2);
2661 repoinfos = read_repoinfos(pool, REPOINFO_PATH, &nrepoinfos);
2663 if (mainmode == MODE_REPOLIST)
2666 for (i = 0; i < nrepoinfos; i++)
2668 struct repoinfo *cinfo = repoinfos + i;
2669 if (!cinfo->enabled)
2671 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2676 read_repos(pool, repoinfos, nrepoinfos);
2678 if (argc > 2 && !strcmp(argv[1], "-r"))
2680 const char *rname = argv[2], *rp;
2681 for (rp = rname; *rp; rp++)
2682 if (*rp <= '0' || *rp >= '9')
2686 /* repo specified by number */
2687 int rnum = atoi(rname);
2688 for (i = 0; i < nrepoinfos; i++)
2690 struct repoinfo *cinfo = repoinfos + i;
2691 if (!cinfo->enabled)
2694 repofilter = cinfo->repo->repoid;
2699 /* repo specified by alias */
2703 if (!strcasecmp(rname, repo->name))
2704 repofilter = repo->repoid;
2709 fprintf(stderr, "%s: no such repo\n", rname);
2715 if (mainmode == MODE_SEARCH)
2721 map_init(&m, pool->nsolvables);
2722 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2723 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2724 dataiterator_set_search(&di, 0, 0);
2725 while (dataiterator_step(&di))
2726 MAPSET(&m, di.solvid);
2727 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2728 dataiterator_set_search(&di, 0, 0);
2729 while (dataiterator_step(&di))
2730 MAPSET(&m, di.solvid);
2731 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2732 dataiterator_set_search(&di, 0, 0);
2733 while (dataiterator_step(&di))
2734 MAPSET(&m, di.solvid);
2735 dataiterator_free(&di);
2737 for (p = 1; p < pool->nsolvables; p++)
2739 Solvable *s = pool_id2solvable(pool, p);
2742 printf(" - %s: %s\n", solvable2str(pool, s), solvable_lookup_str(s, SOLVABLE_SUMMARY));
2749 if (mainmode == MODE_LIST || mainmode == MODE_INSTALL)
2751 for (i = 1; i < argc; i++)
2754 l = strlen(argv[i]);
2756 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2759 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2762 if (access(argv[i], R_OK))
2767 if (!commandlinepkgs)
2768 commandlinepkgs = sat_calloc(argc, sizeof(Id));
2769 if (!commandlinerepo)
2770 commandlinerepo = repo_create(pool, "@commandline");
2772 p = repo_add_rpm(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2774 p = repo_add_deb(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2776 commandlinepkgs[i] = p;
2778 if (commandlinerepo)
2779 repo_internalize(commandlinerepo);
2782 // FOR_REPOS(i, repo)
2783 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2784 addedfileprovides = 0;
2785 pool_addfileprovides_ids(pool, pool->installed, &addedfileprovides);
2786 if (addedfileprovides && *addedfileprovides)
2787 rewrite_repos(pool, addedfileprovides);
2788 sat_free(addedfileprovides);
2789 pool_createwhatprovides(pool);
2792 for (i = 1; i < argc; i++)
2797 if (commandlinepkgs && commandlinepkgs[i])
2799 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2803 if (!mkselect(pool, mode, argv[i], &job2))
2805 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2808 if (repofilter && !limitrepo(pool, repofilter, &job2))
2810 fprintf(stderr, "nothing in repo matches '%s'\n", argv[i]);
2813 for (j = 0; j < job2.count; j++)
2814 queue_push(&job, job2.elements[j]);
2818 if (!job.count && mainmode != MODE_UPDATE && mainmode != MODE_DISTUPGRADE && mainmode != MODE_VERIFY && mainmode != MODE_PATCH)
2820 printf("no package matched\n");
2827 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
2829 /* list mode, no solver needed */
2830 for (i = 0; i < job.count; i += 2)
2832 Id how = job.elements[i] & SOLVER_SELECTMASK;
2833 FOR_JOB_SELECT(p, pp, how, job.elements[i + 1])
2835 Solvable *s = pool_id2solvable(pool, p);
2836 if (mainmode == MODE_INFO)
2839 printf("Name: %s\n", solvable2str(pool, s));
2840 printf("Repo: %s\n", s->repo->name);
2841 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
2842 str = solvable_lookup_str(s, SOLVABLE_URL);
2844 printf("Url: %s\n", str);
2845 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
2847 printf("License: %s\n", str);
2848 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
2854 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
2856 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
2858 printf(" - %s [%s]\n", solvable2str(pool, s), s->repo->name);
2860 printf(" %s\n", sum);
2866 free_repoinfos(repoinfos, nrepoinfos);
2867 sat_free(commandlinepkgs);
2869 yum_substitute(pool, 0);
2874 if (mainmode == MODE_PATCH)
2880 map_init(&installedmap, pool->nsolvables);
2881 if (pool->installed)
2882 FOR_REPO_SOLVABLES(pool->installed, p, s)
2883 MAPSET(&installedmap, p);
2885 /* install all patches */
2886 for (p = 1; p < pool->nsolvables; p++)
2892 s = pool->solvables + p;
2893 if (strncmp(id2str(pool, s->name), "patch:", 6) != 0)
2895 FOR_PROVIDES(p2, pp, s->name)
2897 Solvable *s2 = pool->solvables + p2;
2898 if (s2->name != s->name)
2900 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2901 if (r < 0 || (r == 0 && p > p2))
2906 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2907 if (type && !strcmp(type, "optional"))
2909 r = solvable_trivial_installable_map(s, &installedmap, 0);
2912 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2919 queue_push2(&job, SOLVER_SOLVABLE, p);
2921 map_free(&installedmap);
2925 for (i = 0; i < job.count; i += 2)
2927 if (mode == SOLVER_UPDATE)
2929 /* make update of not installed packages an install */
2930 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
2931 if (pool->installed && pool->solvables[p].repo == pool->installed)
2935 job.elements[i] |= SOLVER_INSTALL;
2939 job.elements[i] |= mode;
2940 if (mainmode == MODE_ERASECLEAN)
2941 job.elements[i] |= SOLVER_CLEANDEPS;
2944 if (mainmode == MODE_DISTUPGRADE && allpkgs && repofilter)
2945 queue_push2(&job, SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_REPO, repofilter);
2947 // multiversion test
2948 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae", 1));
2949 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-base", 1));
2950 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-extra", 1));
2952 #ifdef SOFTLOCKS_PATH
2953 addsoftlocks(pool, &job);
2961 Id problem, solution;
2964 solv = solver_create(pool);
2965 solv->ignorealreadyrecommended = 1;
2966 solv->updatesystem = allpkgs && !repofilter && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE);
2967 solv->dosplitprovides = solv->updatesystem;
2968 solv->fixsystem = allpkgs && !repofilter && mainmode == MODE_VERIFY;
2969 if (mainmode == MODE_DISTUPGRADE && allpkgs && !repofilter)
2971 solv->distupgrade = 1;
2972 solv->allowdowngrade = 1;
2973 solv->allowarchchange = 1;
2974 solv->allowvendorchange = 1;
2976 if (mainmode == MODE_ERASE || mainmode == MODE_ERASECLEAN)
2977 solv->allowuninstall = 1; /* don't nag */
2979 solver_solve(solv, &job);
2980 if (!solv->problems.count)
2982 pcnt = solver_problem_count(solv);
2983 printf("Found %d problems:\n", pcnt);
2984 for (problem = 1; problem <= pcnt; problem++)
2987 printf("Problem %d:\n", problem);
2988 solver_printprobleminfo(solv, problem);
2990 scnt = solver_solution_count(solv, problem);
2991 for (solution = 1; solution <= scnt; solution++)
2993 printf("Solution %d:\n", solution);
2994 solver_printsolution(solv, problem, solution);
2999 printf("Please choose a solution: ");
3002 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
3007 while (*ip == ' ' || *ip == '\t')
3009 if (*ip >= '0' && *ip <= '9')
3012 if (take >= 1 && take <= scnt)
3028 solver_take_solution(solv, problem, take, &job);
3034 trans = &solv->trans;
3035 if (!trans->steps.count)
3037 printf("Nothing to do.\n");
3041 free_repoinfos(repoinfos, nrepoinfos);
3042 sat_free(commandlinepkgs);
3044 yum_substitute(pool, 0);
3049 printf("Transaction summary:\n\n");
3050 solver_printtransaction(solv);
3052 #if !defined(FEDORA) && !defined(DEBIAN)
3059 duc[1].path = "/usr/share/man";
3060 duc[2].path = "/sbin";
3061 duc[3].path = "/etc";
3062 transaction_calc_duchanges(trans, duc, 4);
3063 for (i = 0; i < 4; i++)
3064 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
3067 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
3070 if (!yesno("OK to continue (y/n)? "))
3076 free_repoinfos(repoinfos, nrepoinfos);
3077 sat_free(commandlinepkgs);
3079 yum_substitute(pool, 0);
3084 queue_init(&checkq);
3085 newpkgs = transaction_installedresult(trans, &checkq);
3090 int downloadsize = 0;
3091 for (i = 0; i < newpkgs; i++)
3095 p = checkq.elements[i];
3096 s = pool_id2solvable(pool, p);
3097 downloadsize += solvable_lookup_num(s, SOLVABLE_DOWNLOADSIZE, 0);
3099 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
3100 newpkgsfps = sat_calloc(newpkgs, sizeof(*newpkgsfps));
3101 for (i = 0; i < newpkgs; i++)
3103 unsigned int medianr;
3106 struct repoinfo *cinfo;
3107 const unsigned char *chksum;
3111 p = checkq.elements[i];
3112 s = pool_id2solvable(pool, p);
3113 if (s->repo == commandlinerepo)
3115 loc = solvable_get_location(s, &medianr);
3116 if (!(newpkgsfps[i] = fopen(loc, "r")))
3124 cinfo = s->repo->appdata;
3127 printf("%s: no repository information\n", s->repo->name);
3130 loc = solvable_get_location(s, &medianr);
3134 if (pool->installed && pool->installed->nsolvables)
3136 /* try a delta first */
3137 char *matchname = strdup(id2str(pool, s->name));
3138 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
3139 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
3140 while (dataiterator_step(&di))
3144 dataiterator_setpos_parent(&di);
3145 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
3146 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
3148 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
3149 FOR_PROVIDES(op, pp, s->name)
3151 Solvable *os = pool->solvables + op;
3152 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
3155 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
3157 /* base is installed, run sequence check */
3158 const char *seqname;
3167 seqname = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME);
3168 seqevr = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR);
3169 seqnum = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM);
3170 seq = pool_tmpjoin(pool, seqname, "-", seqevr);
3171 seq = pool_tmpjoin(pool, seq, "-", seqnum);
3173 sprintf(cmd, "/usr/bin/applydeltarpm -a %s -c -s ", id2str(pool, s->arch));
3175 sprintf(cmd, "/usr/bin/applydeltarpm -c -s ");
3177 if (system(pool_tmpjoin(pool, cmd, seq, 0)) != 0)
3178 continue; /* didn't match */
3179 /* looks good, download delta */
3181 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
3183 continue; /* no way! */
3184 dloc = pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_DIR);
3185 dloc = pool_tmpjoin(pool, dloc, "/", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_NAME));
3186 dloc = pool_tmpjoin(pool, dloc, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_EVR));
3187 dloc = pool_tmpjoin(pool, dloc, ".", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_SUFFIX));
3188 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
3190 /* got it, now reconstruct */
3191 newfd = opentmpfile();
3193 sprintf(cmd, "applydeltarpm -a %s /dev/fd/%d /dev/fd/%d", id2str(pool, s->arch), fileno(fp), newfd);
3195 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
3197 fcntl(fileno(fp), F_SETFD, 0);
3204 lseek(newfd, 0, SEEK_SET);
3206 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3207 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
3213 newpkgsfps[i] = fdopen(newfd, "r");
3218 dataiterator_free(&di);
3219 sat_free(matchname);
3226 continue; /* delta worked! */
3228 if (cinfo->type == TYPE_SUSETAGS)
3230 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3231 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3234 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3235 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3237 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3250 struct fcstate fcstate;
3252 printf("Searching for file conflicts\n");
3253 queue_init(&conflicts);
3254 fcstate.rpmdbstate = 0;
3255 fcstate.newpkgscnt = newpkgs;
3256 fcstate.checkq = &checkq;
3257 fcstate.newpkgsfps = newpkgsfps;
3258 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fileconflict_cb, &fcstate);
3259 if (conflicts.count)
3262 for (i = 0; i < conflicts.count; i += 5)
3263 printf("file %s of package %s conflicts with package %s\n", id2str(pool, conflicts.elements[i]), solvid2str(pool, conflicts.elements[i + 1]), solvid2str(pool, conflicts.elements[i + 3]));
3265 if (yesno("Re-run solver (y/n/q)? "))
3267 for (i = 0; i < newpkgs; i++)
3269 fclose(newpkgsfps[i]);
3270 newpkgsfps = sat_free(newpkgsfps);
3272 pool_add_fileconflicts_deps(pool, &conflicts);
3273 pool_createwhatprovides(pool); /* Hmm... */
3277 queue_free(&conflicts);
3281 printf("Committing transaction:\n\n");
3282 transaction_order(trans, 0);
3283 for (i = 0; i < trans->steps.count; i++)
3286 const char *evr, *evrp, *nvra;
3292 p = trans->steps.elements[i];
3293 s = pool_id2solvable(pool, p);
3294 Id type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3297 case SOLVER_TRANSACTION_ERASE:
3298 printf("erase %s\n", solvid2str(pool, p));
3300 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3302 /* strip epoch from evr */
3303 evr = evrp = id2str(pool, s->evr);
3304 while (*evrp >= '0' && *evrp <= '9')
3306 if (evrp > evr && evrp[0] == ':' && evrp[1])
3308 nvra = pool_tmpjoin(pool, id2str(pool, s->name), "-", evr);
3309 nvra = pool_tmpjoin(pool, nvra, ".", id2str(pool, s->arch));
3310 runrpm("-e", nvra, -1); /* too bad that --querybynumber doesn't work */
3312 rundpkg("--remove", id2str(pool, s->name), 0);
3315 case SOLVER_TRANSACTION_INSTALL:
3316 case SOLVER_TRANSACTION_MULTIINSTALL:
3317 printf("install %s\n", solvid2str(pool, p));
3318 for (j = 0; j < newpkgs; j++)
3319 if (checkq.elements[j] == p)
3321 fp = j < newpkgs ? newpkgsfps[j] : 0;
3325 lseek(fileno(fp), 0, SEEK_SET);
3327 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp));
3329 rundpkg("--install", "/dev/fd/3", fileno(fp));
3339 for (i = 0; i < newpkgs; i++)
3341 fclose(newpkgsfps[i]);
3342 sat_free(newpkgsfps);
3343 queue_free(&checkq);
3347 free_repoinfos(repoinfos, nrepoinfos);
3348 sat_free(commandlinepkgs);
3350 yum_substitute(pool, 0);