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 * 15)
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))
669 if (sat_hex2bin((const char **)&bp, chksump, 32) == 32)
670 *chksumtypep = REPOKEY_TYPE_SHA256;
673 if (strncmp(bp, "<url", 4))
675 bp = strchr(bp, '>');
679 ep = strstr(bp, "repodata/repomd.xml</url>");
683 if (strncmp(bp, "http", 4))
685 urls = sat_extend(urls, nurls, 1, sizeof(*urls), 15);
686 urls[nurls++] = strdup(bp);
691 findfastest(urls, nurls > 5 ? 5 : nurls);
694 for (i = 0; i < nurls; i++)
697 ep = strchr(bp, '/');
698 if ((ep = strchr(ep + 2, '/')) != 0)
701 printf("[using mirror %s]\n", bp);
710 findmirrorlisturl(FILE *fp)
712 char buf[4096], *bp, *ep;
717 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
719 while (*bp == ' ' || *bp == '\t')
721 if (!*bp || *bp == '#')
724 while (l > 0 && (bp[l - 1] == ' ' || bp[l - 1] == '\t' || bp[l - 1] == '\n'))
726 urls = sat_extend(urls, nurls, 1, sizeof(*urls), 15);
727 urls[nurls++] = strdup(bp);
732 findfastest(urls, nurls > 5 ? 5 : nurls);
735 for (i = 0; i < nurls; i++)
738 ep = strchr(bp, '/');
739 if ((ep = strchr(ep + 2, '/')) != 0)
742 printf("[using mirror %s]\n", bp);
751 iscompressed(const char *name)
753 int l = strlen(name);
754 return l > 3 && !strcmp(name + l - 3, ".gz") ? 1 : 0;
758 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int *badchecksump)
764 const char *baseurl = cinfo->baseurl;
768 if (!cinfo->metalink && !cinfo->mirrorlist)
770 if (file != cinfo->metalink && file != cinfo->mirrorlist)
772 FILE *fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
773 unsigned char mlchksum[32];
778 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
780 cinfo->baseurl = findmirrorlisturl(fp);
785 if (strchr(cinfo->baseurl, '$'))
787 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
788 free(cinfo->baseurl);
789 cinfo->baseurl = strdup(b);
792 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
794 chksumtype = mlchksumtype;
797 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, badchecksump);
799 snprintf(url, sizeof(url), "%s", file);
804 if (l && baseurl[l - 1] == '/')
805 snprintf(url, sizeof(url), "%s%s", baseurl, file);
807 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
810 // printf("url: %s\n", url);
811 if ((pid = fork()) == (pid_t)-1)
823 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
828 while (waitpid(pid, &status, 0) != pid)
830 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
836 lseek(fd, 0, SEEK_SET);
839 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
845 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
853 return sat_xfopen_fd(".gz", fd, 0);
854 fcntl(fd, F_SETFD, FD_CLOEXEC);
855 return fdopen(fd, "r");
861 cleanupgpg(char *gpgdir)
864 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
866 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
868 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
870 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
872 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
878 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
887 off_t posfp, possigfp;
890 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
893 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
894 if (!(kfp = fopen(keysfile, "w")) )
900 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
904 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
905 if (!pubkey || !*pubkey)
907 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
909 if (fputc('\n', kfp) == EOF) /* Just in case... */
913 if (fclose(kfp) || !nkeys)
918 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
921 fprintf(stderr, "key import error\n");
926 posfp = lseek(fileno(fp), 0, SEEK_CUR);
927 lseek(fileno(fp), 0, SEEK_SET);
928 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
929 lseek(fileno(sigfp), 0, SEEK_SET);
930 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
931 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
932 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
934 lseek(fileno(sigfp), possigfp, SEEK_SET);
935 lseek(fileno(fp), posfp, SEEK_SET);
936 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
937 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
939 return r == 0 ? 1 : 0;
945 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
950 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));
951 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
952 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
954 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
955 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
956 return r == 0 ? 1 : 0;
961 #define CHKSUM_IDENT "1.1"
964 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
967 void *h = sat_chksum_create(chktype);
970 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
971 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
972 sat_chksum_add(h, buf, l);
974 sat_chksum_free(h, out);
978 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *out)
980 void *h = sat_chksum_create(chktype);
981 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
982 sat_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
983 sat_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
984 sat_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
985 sat_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
986 sat_chksum_free(h, out);
998 pool_setarch(pool, un.machine);
1001 char *calccachepath(Repo *repo, const char *repoext)
1003 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
1006 p = pool_tmpappend(repo->pool, p, "_", repoext);
1007 p = pool_tmpappend(repo->pool, p, ".solvx", 0);
1010 p = pool_tmpappend(repo->pool, p, ".solv", 0);
1011 q = p + strlen(SOLVCACHE_PATH) + 1;
1021 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1024 unsigned char mycookie[32];
1025 unsigned char myextcookie[32];
1026 struct repoinfo *cinfo;
1029 cinfo = repo->appdata;
1030 if (!(fp = fopen(calccachepath(repo, repoext), "r")))
1032 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1037 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1042 if (cinfo && !repoext)
1044 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1055 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1056 if (strcmp(repoext, "DL") != 0)
1057 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1060 if (repo_add_solv_flags(repo, fp, flags))
1065 if (cinfo && !repoext)
1067 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1068 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1071 futimes(fileno(fp), 0); /* try to set modification time */
1077 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1082 struct repoinfo *cinfo;
1085 cinfo = repo->appdata;
1086 mkdir(SOLVCACHE_PATH, 0755);
1087 /* use dupjoin instead of tmpjoin because tmpl must survive repo_write */
1088 tmpl = sat_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
1096 if (!(fp = fdopen(fd, "w")))
1105 for (i = repo->start; i < repo->end; i++)
1106 if (repo->pool->solvables[i].repo != repo)
1112 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
1114 repodata_write(info, fp, repo_write_stdkeyfilter, 0);
1117 int oldnrepodata = repo->nrepodata;
1118 repo->nrepodata = 1; /* XXX: do this right */
1119 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
1120 repo->nrepodata = oldnrepodata;
1124 if (!repoext && cinfo)
1126 if (!cinfo->extcookie[0])
1128 /* create the ext cookie and append it */
1129 /* we just need some unique ID */
1131 if (!fstat(fileno(fp), &stb))
1135 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cinfo->extcookie);
1136 for (i = 0; i < 32; i++)
1137 cinfo->extcookie[i] ^= cookie[i];
1139 if (cinfo->extcookie[0] == 0)
1140 cinfo->extcookie[0] = 1;
1142 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1150 /* append our cookie describing the metadata state */
1151 if (fwrite(cookie, 32, 1, fp) != 1)
1166 /* switch to just saved repo to activate paging and save memory */
1167 FILE *fp = fopen(tmpl, "r");
1173 repo_empty(repo, 1);
1174 if (repo_add_solv_flags(repo, fp, SOLV_ADD_NO_STUBS))
1176 /* oops, no way to recover from here */
1177 fprintf(stderr, "internal error\n");
1183 /* make sure repodata contains complete repo */
1184 /* (this is how repodata_write saves it) */
1185 repodata_extend_block(info, repo->start, repo->end - repo->start);
1186 info->state = REPODATA_LOADING;
1187 /* no need for LOCALPOOL as pool already contains ids */
1188 repo_add_solv_flags(repo, fp, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1189 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1194 if (!rename(tmpl, calccachepath(repo, repoext)))
1203 Pool *sigpool = pool_create();
1205 Repo *repo = repo_create(sigpool, "rpmdbkeys");
1206 repo_add_rpmdb_pubkeys(repo, 0, 0);
1212 /* repomd helpers */
1214 static inline const char *
1215 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1217 Pool *pool = repo->pool;
1219 const char *filename;
1224 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1225 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1226 if (dataiterator_step(&di))
1228 dataiterator_setpos_parent(&di);
1229 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1230 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1232 dataiterator_free(&di);
1233 if (filename && !*chksumtypep)
1235 printf("no %s file checksum!\n", what);
1242 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1244 Id chksumtype, handle;
1245 const unsigned char *chksum;
1246 const char *filename;
1248 filename = repomd_find(repo, what, &chksum, &chksumtype);
1251 if (!strcmp(what, "prestodelta"))
1253 handle = repodata_new_handle(data);
1254 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1255 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1256 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1257 if (!strcmp(what, "deltainfo"))
1259 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1260 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1262 if (!strcmp(what, "filelists"))
1264 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1265 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1267 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1272 repomd_load_ext(Repo *repo, Repodata *data)
1274 const char *filename, *repomdtype;
1277 struct repoinfo *cinfo;
1278 const unsigned char *filechksum;
1281 cinfo = repo->appdata;
1282 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1285 if (!strcmp(repomdtype, "filelists"))
1287 else if (!strcmp(repomdtype, "deltainfo"))
1292 printf("[%s:%s", repo->name, ext);
1294 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1296 printf(" cached]\n");fflush(stdout);
1299 printf(" fetching]\n"); fflush(stdout);
1300 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1302 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1303 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1305 if (!strcmp(ext, "FL"))
1306 repo_add_rpmmd(repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1307 else if (!strcmp(ext, "DL"))
1308 repo_add_deltainfoxml(repo, fp, REPO_USE_LOADING);
1310 writecachedrepo(repo, data, ext, cinfo->extcookie);
1315 /* susetags helpers */
1317 static inline const char *
1318 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1320 Pool *pool = repo->pool;
1322 const char *filename;
1327 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
1328 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1329 if (dataiterator_step(&di))
1331 dataiterator_setpos_parent(&di);
1332 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
1335 dataiterator_free(&di);
1336 if (filename && !*chksumtypep)
1338 printf("no %s file checksum!\n", what);
1344 static Id susetags_langtags[] = {
1345 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
1346 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
1347 SOLVABLE_EULA, REPOKEY_TYPE_STR,
1348 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
1349 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
1350 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
1355 susetags_add_ext(Repo *repo, Repodata *data)
1357 Pool *pool = repo->pool;
1360 Id handle, filechksumtype;
1361 const unsigned char *filechksum;
1364 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
1365 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1366 while (dataiterator_step(&di))
1368 if (strncmp(di.kv.str, "packages.", 9) != 0)
1370 if (!strcmp(di.kv.str + 9, "gz"))
1372 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
1374 ext[0] = di.kv.str[9];
1375 ext[1] = di.kv.str[10];
1377 if (!strcmp(ext, "en"))
1379 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
1381 handle = repodata_new_handle(data);
1382 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
1384 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
1385 if (!strcmp(ext, "DU"))
1387 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
1388 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
1390 else if (!strcmp(ext, "FL"))
1392 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1393 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1397 for (i = 0; susetags_langtags[i]; i += 2)
1399 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
1400 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
1403 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1405 dataiterator_free(&di);
1409 susetags_load_ext(Repo *repo, Repodata *data)
1411 const char *filename, *descrdir;
1415 struct repoinfo *cinfo;
1416 const unsigned char *filechksum;
1419 cinfo = repo->appdata;
1420 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1424 ext[0] = filename[9];
1425 ext[1] = filename[10];
1428 printf("[%s:%s", repo->name, ext);
1430 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1432 printf(" cached]\n"); fflush(stdout);
1436 printf(" fetching]\n"); fflush(stdout);
1438 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1439 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1441 descrdir = "suse/setup/descr";
1443 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1444 if ((fp = curlfopen(cinfo, pool_tmpjoin(repo->pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1446 repo_add_susetags(repo, fp, defvendor, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1448 writecachedrepo(repo, data, ext, cinfo->extcookie);
1457 load_stub(Pool *pool, Repodata *data, void *dp)
1459 struct repoinfo *cinfo = data->repo->appdata;
1460 if (cinfo->type == TYPE_SUSETAGS)
1461 return susetags_load_ext(data->repo, data);
1462 if (cinfo->type == TYPE_RPMMD)
1463 return repomd_load_ext(data->repo, data);
1467 static unsigned char installedcookie[32];
1472 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1476 unsigned char *chksum;
1481 static char *basearch;
1493 basearch = strdup(un.machine);
1494 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
1497 binarydir = sat_dupjoin("binary-", basearch, "/");
1498 lbinarydir = strlen(binarydir);
1499 compl = strlen(comp);
1503 chksum = sat_malloc(32);
1505 while(fgets(buf, sizeof(buf), fp))
1510 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1512 if (!strncasecmp(buf, "MD5Sum:", 7))
1514 curchksumtype = REPOKEY_TYPE_MD5;
1517 if (!strncasecmp(buf, "SHA1:", 5))
1519 curchksumtype = REPOKEY_TYPE_SHA1;
1522 if (!strncasecmp(buf, "SHA256:", 7))
1524 curchksumtype = REPOKEY_TYPE_SHA256;
1536 while (*bp && *bp != ' ' && *bp != '\t')
1541 while (*bp == ' ' || *bp == '\t')
1543 while (*bp && *bp != ' ' && *bp != '\t')
1547 while (*bp == ' ' || *bp == '\t')
1550 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1553 if (strncmp(bp, binarydir, lbinarydir))
1556 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1558 unsigned char curchksum[32];
1560 if (filename && !strcmp(bp, "Packages"))
1562 curl = sat_chksum_len(curchksumtype);
1563 if (!curl || (chksumtype && sat_chksum_len(chksumtype) > curl))
1565 if (sat_hex2bin(&ch, curchksum, sizeof(curchksum)) != curl)
1568 filename = strdup(fn);
1569 chksumtype = curchksumtype;
1570 memcpy(chksum, curchksum, curl);
1576 fn = sat_dupjoin("/", filename, 0);
1578 filename = sat_dupjoin("dists/", cinfo->name, fn);
1582 chksum = sat_free(chksum);
1584 *chksumtypep = chksumtype;
1590 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1593 struct repoinfo *cinfo;
1597 const char *filename;
1598 const unsigned char *filechksum;
1600 const char *descrdir;
1612 repo = repo_create(pool, "@System");
1614 printf("rpm database:");
1615 if (stat("/var/lib/rpm/Packages", &stb))
1616 memset(&stb, 0, sizeof(&stb));
1618 printf("dpgk database:");
1619 if (stat("/var/lib/dpkg/status", &stb))
1620 memset(&stb, 0, sizeof(&stb));
1622 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, installedcookie);
1623 if (usecachedrepo(repo, 0, installedcookie, 0))
1624 printf(" cached\n");
1631 printf(" reading\n");
1633 #ifdef PRODUCTS_PATH
1634 repo_add_products(repo, PRODUCTS_PATH, 0, REPO_NO_INTERNALIZE);
1637 if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
1639 Repo *ref = repo_create(pool, "@System.old");
1640 if (!repo_add_solv(ref, ofp))
1642 repo_add_rpmdb(repo, ref, 0, REPO_REUSE_REPODATA);
1649 repo_add_rpmdb(repo, 0, 0, REPO_REUSE_REPODATA);
1651 repo_add_debdb(repo, 0, REPO_REUSE_REPODATA);
1653 writecachedrepo(repo, 0, 0, installedcookie);
1655 pool_set_installed(pool, repo);
1657 for (i = 0; i < nrepoinfos; i++)
1659 cinfo = repoinfos + i;
1660 if (!cinfo->enabled)
1663 repo = repo_create(pool, cinfo->alias);
1665 repo->appdata = cinfo;
1666 repo->priority = 99 - cinfo->priority;
1668 dorefresh = cinfo->autorefresh;
1669 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0), &stb) == 0)
1671 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1674 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1676 printf("repo '%s':", cinfo->alias);
1677 printf(" cached\n");
1681 switch (cinfo->type)
1684 printf("rpmmd repo '%s':", cinfo->alias);
1686 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1688 printf(" no repomd.xml file, skipped\n");
1693 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1694 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1696 printf(" cached\n");
1700 if (cinfo->repo_gpgcheck)
1702 sigfp = curlfopen(cinfo, "repodata/repomd.xml.asc", 0, 0, 0, 0);
1705 printf(" unsigned, skipped\n");
1710 sigpool = read_sigs();
1711 if (!checksig(sigpool, fp, sigfp))
1713 printf(" checksig failed, skipped\n");
1720 repo_add_repomdxml(repo, fp, 0);
1722 printf(" fetching\n");
1723 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1724 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1726 repo_add_rpmmd(repo, fp, 0, 0);
1730 break; /* hopeless */
1732 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1733 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1735 repo_add_updateinfoxml(repo, fp, 0);
1739 data = repo_add_repodata(repo, 0);
1740 if (!repomd_add_ext(repo, data, "deltainfo"))
1741 repomd_add_ext(repo, data, "prestodelta");
1742 repomd_add_ext(repo, data, "filelists");
1743 repodata_internalize(data);
1745 writecachedrepo(repo, 0, 0, cinfo->cookie);
1746 repodata_create_stubs(repo_last_repodata(repo));
1750 printf("susetags repo '%s':", cinfo->alias);
1754 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1756 printf(" no content file, skipped\n");
1761 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1762 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1764 printf(" cached\n");
1768 if (cinfo->repo_gpgcheck)
1770 sigfp = curlfopen(cinfo, "content.asc", 0, 0, 0, 0);
1773 printf(" unsigned, skipped\n");
1780 sigpool = read_sigs();
1781 if (!checksig(sigpool, fp, sigfp))
1783 printf(" checksig failed, skipped\n");
1791 repo_add_content(repo, fp, 0);
1793 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1794 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1796 descrdir = "suse/setup/descr";
1797 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1799 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1802 printf(" no packages file entry, skipped\n");
1805 printf(" fetching\n");
1806 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) == 0)
1807 break; /* hopeless */
1808 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES);
1810 /* add default language */
1811 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1813 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1816 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1818 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES);
1822 repo_internalize(repo);
1823 data = repo_add_repodata(repo, 0);
1824 susetags_add_ext(repo, data);
1825 repodata_internalize(data);
1827 writecachedrepo(repo, 0, 0, cinfo->cookie);
1828 repodata_create_stubs(repo_last_repodata(repo));
1833 printf("debian repo '%s':", cinfo->alias);
1835 filename = sat_dupjoin("dists/", cinfo->name, "/Release");
1836 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
1838 printf(" no Release file, skipped\n");
1841 free((char *)filename);
1844 sat_free((char *)filename);
1845 if (cinfo->repo_gpgcheck)
1847 filename = sat_dupjoin("dists/", cinfo->name, "/Release.gpg");
1848 sigfp = curlfopen(cinfo, filename, 0, 0, 0, 0);
1849 sat_free((char *)filename);
1852 printf(" unsigned, skipped\n");
1857 sigpool = read_sigs();
1858 if (!checksig(sigpool, fpr, sigfp))
1860 printf(" checksig failed, skipped\n");
1867 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
1868 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1870 printf(" cached\n");
1874 printf(" fetching\n");
1875 for (j = 0; j < cinfo->ncomponents; j++)
1877 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
1879 printf("[component %s not found]\n", cinfo->components[j]);
1882 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1884 repo_add_debpackages(repo, fp, 0);
1887 sat_free((char *)filechksum);
1888 sat_free((char *)filename);
1892 writecachedrepo(repo, 0, 0, cinfo->cookie);
1897 printf("unsupported repo '%s': skipped\n", cinfo->alias);
1909 str2archid(Pool *pool, char *arch)
1914 id = str2id(pool, arch, 0);
1915 if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH)
1917 if (pool->id2arch && (id > pool->lastarch || !pool->id2arch[id]))
1923 #define DEPGLOB_NAME 1
1924 #define DEPGLOB_DEP 2
1925 #define DEPGLOB_NAMEDEP 3
1928 depglob(Pool *pool, char *name, Queue *job, int what)
1931 Id id = str2id(pool, name, 0);
1936 FOR_PROVIDES(p, pp, id)
1938 Solvable *s = pool->solvables + p;
1940 if (s->name == id && (what & DEPGLOB_NAME) != 0)
1942 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
1948 if (what == DEPGLOB_NAMEDEP)
1949 printf("[using capability match for '%s']\n", name);
1950 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
1955 if (strpbrk(name, "[*?") == 0)
1958 if ((what & DEPGLOB_NAME) != 0)
1960 /* looks like a name glob. hard work. */
1961 for (p = 1; p < pool->nsolvables; p++)
1963 Solvable *s = pool->solvables + p;
1964 if (!s->repo || !pool_installable(pool, s))
1967 if (fnmatch(name, id2str(pool, id), 0) == 0)
1969 for (i = 0; i < job->count; i += 2)
1970 if (job->elements[i] == SOLVER_SOLVABLE_NAME && job->elements[i + 1] == id)
1972 if (i == job->count)
1973 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
1980 if ((what & DEPGLOB_DEP))
1982 /* looks like a dep glob. really hard work. */
1983 for (id = 1; id < pool->ss.nstrings; id++)
1985 if (!pool->whatprovides[id])
1987 if (fnmatch(name, id2str(pool, id), 0) == 0)
1989 if (!match && what == DEPGLOB_NAMEDEP)
1990 printf("[using capability match for '%s']\n", name);
1991 for (i = 0; i < job->count; i += 2)
1992 if (job->elements[i] == SOLVER_SOLVABLE_PROVIDES && job->elements[i + 1] == id)
1994 if (i == job->count)
1995 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
2006 limitrelation(Pool *pool, Queue *job, int flags, Id evr)
2010 for (i = j = 0; i < job->count; i += 2)
2012 Id select = job->elements[i] & SOLVER_SELECTMASK;
2013 if (select != SOLVER_SOLVABLE_NAME && select != SOLVER_SOLVABLE_PROVIDES)
2015 fprintf(stderr, "limitrelation only works on name/provides jobs\n");
2018 job->elements[i + 1] = rel2id(pool, job->elements[i + 1], evr, flags, 1);
2019 if (flags == REL_ARCH)
2020 job->elements[i] |= SOLVER_SETARCH;
2021 if (flags == REL_EQ && select == SOLVER_SOLVABLE_NAME && job->elements[i])
2024 const char *evrstr = id2str(pool, evr);
2025 if (!strchr(evrstr, '-'))
2026 job->elements[i] |= SOLVER_SETEV;
2029 job->elements[i] |= SOLVER_SETEVR;
2031 /* make sure we still have matches */
2032 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2036 job->elements[j] = job->elements[i];
2037 job->elements[j + 1] = job->elements[i + 1];
2041 queue_truncate(job, j);
2046 limitrelation_arch(Pool *pool, Queue *job, int flags, char *evr)
2050 if ((r = strrchr(evr, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2053 limitrelation(pool, job, REL_ARCH, archid);
2054 limitrelation(pool, job, flags, str2id(pool, evr, 1));
2058 limitrelation(pool, job, flags, str2id(pool, evr, 1));
2059 return job->count / 2;
2063 limitrepo(Pool *pool, Id repofilter, Queue *job)
2071 for (i = j = 0; i < job->count; i += 2)
2074 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2076 s = pool_id2solvable(pool, p);
2077 if (s->repo && s->repo->repoid == repofilter)
2082 /* here we assume that repo == vendor, so we also set SOLVER_SETVENDOR */
2085 job->elements[j] = SOLVER_SOLVABLE | (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO | SOLVER_NOAUTOSET;
2086 job->elements[j + 1] = mq.elements[0];
2090 job->elements[j] = SOLVER_SOLVABLE_ONE_OF | (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO;
2091 job->elements[j + 1] = pool_queuetowhatprovides(pool, &mq);
2096 queue_truncate(job, j);
2102 mkselect(Pool *pool, int mode, char *name, Queue *job)
2110 int type = strpbrk(name, "[*?") == 0 ? SEARCH_STRING : SEARCH_GLOB;
2113 dataiterator_init(&di, pool, mode == SOLVER_ERASE ? pool->installed : 0, 0, SOLVABLE_FILELIST, name, type|SEARCH_FILES|SEARCH_COMPLETE_FILELIST);
2114 while (dataiterator_step(&di))
2116 Solvable *s = pool->solvables + di.solvid;
2117 if (!s->repo || !pool_installable(pool, s))
2119 queue_push(&q, di.solvid);
2120 dataiterator_skip_solvable(&di);
2122 dataiterator_free(&di);
2125 printf("[using file list match for '%s']\n", name);
2127 queue_push2(job, SOLVER_SOLVABLE_ONE_OF, pool_queuetowhatprovides(pool, &q));
2129 queue_push2(job, SOLVER_SOLVABLE | SOLVER_NOAUTOSET, q.elements[0]);
2131 return job->count / 2;
2134 if ((r = strpbrk(name, "<=>")) != 0)
2136 /* relation case, support:
2141 int nend = r - name;
2154 while (*r && *r == ' ' && *r == '\t')
2156 while (nend && (name[nend - 1] == ' ' || name[nend -1 ] == '\t'))
2160 fprintf(stderr, "bad relation\n");
2163 oldnend = name[nend];
2165 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2167 name[nend] = oldnend;
2168 limitrelation(pool, job, rflags, str2id(pool, r, 1));
2169 return job->count / 2;
2171 if ((r2 = strrchr(name, '.')) != 0 && r2[1] && (archid = str2archid(pool, r2 + 1)) != 0)
2174 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2176 name[nend] = oldnend;
2178 limitrelation(pool, job, REL_ARCH, archid);
2179 limitrelation(pool, job, rflags, str2id(pool, r, 1));
2180 return job->count / 2;
2184 name[nend] = oldnend;
2188 /* no relation case, support:
2192 * nameglob-version.arch
2193 * nameglob-version-release
2194 * nameglob-version-release.arch
2196 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2197 return job->count / 2;
2198 if ((r = strrchr(name, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2201 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2204 limitrelation(pool, job, REL_ARCH, archid);
2205 return job->count / 2;
2209 if ((r = strrchr(name, '-')) != 0)
2212 if (depglob(pool, name, job, DEPGLOB_NAME))
2214 /* have just the version */
2215 limitrelation_arch(pool, job, REL_EQ, r + 1);
2217 return job->count / 2;
2219 if ((r2 = strrchr(name, '-')) != 0)
2224 if (depglob(pool, name, job, DEPGLOB_NAME))
2226 /* have version-release */
2227 limitrelation_arch(pool, job, REL_EQ, r + 1);
2229 return job->count / 2;
2240 yesno(const char *str)
2242 char inbuf[128], *ip;
2249 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2254 while (*ip == ' ' || *ip == '\t')
2261 if (*ip == 'y' || *ip == 'n')
2262 return *ip == 'y' ? 1 : 0;
2276 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2278 struct fcstate *fcstate = cbdata;
2286 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
2289 s = pool_id2solvable(pool, p);
2290 if (pool->installed && s->repo == pool->installed)
2292 if (!s->repo->rpmdbid)
2294 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2297 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
2299 for (i = 0; i < fcstate->newpkgscnt; i++)
2300 if (fcstate->checkq->elements[i] == p)
2302 if (i == fcstate->newpkgscnt)
2304 fp = fcstate->newpkgsfps[i];
2308 return rpm_byfp(fp, solvable2str(pool, s), &fcstate->rpmdbstate);
2313 runrpm(const char *arg, const char *name, int dupfd3)
2318 if ((pid = fork()) == (pid_t)-1)
2325 if (dupfd3 != -1 && dupfd3 != 3)
2331 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2332 if (strcmp(arg, "-e") == 0)
2333 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2335 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2339 while (waitpid(pid, &status, 0) != pid)
2343 printf("rpm failed\n");
2353 rundpkg(const char *arg, const char *name, int dupfd3)
2358 if ((pid = fork()) == (pid_t)-1)
2365 if (dupfd3 != -1 && dupfd3 != 3)
2371 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2372 if (strcmp(arg, "--install") == 0)
2373 execlp("dpkg", "dpkg", "--install", "--force", "all", name, (char *)0);
2375 execlp("dpkg", "dpkg", "--remove", "--force", "all", name, (char *)0);
2379 while (waitpid(pid, &status, 0) != pid)
2383 printf("dpkg failed\n");
2391 nscallback(Pool *pool, void *data, Id name, Id evr)
2393 if (name == NAMESPACE_PRODUCTBUDDY)
2395 /* SUSE specific hack: each product has an associated rpm */
2396 Solvable *s = pool->solvables + evr;
2399 cap = str2id(pool, pool_tmpjoin(pool, "product(", id2str(pool, s->name) + 8, ")"), 0);
2402 cap = rel2id(pool, cap, s->evr, REL_EQ, 0);
2405 FOR_PROVIDES(p, pp, cap)
2407 Solvable *ps = pool->solvables + p;
2408 if (ps->repo == s->repo && ps->arch == s->arch)
2416 #ifdef SOFTLOCKS_PATH
2419 addsoftlocks(Pool *pool, Queue *job)
2423 char *bp, *ep, buf[4096];
2425 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2427 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2429 while (*bp == ' ' || *bp == '\t')
2431 if (!*bp || *bp == '#')
2433 for (ep = bp; *ep; ep++)
2434 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2437 type = SOLVER_SOLVABLE_NAME;
2438 if (!strncmp(bp, "provides:", 9) && bp[9])
2440 type = SOLVER_SOLVABLE_PROVIDES;
2443 id = str2id(pool, bp, 1);
2444 if (pool->installed)
2446 FOR_JOB_SELECT(p, pp, type, id)
2447 if (pool->solvables[p].repo == pool->installed)
2450 continue; /* ignore, as it is already installed */
2452 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2461 rewrite_repos(Pool *pool, Id *addedfileprovides)
2466 Queue fileprovidesq;
2468 int i, j, n, nprovidedids;
2469 struct repoinfo *cinfo;
2471 map_init(&providedids, pool->ss.nstrings);
2472 queue_init(&fileprovidesq);
2473 for (nprovidedids = 0; (id = addedfileprovides[nprovidedids]) != 0; nprovidedids++)
2474 MAPSET(&providedids, id);
2477 /* make sure this repo has just one main repodata */
2478 if (!repo->nrepodata)
2480 cinfo = repo->appdata;
2481 data = repo->repodata + 0;
2482 if (data->store.pagefd == -1)
2484 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2487 for (j = 0; j < fileprovidesq.count; j++)
2488 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2490 if (n == nprovidedids)
2491 continue; /* nothing new added */
2494 for (j = 0; addedfileprovides[j]; j++)
2495 repodata_add_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, addedfileprovides[j]);
2496 repodata_internalize(data);
2497 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2499 queue_free(&fileprovidesq);
2500 map_free(&providedids);
2504 #define MODE_INSTALL 1
2505 #define MODE_ERASE 2
2506 #define MODE_UPDATE 3
2507 #define MODE_DISTUPGRADE 4
2508 #define MODE_VERIFY 5
2509 #define MODE_PATCH 6
2511 #define MODE_REPOLIST 8
2512 #define MODE_SEARCH 9
2513 #define MODE_ERASECLEAN 10
2518 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2519 fprintf(stderr, "\n");
2520 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2521 fprintf(stderr, " versions from the repositories\n");
2522 fprintf(stderr, " erase: erase installed packages\n");
2523 fprintf(stderr, " info: display package information\n");
2524 fprintf(stderr, " install: install packages\n");
2525 fprintf(stderr, " list: list packages\n");
2526 fprintf(stderr, " repos: list enabled repositories\n");
2527 fprintf(stderr, " search: search name/summary/description\n");
2528 fprintf(stderr, " update: update installed packages\n");
2529 fprintf(stderr, " verify: check dependencies of installed packages\n");
2530 fprintf(stderr, "\n");
2535 main(int argc, char **argv)
2538 Repo *commandlinerepo = 0;
2539 Id *commandlinepkgs = 0;
2541 struct repoinfo *repoinfos;
2543 int mainmode = 0, mode = 0;
2548 char inbuf[128], *ip;
2551 Id *addedfileprovides = 0;
2558 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2560 mainmode = MODE_INSTALL;
2561 mode = SOLVER_INSTALL;
2563 else if (!strcmp(argv[0], "patch"))
2565 mainmode = MODE_PATCH;
2566 mode = SOLVER_INSTALL;
2568 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2570 mainmode = MODE_ERASE;
2571 mode = SOLVER_ERASE;
2573 else if (!strcmp(argv[0], "eraseclean") || !strcmp(argv[0], "rmclean"))
2575 mainmode = MODE_ERASECLEAN;
2576 mode = SOLVER_ERASE;
2578 else if (!strcmp(argv[0], "list"))
2580 mainmode = MODE_LIST;
2583 else if (!strcmp(argv[0], "info"))
2585 mainmode = MODE_INFO;
2588 else if (!strcmp(argv[0], "search"))
2590 mainmode = MODE_SEARCH;
2593 else if (!strcmp(argv[0], "verify"))
2595 mainmode = MODE_VERIFY;
2596 mode = SOLVER_VERIFY;
2598 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2600 mainmode = MODE_UPDATE;
2601 mode = SOLVER_UPDATE;
2603 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2605 mainmode = MODE_DISTUPGRADE;
2606 mode = SOLVER_UPDATE;
2608 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2610 mainmode = MODE_REPOLIST;
2616 pool = pool_create();
2620 const char *langs[] = {"de_DE", "de", "en"};
2621 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2626 pool->obsoleteusescolors = 1;
2628 pool_setloadcallback(pool, load_stub, 0);
2629 pool->nscallback = nscallback;
2630 // pool_setdebuglevel(pool, 2);
2632 repoinfos = read_repoinfos(pool, REPOINFO_PATH, &nrepoinfos);
2634 if (mainmode == MODE_REPOLIST)
2637 for (i = 0; i < nrepoinfos; i++)
2639 struct repoinfo *cinfo = repoinfos + i;
2640 if (!cinfo->enabled)
2642 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2647 read_repos(pool, repoinfos, nrepoinfos);
2649 if (argc > 2 && !strcmp(argv[1], "-r"))
2651 const char *rname = argv[2], *rp;
2652 for (rp = rname; *rp; rp++)
2653 if (*rp <= '0' || *rp >= '9')
2657 /* repo specified by number */
2658 int rnum = atoi(rname);
2659 for (i = 0; i < nrepoinfos; i++)
2661 struct repoinfo *cinfo = repoinfos + i;
2662 if (!cinfo->enabled)
2665 repofilter = cinfo->repo->repoid;
2670 /* repo specified by alias */
2674 if (!strcasecmp(rname, repo->name))
2675 repofilter = repo->repoid;
2680 fprintf(stderr, "%s: no such repo\n", rname);
2686 if (mainmode == MODE_SEARCH)
2692 map_init(&m, pool->nsolvables);
2693 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2694 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2695 dataiterator_set_search(&di, 0, 0);
2696 while (dataiterator_step(&di))
2697 MAPSET(&m, di.solvid);
2698 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2699 dataiterator_set_search(&di, 0, 0);
2700 while (dataiterator_step(&di))
2701 MAPSET(&m, di.solvid);
2702 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2703 dataiterator_set_search(&di, 0, 0);
2704 while (dataiterator_step(&di))
2705 MAPSET(&m, di.solvid);
2706 dataiterator_free(&di);
2708 for (p = 1; p < pool->nsolvables; p++)
2710 Solvable *s = pool_id2solvable(pool, p);
2713 printf(" - %s: %s\n", solvable2str(pool, s), solvable_lookup_str(s, SOLVABLE_SUMMARY));
2720 if (mainmode == MODE_LIST || mainmode == MODE_INSTALL)
2722 for (i = 1; i < argc; i++)
2725 l = strlen(argv[i]);
2727 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2730 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2733 if (access(argv[i], R_OK))
2738 if (!commandlinepkgs)
2739 commandlinepkgs = sat_calloc(argc, sizeof(Id));
2740 if (!commandlinerepo)
2741 commandlinerepo = repo_create(pool, "@commandline");
2743 p = repo_add_rpm(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2745 p = repo_add_deb(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2747 commandlinepkgs[i] = p;
2749 if (commandlinerepo)
2750 repo_internalize(commandlinerepo);
2753 // FOR_REPOS(i, repo)
2754 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2755 addedfileprovides = 0;
2756 pool_addfileprovides_ids(pool, pool->installed, &addedfileprovides);
2757 if (addedfileprovides && *addedfileprovides)
2758 rewrite_repos(pool, addedfileprovides);
2759 sat_free(addedfileprovides);
2760 pool_createwhatprovides(pool);
2763 for (i = 1; i < argc; i++)
2768 if (commandlinepkgs && commandlinepkgs[i])
2770 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2774 if (!mkselect(pool, mode, argv[i], &job2))
2776 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2779 if (repofilter && !limitrepo(pool, repofilter, &job2))
2781 fprintf(stderr, "nothing in repo matches '%s'\n", argv[i]);
2784 for (j = 0; j < job2.count; j++)
2785 queue_push(&job, job2.elements[j]);
2789 if (!job.count && mainmode != MODE_UPDATE && mainmode != MODE_DISTUPGRADE && mainmode != MODE_VERIFY && mainmode != MODE_PATCH)
2791 printf("no package matched\n");
2798 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
2800 /* list mode, no solver needed */
2801 for (i = 0; i < job.count; i += 2)
2803 Id how = job.elements[i] & SOLVER_SELECTMASK;
2804 FOR_JOB_SELECT(p, pp, how, job.elements[i + 1])
2806 Solvable *s = pool_id2solvable(pool, p);
2807 if (mainmode == MODE_INFO)
2810 printf("Name: %s\n", solvable2str(pool, s));
2811 printf("Repo: %s\n", s->repo->name);
2812 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
2813 str = solvable_lookup_str(s, SOLVABLE_URL);
2815 printf("Url: %s\n", str);
2816 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
2818 printf("License: %s\n", str);
2819 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
2825 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
2827 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
2829 printf(" - %s [%s]\n", solvable2str(pool, s), s->repo->name);
2831 printf(" %s\n", sum);
2837 free_repoinfos(repoinfos, nrepoinfos);
2838 sat_free(commandlinepkgs);
2840 yum_substitute(pool, 0);
2845 if (mainmode == MODE_PATCH)
2851 map_init(&installedmap, pool->nsolvables);
2852 if (pool->installed)
2853 FOR_REPO_SOLVABLES(pool->installed, p, s)
2854 MAPSET(&installedmap, p);
2856 /* install all patches */
2857 for (p = 1; p < pool->nsolvables; p++)
2863 s = pool->solvables + p;
2864 if (strncmp(id2str(pool, s->name), "patch:", 6) != 0)
2866 FOR_PROVIDES(p2, pp, s->name)
2868 Solvable *s2 = pool->solvables + p2;
2869 if (s2->name != s->name)
2871 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2872 if (r < 0 || (r == 0 && p > p2))
2877 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2878 if (type && !strcmp(type, "optional"))
2880 r = solvable_trivial_installable_map(s, &installedmap, 0);
2883 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2890 queue_push2(&job, SOLVER_SOLVABLE, p);
2892 map_free(&installedmap);
2896 for (i = 0; i < job.count; i += 2)
2898 if (mode == SOLVER_UPDATE)
2900 /* make update of not installed packages an install */
2901 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
2902 if (pool->installed && pool->solvables[p].repo == pool->installed)
2906 job.elements[i] |= SOLVER_INSTALL;
2910 job.elements[i] |= mode;
2911 if (mainmode == MODE_ERASECLEAN)
2912 job.elements[i] |= SOLVER_CLEANDEPS;
2915 if (mainmode == MODE_DISTUPGRADE && allpkgs && repofilter)
2916 queue_push2(&job, SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_REPO, repofilter);
2918 // multiversion test
2919 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae", 1));
2920 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-base", 1));
2921 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-extra", 1));
2923 #ifdef SOFTLOCKS_PATH
2924 addsoftlocks(pool, &job);
2932 Id problem, solution;
2935 solv = solver_create(pool);
2936 solv->ignorealreadyrecommended = 1;
2937 solv->updatesystem = allpkgs && !repofilter && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE);
2938 solv->dosplitprovides = solv->updatesystem;
2939 solv->fixsystem = allpkgs && !repofilter && mainmode == MODE_VERIFY;
2940 if (mainmode == MODE_DISTUPGRADE && allpkgs && !repofilter)
2942 solv->distupgrade = 1;
2943 solv->allowdowngrade = 1;
2944 solv->allowarchchange = 1;
2945 solv->allowvendorchange = 1;
2947 if (mainmode == MODE_ERASE || mainmode == MODE_ERASECLEAN)
2948 solv->allowuninstall = 1; /* don't nag */
2950 solver_solve(solv, &job);
2951 if (!solv->problems.count)
2953 pcnt = solver_problem_count(solv);
2954 printf("Found %d problems:\n", pcnt);
2955 for (problem = 1; problem <= pcnt; problem++)
2958 printf("Problem %d:\n", problem);
2959 solver_printprobleminfo(solv, problem);
2961 scnt = solver_solution_count(solv, problem);
2962 for (solution = 1; solution <= scnt; solution++)
2964 printf("Solution %d:\n", solution);
2965 solver_printsolution(solv, problem, solution);
2970 printf("Please choose a solution: ");
2973 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2978 while (*ip == ' ' || *ip == '\t')
2980 if (*ip >= '0' && *ip <= '9')
2983 if (take >= 1 && take <= scnt)
2999 solver_take_solution(solv, problem, take, &job);
3005 trans = &solv->trans;
3006 if (!trans->steps.count)
3008 printf("Nothing to do.\n");
3012 free_repoinfos(repoinfos, nrepoinfos);
3013 sat_free(commandlinepkgs);
3015 yum_substitute(pool, 0);
3020 printf("Transaction summary:\n\n");
3021 solver_printtransaction(solv);
3023 #if !defined(FEDORA) && !defined(DEBIAN)
3030 duc[1].path = "/usr/share/man";
3031 duc[2].path = "/sbin";
3032 duc[3].path = "/etc";
3033 transaction_calc_duchanges(trans, duc, 4);
3034 for (i = 0; i < 4; i++)
3035 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
3038 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
3041 if (!yesno("OK to continue (y/n)? "))
3047 free_repoinfos(repoinfos, nrepoinfos);
3048 sat_free(commandlinepkgs);
3050 yum_substitute(pool, 0);
3055 queue_init(&checkq);
3056 newpkgs = transaction_installedresult(trans, &checkq);
3061 int downloadsize = 0;
3062 for (i = 0; i < newpkgs; i++)
3066 p = checkq.elements[i];
3067 s = pool_id2solvable(pool, p);
3068 downloadsize += solvable_lookup_num(s, SOLVABLE_DOWNLOADSIZE, 0);
3070 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
3071 newpkgsfps = sat_calloc(newpkgs, sizeof(*newpkgsfps));
3072 for (i = 0; i < newpkgs; i++)
3074 unsigned int medianr;
3077 struct repoinfo *cinfo;
3078 const unsigned char *chksum;
3082 p = checkq.elements[i];
3083 s = pool_id2solvable(pool, p);
3084 if (s->repo == commandlinerepo)
3086 loc = solvable_get_location(s, &medianr);
3087 if (!(newpkgsfps[i] = fopen(loc, "r")))
3095 cinfo = s->repo->appdata;
3098 printf("%s: no repository information\n", s->repo->name);
3101 loc = solvable_get_location(s, &medianr);
3105 if (pool->installed && pool->installed->nsolvables)
3107 /* try a delta first */
3108 char *matchname = strdup(id2str(pool, s->name));
3109 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
3110 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
3111 while (dataiterator_step(&di))
3115 dataiterator_setpos_parent(&di);
3116 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
3117 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
3119 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
3120 FOR_PROVIDES(op, pp, s->name)
3122 Solvable *os = pool->solvables + op;
3123 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
3126 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
3128 /* base is installed, run sequence check */
3129 const char *seqname;
3138 seqname = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME);
3139 seqevr = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR);
3140 seqnum = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM);
3141 seq = pool_tmpjoin(pool, seqname, "-", seqevr);
3142 seq = pool_tmpappend(pool, seq, "-", seqnum);
3144 sprintf(cmd, "/usr/bin/applydeltarpm -a %s -c -s ", id2str(pool, s->arch));
3146 sprintf(cmd, "/usr/bin/applydeltarpm -c -s ");
3148 if (system(pool_tmpjoin(pool, cmd, seq, 0)) != 0)
3149 continue; /* didn't match */
3150 /* looks good, download delta */
3152 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
3154 continue; /* no way! */
3155 dloc = pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_DIR);
3156 dloc = pool_tmpappend(pool, dloc, "/", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_NAME));
3157 dloc = pool_tmpappend(pool, dloc, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_EVR));
3158 dloc = pool_tmpappend(pool, dloc, ".", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_SUFFIX));
3159 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
3161 /* got it, now reconstruct */
3162 newfd = opentmpfile();
3164 sprintf(cmd, "applydeltarpm -a %s /dev/fd/%d /dev/fd/%d", id2str(pool, s->arch), fileno(fp), newfd);
3166 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
3168 fcntl(fileno(fp), F_SETFD, 0);
3175 lseek(newfd, 0, SEEK_SET);
3177 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3178 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
3184 newpkgsfps[i] = fdopen(newfd, "r");
3189 dataiterator_free(&di);
3190 sat_free(matchname);
3197 continue; /* delta worked! */
3199 if (cinfo->type == TYPE_SUSETAGS)
3201 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3202 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3205 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3206 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3208 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3221 struct fcstate fcstate;
3223 printf("Searching for file conflicts\n");
3224 queue_init(&conflicts);
3225 fcstate.rpmdbstate = 0;
3226 fcstate.newpkgscnt = newpkgs;
3227 fcstate.checkq = &checkq;
3228 fcstate.newpkgsfps = newpkgsfps;
3229 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fileconflict_cb, &fcstate);
3230 if (conflicts.count)
3233 for (i = 0; i < conflicts.count; i += 5)
3234 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]));
3236 if (yesno("Re-run solver (y/n/q)? "))
3238 for (i = 0; i < newpkgs; i++)
3240 fclose(newpkgsfps[i]);
3241 newpkgsfps = sat_free(newpkgsfps);
3243 pool_add_fileconflicts_deps(pool, &conflicts);
3244 pool_createwhatprovides(pool); /* Hmm... */
3248 queue_free(&conflicts);
3252 printf("Committing transaction:\n\n");
3253 transaction_order(trans, 0);
3254 for (i = 0; i < trans->steps.count; i++)
3257 const char *evr, *evrp, *nvra;
3263 p = trans->steps.elements[i];
3264 s = pool_id2solvable(pool, p);
3265 Id type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3268 case SOLVER_TRANSACTION_ERASE:
3269 printf("erase %s\n", solvid2str(pool, p));
3271 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3273 /* strip epoch from evr */
3274 evr = evrp = id2str(pool, s->evr);
3275 while (*evrp >= '0' && *evrp <= '9')
3277 if (evrp > evr && evrp[0] == ':' && evrp[1])
3279 nvra = pool_tmpjoin(pool, id2str(pool, s->name), "-", evr);
3280 nvra = pool_tmpappend(pool, nvra, ".", id2str(pool, s->arch));
3281 runrpm("-e", nvra, -1); /* too bad that --querybynumber doesn't work */
3283 rundpkg("--remove", id2str(pool, s->name), 0);
3286 case SOLVER_TRANSACTION_INSTALL:
3287 case SOLVER_TRANSACTION_MULTIINSTALL:
3288 printf("install %s\n", solvid2str(pool, p));
3289 for (j = 0; j < newpkgs; j++)
3290 if (checkq.elements[j] == p)
3292 fp = j < newpkgs ? newpkgsfps[j] : 0;
3296 lseek(fileno(fp), 0, SEEK_SET);
3298 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp));
3300 rundpkg("--install", "/dev/fd/3", fileno(fp));
3310 for (i = 0; i < newpkgs; i++)
3312 fclose(newpkgsfps[i]);
3313 sat_free(newpkgsfps);
3314 queue_free(&checkq);
3318 free_repoinfos(repoinfos, nrepoinfos);
3319 sat_free(commandlinepkgs);
3321 yum_substitute(pool, 0);