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"
60 #include "selection.h"
62 #include "repo_write.h"
64 #include "repo_rpmdb.h"
65 #include "pool_fileconflicts.h"
71 #include "repo_rpmmd.h"
72 #include "repo_repomdxml.h"
73 #include "repo_updateinfoxml.h"
74 #include "repo_deltainfoxml.h"
76 #ifdef ENABLE_SUSEREPO
77 #include "repo_products.h"
78 #include "repo_susetags.h"
79 #include "repo_content.h"
81 #include "solv_xfopen.h"
84 # define REPOINFO_PATH "/etc/yum.repos.d"
87 # define REPOINFO_PATH "/etc/zypp/repos.d"
88 # define PRODUCTS_PATH "/etc/products.d"
89 # define SOFTLOCKS_PATH "/var/lib/zypp/SoftLocks"
92 #define SOLVCACHE_PATH "/var/cache/solv"
94 #define METADATA_EXPIRE (60 * 15)
116 unsigned char cookie[32];
117 unsigned char extcookie[32];
123 yum_substitute(Pool *pool, char *line)
126 static char *releaseevr;
127 static char *basearch;
131 solv_free(releaseevr);
138 while ((p2 = strchr(p, '$')) != 0)
140 if (!strncmp(p2, "$releasever", 11))
145 const char *rootdir = pool_get_rootdir(pool);
148 rpm_installedrpmdbids(rootdir, "Providename", "redhat-release", &q);
151 void *handle, *state = 0;
153 handle = rpm_byrpmdbid(q.elements[0], rootdir, &state);
154 releaseevr = rpm_query(handle, SOLVABLE_EVR);
155 rpm_byrpmdbid(0, 0, &state);
156 if ((p = strchr(releaseevr, '-')) != 0)
162 fprintf(stderr, "no installed package provides 'redhat-release', cannot determine $releasever\n");
167 p = pool_tmpjoin(pool, line, releaseevr, p2 + 11);
168 p2 = p + (p2 - line);
170 p = p2 + strlen(releaseevr);
173 if (!strncmp(p2, "$basearch", 9))
183 basearch = strdup(un.machine);
184 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
188 p = pool_tmpjoin(pool, line, basearch, p2 + 9);
189 p2 = p + (p2 - line);
191 p = p2 + strlen(basearch);
200 #define TYPE_UNKNOWN 0
201 #define TYPE_SUSETAGS 1
203 #define TYPE_PLAINDIR 3
204 #define TYPE_DEBIAN 4
208 read_repoinfos_sort(const void *ap, const void *bp)
210 const struct repoinfo *a = ap;
211 const struct repoinfo *b = bp;
212 return strcmp(a->alias, b->alias);
216 #if defined(SUSE) || defined(FEDORA)
219 read_repoinfos(Pool *pool, int *nrepoinfosp)
221 const char *reposdir = REPOINFO_PATH;
223 char buf2[4096], *kp, *vp, *kpe;
228 struct repoinfo *repoinfos = 0, *cinfo;
231 rdlen = strlen(reposdir);
232 dir = opendir(reposdir);
238 while ((ent = readdir(dir)) != 0)
240 if (ent->d_name[0] == '.')
242 l = strlen(ent->d_name);
243 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
245 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
246 if ((fp = fopen(buf, "r")) == 0)
252 while(fgets(buf2, sizeof(buf2), fp))
257 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
260 while (*kp == ' ' || *kp == '\t')
262 if (!*kp || *kp == '#')
266 kp = yum_substitute(pool, kp);
270 vp = strrchr(kp, ']');
274 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
275 cinfo = repoinfos + nrepoinfos++;
276 memset(cinfo, 0, sizeof(*cinfo));
277 cinfo->alias = strdup(kp + 1);
278 cinfo->type = TYPE_RPMMD;
279 cinfo->autorefresh = 1;
280 cinfo->priority = 99;
282 cinfo->repo_gpgcheck = 1;
284 cinfo->metadata_expire = METADATA_EXPIRE;
289 vp = strchr(kp, '=');
292 for (kpe = vp - 1; kpe >= kp; kpe--)
293 if (*kpe != ' ' && *kpe != '\t')
298 while (*vp == ' ' || *vp == '\t')
301 if (!strcmp(kp, "name"))
302 cinfo->name = strdup(vp);
303 else if (!strcmp(kp, "enabled"))
304 cinfo->enabled = *vp == '0' ? 0 : 1;
305 else if (!strcmp(kp, "autorefresh"))
306 cinfo->autorefresh = *vp == '0' ? 0 : 1;
307 else if (!strcmp(kp, "gpgcheck"))
308 cinfo->pkgs_gpgcheck = *vp == '0' ? 0 : 1;
309 else if (!strcmp(kp, "repo_gpgcheck"))
310 cinfo->repo_gpgcheck = *vp == '0' ? 0 : 1;
311 else if (!strcmp(kp, "baseurl"))
312 cinfo->baseurl = strdup(vp);
313 else if (!strcmp(kp, "mirrorlist"))
315 if (strstr(vp, "metalink"))
316 cinfo->metalink = strdup(vp);
318 cinfo->mirrorlist = strdup(vp);
320 else if (!strcmp(kp, "path"))
322 if (vp && strcmp(vp, "/") != 0)
323 cinfo->path = strdup(vp);
325 else if (!strcmp(kp, "type"))
327 if (!strcmp(vp, "yast2"))
328 cinfo->type = TYPE_SUSETAGS;
329 else if (!strcmp(vp, "rpm-md"))
330 cinfo->type = TYPE_RPMMD;
331 else if (!strcmp(vp, "plaindir"))
332 cinfo->type = TYPE_PLAINDIR;
334 cinfo->type = TYPE_UNKNOWN;
336 else if (!strcmp(kp, "priority"))
337 cinfo->priority = atoi(vp);
338 else if (!strcmp(kp, "keeppackages"))
339 cinfo->keeppackages = *vp == '0' ? 0 : 1;
345 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
346 *nrepoinfosp = nrepoinfos;
355 read_repoinfos(Pool *pool, int *nrepoinfosp)
361 char *kp, *url, *distro;
362 struct repoinfo *repoinfos = 0, *cinfo;
367 fp = fopen("/etc/apt/sources.list", "r");
374 dir = opendir("/etc/apt/sources.list.d");
378 if ((ent = readdir(dir)) == 0)
383 if (ent->d_name[0] == '.')
385 l = strlen(ent->d_name);
386 if (l < 5 || strcmp(ent->d_name + l - 5, ".list") != 0)
388 snprintf(buf, sizeof(buf), "%s/%s", "/etc/apt/sources.list.d", ent->d_name);
389 if (!(fp = fopen(buf, "r")))
392 while(fgets(buf2, sizeof(buf2), fp))
397 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
400 while (*kp == ' ' || *kp == '\t')
402 if (!*kp || *kp == '#')
404 if (strncmp(kp, "deb", 3) != 0)
407 if (*kp != ' ' && *kp != '\t')
409 while (*kp == ' ' || *kp == '\t')
414 while (*kp && *kp != ' ' && *kp != '\t')
418 while (*kp == ' ' || *kp == '\t')
423 while (*kp && *kp != ' ' && *kp != '\t')
427 while (*kp == ' ' || *kp == '\t')
431 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
432 cinfo = repoinfos + nrepoinfos++;
433 memset(cinfo, 0, sizeof(*cinfo));
434 cinfo->baseurl = strdup(url);
435 cinfo->alias = solv_dupjoin(url, "/", distro);
436 cinfo->name = strdup(distro);
437 cinfo->type = TYPE_DEBIAN;
439 cinfo->autorefresh = 1;
440 cinfo->repo_gpgcheck = 1;
441 cinfo->metadata_expire = METADATA_EXPIRE;
445 while (*kp == ' ' || *kp == '\t')
450 while (*kp && *kp != ' ' && *kp != '\t')
454 cinfo->components = solv_extend(cinfo->components, cinfo->ncomponents, 1, sizeof(*cinfo->components), 15);
455 cinfo->components[cinfo->ncomponents++] = strdup(compo);
461 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
462 *nrepoinfosp = nrepoinfos;
470 read_repoinfos(Pool *pool, int *nrepoinfosp)
479 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
482 for (i = 0; i < nrepoinfos; i++)
484 struct repoinfo *cinfo = repoinfos + i;
485 solv_free(cinfo->name);
486 solv_free(cinfo->alias);
487 solv_free(cinfo->path);
488 solv_free(cinfo->metalink);
489 solv_free(cinfo->mirrorlist);
490 solv_free(cinfo->baseurl);
491 for (j = 0; j < cinfo->ncomponents; j++)
492 solv_free(cinfo->components[j]);
493 solv_free(cinfo->components);
495 solv_free(repoinfos);
504 strcpy(tmpl, "/var/tmp/solvXXXXXX");
516 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
519 const unsigned char *sum;
523 h = solv_chksum_create(chksumtype);
526 printf("%s: unknown checksum type\n", file);
529 while ((l = read(fd, buf, sizeof(buf))) > 0)
530 solv_chksum_add(h, buf, l);
531 lseek(fd, 0, SEEK_SET);
533 sum = solv_chksum_get(h, &l);
534 if (memcmp(sum, chksum, l))
536 printf("%s: checksum mismatch\n", file);
537 solv_chksum_free(h, 0);
540 solv_chksum_free(h, 0);
545 findfastest(char **urls, int nurls)
552 struct addrinfo hints, *result;;
554 fds = solv_calloc(nurls, sizeof(*fds));
555 socks = solv_calloc(nurls, sizeof(*socks));
556 for (i = 0; i < nurls; i++)
559 p = strchr(urls[i], '/');
572 if ((p2 = strchr(p, '@')) != 0)
575 if (!strncmp("https:", urls[i], 6))
577 else if (!strncmp("ftp:", urls[i], 4))
579 if ((p2 = strrchr(p, ':')) != 0)
588 sprintf(portstr, "%d", port);
589 memset(&hints, 0, sizeof(struct addrinfo));
590 hints.ai_family = AF_UNSPEC;
591 hints.ai_socktype = SOCK_STREAM;
592 hints.ai_flags = AI_NUMERICSERV;
594 if (!getaddrinfo(p, portstr, &hints, &result))
596 socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
599 fcntl(socks[i], F_SETFL, O_NONBLOCK);
600 if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1)
602 if (errno != EINPROGRESS)
609 freeaddrinfo(result);
616 for (i = j = 0; i < nurls; i++)
620 fds[j].fd = socks[i];
621 fds[j].events = POLLOUT;
629 if (poll(fds, j, 10000) <= 0)
631 i = -1; /* something is wrong */
634 for (i = 0; i < j; i++)
635 if ((fds[i].revents & POLLOUT) != 0)
638 socklen_t soel = sizeof(int);
639 if (getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, &soe, &soel) == -1 || soe != 0)
641 /* connect failed, kill socket */
642 for (j = 0; j < nurls; j++)
643 if (socks[j] == fds[i].fd)
656 i = -1; /* something is wrong, no bit was set */
659 /* now i contains the fastest fd index */
662 for (j = 0; j < nurls; j++)
663 if (socks[j] == fds[i].fd)
667 char *url0 = urls[0];
672 for (i = j = 0; i < nurls; i++)
680 findmetalinkurl(FILE *fp, unsigned char *chksump, Id *chksumtypep)
682 char buf[4096], *bp, *ep;
689 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
691 while (*bp == ' ' || *bp == '\t')
693 if (chksumtypep && !*chksumtypep && !strncmp(bp, "<hash type=\"sha256\">", 20))
696 if (solv_hex2bin((const char **)&bp, chksump, 32) == 32)
697 *chksumtypep = REPOKEY_TYPE_SHA256;
700 if (strncmp(bp, "<url", 4))
702 bp = strchr(bp, '>');
706 ep = strstr(bp, "repodata/repomd.xml</url>");
710 if (strncmp(bp, "http", 4))
712 urls = solv_extend(urls, nurls, 1, sizeof(*urls), 15);
713 urls[nurls++] = strdup(bp);
718 findfastest(urls, nurls > 5 ? 5 : nurls);
721 for (i = 0; i < nurls; i++)
724 ep = strchr(bp, '/');
725 if ((ep = strchr(ep + 2, '/')) != 0)
728 printf("[using mirror %s]\n", bp);
737 findmirrorlisturl(FILE *fp)
739 char buf[4096], *bp, *ep;
744 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
746 while (*bp == ' ' || *bp == '\t')
748 if (!*bp || *bp == '#')
751 while (l > 0 && (bp[l - 1] == ' ' || bp[l - 1] == '\t' || bp[l - 1] == '\n'))
753 urls = solv_extend(urls, nurls, 1, sizeof(*urls), 15);
754 urls[nurls++] = strdup(bp);
759 findfastest(urls, nurls > 5 ? 5 : nurls);
762 for (i = 0; i < nurls; i++)
765 ep = strchr(bp, '/');
766 if ((ep = strchr(ep + 2, '/')) != 0)
769 printf("[using mirror %s]\n", bp);
778 iscompressed(const char *name)
780 return solv_xfopen_iscompressed(name) != 0;
784 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int markincomplete)
791 const char *baseurl = cinfo->baseurl;
795 if (!cinfo->metalink && !cinfo->mirrorlist)
797 if (file != cinfo->metalink && file != cinfo->mirrorlist)
799 unsigned char mlchksum[32];
801 fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
806 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
808 cinfo->baseurl = findmirrorlisturl(fp);
813 if (strchr(cinfo->baseurl, '$'))
815 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
816 free(cinfo->baseurl);
817 cinfo->baseurl = strdup(b);
820 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
822 chksumtype = mlchksumtype;
825 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, markincomplete);
827 snprintf(url, sizeof(url), "%s", file);
832 if (l && baseurl[l - 1] == '/')
833 snprintf(url, sizeof(url), "%s%s", baseurl, file);
835 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
838 // printf("url: %s\n", url);
839 if ((pid = fork()) == (pid_t)-1)
851 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
856 while (waitpid(pid, &status, 0) != pid)
858 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
864 lseek(fd, 0, SEEK_SET);
867 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
869 cinfo->incomplete = 1;
873 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
876 cinfo->incomplete = 1;
880 fcntl(fd, F_SETFD, FD_CLOEXEC);
883 if (solv_xfopen_iscompressed(file) < 0)
885 printf("%s: unsupported compression\n", file);
887 cinfo->incomplete = 1;
891 fp = solv_xfopen_fd(file, fd, "r");
894 fp = fdopen(fd, "r");
903 cleanupgpg(char *gpgdir)
906 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
908 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
910 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
912 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
914 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
920 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
929 off_t posfp, possigfp;
932 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
935 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
936 if (!(kfp = fopen(keysfile, "w")) )
942 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
946 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
947 if (!pubkey || !*pubkey)
949 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
951 if (fputc('\n', kfp) == EOF) /* Just in case... */
955 if (fclose(kfp) || !nkeys)
960 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
963 fprintf(stderr, "key import error\n");
968 posfp = lseek(fileno(fp), 0, SEEK_CUR);
969 lseek(fileno(fp), 0, SEEK_SET);
970 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
971 lseek(fileno(sigfp), 0, SEEK_SET);
972 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
973 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
974 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
976 lseek(fileno(sigfp), possigfp, SEEK_SET);
977 lseek(fileno(fp), posfp, SEEK_SET);
978 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
979 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
981 return r == 0 ? 1 : 0;
987 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
992 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));
993 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
994 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
996 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
997 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
998 return r == 0 ? 1 : 0;
1006 Pool *sigpool = pool_create();
1007 #if defined(ENABLE_RPMDB_PUBKEY)
1008 Repo *repo = repo_create(sigpool, "rpmdbkeys");
1009 repo_add_rpmdb_pubkeys(repo, 0);
1015 downloadchecksig(struct repoinfo *cinfo, FILE *fp, const char *sigurl, Pool **sigpool)
1018 sigfp = curlfopen(cinfo, sigurl, 0, 0, 0, 0);
1021 printf(" unsigned, skipped\n");
1025 *sigpool = read_sigs();
1026 if (!checksig(*sigpool, fp, sigfp))
1028 printf(" checksig failed, skipped\n");
1036 #define CHKSUM_IDENT "1.1"
1039 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
1042 void *h = solv_chksum_create(chktype);
1045 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1046 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
1047 solv_chksum_add(h, buf, l);
1049 solv_chksum_free(h, out);
1053 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *cookie, unsigned char *out)
1055 void *h = solv_chksum_create(chktype);
1056 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1058 solv_chksum_add(h, cookie, 32);
1059 solv_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
1060 solv_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
1061 solv_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
1062 solv_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
1063 solv_chksum_free(h, out);
1075 pool_setarch(pool, un.machine);
1078 char *calccachepath(Repo *repo, const char *repoext)
1080 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
1083 p = pool_tmpappend(repo->pool, p, "_", repoext);
1084 p = pool_tmpappend(repo->pool, p, ".solvx", 0);
1087 p = pool_tmpappend(repo->pool, p, ".solv", 0);
1088 q = p + strlen(SOLVCACHE_PATH) + 1;
1098 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1101 unsigned char mycookie[32];
1102 unsigned char myextcookie[32];
1103 struct repoinfo *cinfo;
1106 cinfo = repo->appdata;
1107 if (!(fp = fopen(calccachepath(repo, repoext), "r")))
1109 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1114 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1119 if (cinfo && !repoext)
1121 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1132 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1133 if (strcmp(repoext, "DL") != 0)
1134 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1137 if (repo_add_solv(repo, fp, flags))
1142 if (cinfo && !repoext)
1144 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1145 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1148 futimens(fileno(fp), 0); /* try to set modification time */
1154 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1159 struct repoinfo *cinfo;
1162 cinfo = repo->appdata;
1163 if (cinfo && cinfo->incomplete)
1165 mkdir(SOLVCACHE_PATH, 0755);
1166 /* use dupjoin instead of tmpjoin because tmpl must survive repo_write */
1167 tmpl = solv_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
1175 if (!(fp = fdopen(fd, "w")))
1184 for (i = repo->start; i < repo->end; i++)
1185 if (repo->pool->solvables[i].repo != repo)
1191 repo_write(repo, fp);
1193 repodata_write(info, fp);
1196 int oldnrepodata = repo->nrepodata;
1197 repo->nrepodata = oldnrepodata > 2 ? 2 : oldnrepodata; /* XXX: do this right */
1198 repo_write(repo, fp);
1199 repo->nrepodata = oldnrepodata;
1203 if (!repoext && cinfo)
1205 if (!cinfo->extcookie[0])
1207 /* create the ext cookie and append it */
1208 /* we just need some unique ID */
1210 if (!fstat(fileno(fp), &stb))
1211 memset(&stb, 0, sizeof(stb));
1212 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cookie, cinfo->extcookie);
1213 if (cinfo->extcookie[0] == 0)
1214 cinfo->extcookie[0] = 1;
1216 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1224 /* append our cookie describing the metadata state */
1225 if (fwrite(cookie, 32, 1, fp) != 1)
1240 /* switch to just saved repo to activate paging and save memory */
1241 FILE *fp = fopen(tmpl, "r");
1247 repo_empty(repo, 1);
1248 if (repo_add_solv(repo, fp, SOLV_ADD_NO_STUBS))
1250 /* oops, no way to recover from here */
1251 fprintf(stderr, "internal error\n");
1257 int flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1258 /* make sure repodata contains complete repo */
1259 /* (this is how repodata_write saves it) */
1260 repodata_extend_block(info, repo->start, repo->end - repo->start);
1261 info->state = REPODATA_LOADING;
1262 if (strcmp(repoext, "DL") != 0)
1263 flags |= REPO_LOCALPOOL;
1264 repo_add_solv(repo, fp, flags);
1265 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1270 if (!rename(tmpl, calccachepath(repo, repoext)))
1277 /* repomd helpers */
1279 static inline const char *
1280 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1282 Pool *pool = repo->pool;
1284 const char *filename;
1289 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1290 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1291 if (dataiterator_step(&di))
1293 dataiterator_setpos_parent(&di);
1294 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1295 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1297 dataiterator_free(&di);
1298 if (filename && !*chksumtypep)
1300 printf("no %s file checksum!\n", what);
1307 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1309 Id chksumtype, handle;
1310 const unsigned char *chksum;
1311 const char *filename;
1313 filename = repomd_find(repo, what, &chksum, &chksumtype);
1316 if (!strcmp(what, "prestodelta"))
1318 handle = repodata_new_handle(data);
1319 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1320 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1321 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1322 if (!strcmp(what, "deltainfo"))
1324 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1325 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1327 if (!strcmp(what, "filelists"))
1329 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1330 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1332 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1337 repomd_load_ext(Repo *repo, Repodata *data)
1339 const char *filename, *repomdtype;
1342 struct repoinfo *cinfo;
1343 const unsigned char *filechksum;
1347 cinfo = repo->appdata;
1348 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1351 if (!strcmp(repomdtype, "filelists"))
1353 else if (!strcmp(repomdtype, "deltainfo"))
1358 printf("[%s:%s", repo->name, ext);
1360 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1362 printf(" cached]\n");fflush(stdout);
1365 printf(" fetching]\n"); fflush(stdout);
1366 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1368 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1369 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1371 if (!strcmp(ext, "FL"))
1372 r = repo_add_rpmmd(repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES|REPO_LOCALPOOL);
1373 else if (!strcmp(ext, "DL"))
1374 r = repo_add_deltainfoxml(repo, fp, REPO_USE_LOADING);
1378 printf("%s\n", pool_errstr(repo->pool));
1381 writecachedrepo(repo, data, ext, cinfo->extcookie);
1388 #ifdef ENABLE_SUSEREPO
1389 /* susetags helpers */
1391 static inline const char *
1392 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1394 Pool *pool = repo->pool;
1396 const char *filename;
1401 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
1402 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1403 if (dataiterator_step(&di))
1405 dataiterator_setpos_parent(&di);
1406 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
1409 dataiterator_free(&di);
1410 if (filename && !*chksumtypep)
1412 printf("no %s file checksum!\n", what);
1418 static Id susetags_langtags[] = {
1419 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
1420 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
1421 SOLVABLE_EULA, REPOKEY_TYPE_STR,
1422 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
1423 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
1424 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
1429 susetags_add_ext(Repo *repo, Repodata *data)
1431 Pool *pool = repo->pool;
1434 Id handle, filechksumtype;
1435 const unsigned char *filechksum;
1438 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
1439 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1440 while (dataiterator_step(&di))
1442 if (strncmp(di.kv.str, "packages.", 9) != 0)
1444 if (!strcmp(di.kv.str + 9, "gz"))
1446 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
1448 ext[0] = di.kv.str[9];
1449 ext[1] = di.kv.str[10];
1451 if (!strcmp(ext, "en"))
1453 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
1455 handle = repodata_new_handle(data);
1456 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
1458 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
1459 if (!strcmp(ext, "DU"))
1461 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
1462 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
1464 else if (!strcmp(ext, "FL"))
1466 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1467 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1471 for (i = 0; susetags_langtags[i]; i += 2)
1473 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
1474 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
1477 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1479 dataiterator_free(&di);
1483 susetags_load_ext(Repo *repo, Repodata *data)
1485 const char *filename, *descrdir;
1489 struct repoinfo *cinfo;
1490 const unsigned char *filechksum;
1494 cinfo = repo->appdata;
1495 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1499 ext[0] = filename[9];
1500 ext[1] = filename[10];
1503 printf("[%s:%s", repo->name, ext);
1505 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1507 printf(" cached]\n"); fflush(stdout);
1511 printf(" fetching]\n"); fflush(stdout);
1513 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1514 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1516 descrdir = "suse/setup/descr";
1518 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1519 if ((fp = curlfopen(cinfo, pool_tmpjoin(repo->pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1521 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1522 if (strcmp(ext, "DL") != 0)
1523 flags |= REPO_LOCALPOOL;
1524 if (repo_add_susetags(repo, fp, defvendor, ext, flags))
1527 printf("%s\n", pool_errstr(repo->pool));
1531 writecachedrepo(repo, data, ext, cinfo->extcookie);
1541 load_stub(Pool *pool, Repodata *data, void *dp)
1543 struct repoinfo *cinfo = data->repo->appdata;
1544 switch (cinfo->type)
1546 #ifdef ENABLE_SUSEREPO
1548 return susetags_load_ext(data->repo, data);
1552 return repomd_load_ext(data->repo, data);
1559 static unsigned char installedcookie[32];
1561 #ifdef ENABLE_DEBIAN
1564 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1568 unsigned char *chksum;
1573 static char *basearch;
1585 basearch = strdup(un.machine);
1586 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
1589 binarydir = solv_dupjoin("binary-", basearch, "/");
1590 lbinarydir = strlen(binarydir);
1591 compl = strlen(comp);
1595 chksum = solv_malloc(32);
1597 while(fgets(buf, sizeof(buf), fp))
1602 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1604 if (!strncasecmp(buf, "MD5Sum:", 7))
1606 curchksumtype = REPOKEY_TYPE_MD5;
1609 if (!strncasecmp(buf, "SHA1:", 5))
1611 curchksumtype = REPOKEY_TYPE_SHA1;
1614 if (!strncasecmp(buf, "SHA256:", 7))
1616 curchksumtype = REPOKEY_TYPE_SHA256;
1628 while (*bp && *bp != ' ' && *bp != '\t')
1633 while (*bp == ' ' || *bp == '\t')
1635 while (*bp && *bp != ' ' && *bp != '\t')
1639 while (*bp == ' ' || *bp == '\t')
1642 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1645 if (strncmp(bp, binarydir, lbinarydir))
1648 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1650 unsigned char curchksum[32];
1652 if (filename && !strcmp(bp, "Packages"))
1654 curl = solv_chksum_len(curchksumtype);
1655 if (!curl || (chksumtype && solv_chksum_len(chksumtype) > curl))
1657 if (solv_hex2bin((const char **)&ch, curchksum, sizeof(curchksum)) != curl)
1659 solv_free(filename);
1660 filename = strdup(fn);
1661 chksumtype = curchksumtype;
1662 memcpy(chksum, curchksum, curl);
1668 fn = solv_dupjoin("/", filename, 0);
1669 solv_free(filename);
1670 filename = solv_dupjoin("dists/", cinfo->name, fn);
1674 chksum = solv_free(chksum);
1676 *chksumtypep = chksumtype;
1682 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1685 struct repoinfo *cinfo;
1688 const char *filename;
1689 const unsigned char *filechksum;
1691 #ifdef ENABLE_SUSEREPO
1692 const char *descrdir;
1697 #if defined(ENABLE_SUSEREPO) || defined(ENABLE_RPMMD)
1701 #if defined(ENABLE_DEBIAN)
1706 repo = repo_create(pool, "@System");
1707 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1708 printf("rpm database:");
1709 if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/rpm/Packages"), &stb))
1710 memset(&stb, 0, sizeof(stb));
1712 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1713 printf("dpgk database:");
1714 if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/dpkg/status"), &stb))
1715 memset(&stb, 0, sizeof(stb));
1718 printf("no installed database:");
1719 memset(&stb, 0, sizeof(stb));
1721 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, 0, installedcookie);
1722 if (usecachedrepo(repo, 0, installedcookie, 0))
1723 printf(" cached\n");
1726 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1730 printf(" reading\n");
1732 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1733 # if defined(ENABLE_SUSEREPO) && defined(PRODUCTS_PATH)
1734 if (repo_add_products(repo, PRODUCTS_PATH, REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
1736 fprintf(stderr, "product reading failed: %s\n", pool_errstr(pool));
1740 if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
1742 ref = repo_create(pool, "@System.old");
1743 if (repo_add_solv(ref, ofp, 0))
1750 if (repo_add_rpmdb(repo, ref, REPO_REUSE_REPODATA | REPO_USE_ROOTDIR))
1752 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
1758 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1759 if (repo_add_debdb(repo, REPO_REUSE_REPODATA | REPO_USE_ROOTDIR))
1761 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
1765 writecachedrepo(repo, 0, 0, installedcookie);
1767 pool_set_installed(pool, repo);
1769 for (i = 0; i < nrepoinfos; i++)
1771 cinfo = repoinfos + i;
1772 if (!cinfo->enabled)
1775 repo = repo_create(pool, cinfo->alias);
1777 repo->appdata = cinfo;
1778 repo->priority = 99 - cinfo->priority;
1780 dorefresh = cinfo->autorefresh;
1781 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0), &stb) == 0)
1783 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1786 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1788 printf("repo '%s':", cinfo->alias);
1789 printf(" cached\n");
1792 switch (cinfo->type)
1796 printf("rpmmd repo '%s':", cinfo->alias);
1798 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1800 printf(" no repomd.xml file, skipped\n");
1805 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1806 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1808 printf(" cached\n");
1812 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "repodata/repomd.xml.asc", &sigpool))
1817 if (repo_add_repomdxml(repo, fp, 0))
1819 printf("repomd.xml: %s\n", pool_errstr(pool));
1821 break; /* hopeless */
1824 printf(" fetching\n");
1825 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1826 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1828 if (repo_add_rpmmd(repo, fp, 0, 0))
1830 printf("primary: %s\n", pool_errstr(pool));
1831 cinfo->incomplete = 1;
1835 if (cinfo->incomplete)
1836 break; /* hopeless */
1838 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1839 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1841 if (repo_add_updateinfoxml(repo, fp, 0))
1843 printf("updateinfo: %s\n", pool_errstr(pool));
1844 cinfo->incomplete = 1;
1849 data = repo_add_repodata(repo, 0);
1850 if (!repomd_add_ext(repo, data, "deltainfo"))
1851 repomd_add_ext(repo, data, "prestodelta");
1852 repomd_add_ext(repo, data, "filelists");
1853 repodata_internalize(data);
1854 if (!cinfo->incomplete)
1855 writecachedrepo(repo, 0, 0, cinfo->cookie);
1856 repodata_create_stubs(repo_last_repodata(repo));
1860 #ifdef ENABLE_SUSEREPO
1862 printf("susetags repo '%s':", cinfo->alias);
1866 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1868 printf(" no content file, skipped\n");
1873 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1874 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1876 printf(" cached\n");
1880 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "content.asc", &sigpool))
1885 if (repo_add_content(repo, fp, 0))
1887 printf("content: %s\n", pool_errstr(pool));
1889 break; /* hopeless */
1892 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1893 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1895 descrdir = "suse/setup/descr";
1896 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1898 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1901 printf(" no packages file entry, skipped\n");
1904 printf(" fetching\n");
1905 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) == 0)
1906 break; /* hopeless */
1907 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES))
1909 printf("packages: %s\n", pool_errstr(pool));
1911 cinfo->incomplete = 1;
1912 break; /* hopeless */
1915 /* add default language */
1916 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1918 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1921 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1923 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES))
1925 printf("packages.en: %s\n", pool_errstr(pool));
1926 cinfo->incomplete = 1;
1931 filename = susetags_find(repo, "patterns", &filechksum, &filechksumtype);
1934 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1937 while (fgets(pbuf, sizeof(pbuf), fp))
1939 int l = strlen(pbuf);
1941 if (l && pbuf[l - 1] == '\n')
1943 if (!*pbuf || *pbuf == '.' || strchr(pbuf, '/') != 0)
1945 filename = susetags_find(repo, pbuf, &filechksum, &filechksumtype);
1946 if (filename && (fp2 = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1948 if (repo_add_susetags(repo, fp2, defvendor, 0, REPO_NO_INTERNALIZE))
1950 printf("%s: %s\n", pbuf, pool_errstr(pool));
1951 cinfo->incomplete = 1;
1959 repo_internalize(repo);
1960 data = repo_add_repodata(repo, 0);
1961 susetags_add_ext(repo, data);
1962 repodata_internalize(data);
1963 if (!cinfo->incomplete)
1964 writecachedrepo(repo, 0, 0, cinfo->cookie);
1965 repodata_create_stubs(repo_last_repodata(repo));
1969 #if defined(ENABLE_DEBIAN)
1971 printf("debian repo '%s':", cinfo->alias);
1973 filename = solv_dupjoin("dists/", cinfo->name, "/Release");
1974 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
1976 printf(" no Release file, skipped\n");
1979 free((char *)filename);
1982 solv_free((char *)filename);
1983 if (cinfo->repo_gpgcheck)
1985 filename = solv_dupjoin("dists/", cinfo->name, "/Release.gpg");
1986 if (!downloadchecksig(cinfo, fpr, filename, &sigpool))
1989 solv_free((char *)filename);
1992 solv_free((char *)filename);
1994 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
1995 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1997 printf(" cached\n");
2001 printf(" fetching\n");
2002 for (j = 0; j < cinfo->ncomponents; j++)
2004 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
2006 printf("[component %s not found]\n", cinfo->components[j]);
2009 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
2011 if (repo_add_debpackages(repo, fp, 0))
2013 printf("component %s: %s\n", cinfo->components[j], pool_errstr(pool));
2014 cinfo->incomplete = 1;
2018 solv_free((char *)filechksum);
2019 solv_free((char *)filename);
2022 if (!cinfo->incomplete)
2023 writecachedrepo(repo, 0, 0, cinfo->cookie);
2028 printf("unsupported repo '%s': skipped\n", cinfo->alias);
2039 yesno(const char *str)
2041 char inbuf[128], *ip;
2048 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2053 while (*ip == ' ' || *ip == '\t')
2060 if (*ip == 'y' || *ip == 'n')
2061 return *ip == 'y' ? 1 : 0;
2065 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2075 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2077 struct fcstate *fcstate = cbdata;
2085 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
2088 s = pool_id2solvable(pool, p);
2089 if (pool->installed && s->repo == pool->installed)
2091 if (!s->repo->rpmdbid)
2093 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2096 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
2098 for (i = 0; i < fcstate->newpkgscnt; i++)
2099 if (fcstate->checkq->elements[i] == p)
2101 if (i == fcstate->newpkgscnt)
2103 fp = fcstate->newpkgsfps[i];
2107 return rpm_byfp(fp, pool_solvable2str(pool, s), &fcstate->rpmdbstate);
2112 runrpm(const char *arg, const char *name, int dupfd3, const char *rootdir)
2117 if ((pid = fork()) == (pid_t)-1)
2126 if (dupfd3 != -1 && dupfd3 != 3)
2132 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2133 if (strcmp(arg, "-e") == 0)
2134 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2136 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2140 while (waitpid(pid, &status, 0) != pid)
2144 printf("rpm failed\n");
2151 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2154 rundpkg(const char *arg, const char *name, int dupfd3, const char *rootdir)
2159 if ((pid = fork()) == (pid_t)-1)
2168 if (dupfd3 != -1 && dupfd3 != 3)
2174 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2175 if (strcmp(arg, "--install") == 0)
2176 execlp("dpkg", "dpkg", "--install", "--root", rootdir, "--force", "all", name, (char *)0);
2178 execlp("dpkg", "dpkg", "--remove", "--root", rootdir, "--force", "all", name, (char *)0);
2182 while (waitpid(pid, &status, 0) != pid)
2186 printf("dpkg failed\n");
2194 nscallback(Pool *pool, void *data, Id name, Id evr)
2196 if (name == NAMESPACE_PRODUCTBUDDY)
2198 /* SUSE specific hack: each product has an associated rpm */
2199 Solvable *s = pool->solvables + evr;
2203 cap = pool_str2id(pool, pool_tmpjoin(pool, "product(", pool_id2str(pool, s->name) + 8, ")"), 0);
2206 cap = pool_rel2id(pool, cap, s->evr, REL_EQ, 0);
2209 FOR_PROVIDES(p, pp, cap)
2211 Solvable *ps = pool->solvables + p;
2212 if (ps->repo == s->repo && ps->arch == s->arch)
2213 if (!bestp || pool_evrcmp(pool, pool->solvables[bestp].evr, ps->evr, EVRCMP_COMPARE) < 0)
2219 if (name == NAMESPACE_LANGUAGE)
2221 if (!strcmp(pool_id2str(pool, evr), "ja"))
2223 if (!strcmp(pool_id2str(pool, evr), "de"))
2225 if (!strcmp(pool_id2str(pool, evr), "en"))
2227 if (!strcmp(pool_id2str(pool, evr), "en_US"))
2234 #ifdef SOFTLOCKS_PATH
2237 addsoftlocks(Pool *pool, Queue *job)
2241 char *bp, *ep, buf[4096];
2243 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2245 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2247 while (*bp == ' ' || *bp == '\t')
2249 if (!*bp || *bp == '#')
2251 for (ep = bp; *ep; ep++)
2252 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2255 type = SOLVER_SOLVABLE_NAME;
2256 if (!strncmp(bp, "provides:", 9) && bp[9])
2258 type = SOLVER_SOLVABLE_PROVIDES;
2261 id = pool_str2id(pool, bp, 1);
2262 if (pool->installed)
2264 FOR_JOB_SELECT(p, pp, type, id)
2265 if (pool->solvables[p].repo == pool->installed)
2268 continue; /* ignore, as it is already installed */
2270 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2279 rewrite_repos(Pool *pool, Queue *addedfileprovides, Queue *addedfileprovides_inst)
2284 Queue fileprovidesq;
2286 struct repoinfo *cinfo;
2288 map_init(&providedids, pool->ss.nstrings);
2289 queue_init(&fileprovidesq);
2290 for (i = 0; i < addedfileprovides->count; i++)
2291 MAPSET(&providedids, addedfileprovides->elements[i]);
2294 /* make sure all repodatas but the first are extensions */
2295 if (repo->nrepodata < 2)
2297 cinfo = repo->appdata;
2298 if (cinfo && cinfo->incomplete)
2300 data = repo_id2repodata(repo, 1);
2301 if (data->loadcallback)
2303 for (j = 2; j < repo->nrepodata; j++)
2305 Repodata *edata = repo_id2repodata(repo, j);
2306 if (!edata->loadcallback)
2309 if (j < repo->nrepodata)
2310 continue; /* found a non-externsion repodata, can't rewrite */
2311 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2313 if (repo == pool->installed && addedfileprovides_inst)
2315 for (j = 0; j < addedfileprovides->count; j++)
2316 MAPCLR(&providedids, addedfileprovides->elements[j]);
2317 for (j = 0; j < addedfileprovides_inst->count; j++)
2318 MAPSET(&providedids, addedfileprovides_inst->elements[j]);
2321 for (j = 0; j < fileprovidesq.count; j++)
2322 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2324 if (repo == pool->installed && addedfileprovides_inst)
2326 for (j = 0; j < addedfileprovides_inst->count; j++)
2327 MAPCLR(&providedids, addedfileprovides_inst->elements[j]);
2328 for (j = 0; j < addedfileprovides->count; j++)
2329 MAPSET(&providedids, addedfileprovides->elements[j]);
2330 if (n == addedfileprovides_inst->count)
2331 continue; /* nothing new added */
2333 else if (n == addedfileprovides->count)
2334 continue; /* nothing new added */
2336 repodata_set_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, repo == pool->installed && addedfileprovides_inst ? addedfileprovides_inst : addedfileprovides);
2337 repodata_internalize(data);
2338 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2340 queue_free(&fileprovidesq);
2341 map_free(&providedids);
2345 select_patches(Pool *pool, Queue *job)
2349 Map installedmap, multiversionmap;
2352 map_init(&multiversionmap, 0);
2353 map_init(&installedmap, pool->nsolvables);
2354 solver_calculate_multiversionmap(pool, job, &multiversionmap);
2355 if (pool->installed)
2356 FOR_REPO_SOLVABLES(pool->installed, p, s)
2357 MAPSET(&installedmap, p);
2359 /* install all patches */
2360 for (p = 1; p < pool->nsolvables; p++)
2366 s = pool->solvables + p;
2367 if (strncmp(pool_id2str(pool, s->name), "patch:", 6) != 0)
2369 FOR_PROVIDES(p2, pp, s->name)
2371 Solvable *s2 = pool->solvables + p2;
2372 if (s2->name != s->name)
2374 r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2375 if (r < 0 || (r == 0 && p > p2))
2380 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2381 if (type && !strcmp(type, "optional"))
2383 r = solvable_trivial_installable_map(s, &installedmap, 0, &multiversionmap);
2386 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2393 queue_push2(job, SOLVER_SOLVABLE, p);
2395 map_free(&installedmap);
2396 map_free(&multiversionmap);
2400 #define MODE_INSTALL 1
2401 #define MODE_ERASE 2
2402 #define MODE_UPDATE 3
2403 #define MODE_DISTUPGRADE 4
2404 #define MODE_VERIFY 5
2405 #define MODE_PATCH 6
2407 #define MODE_REPOLIST 8
2408 #define MODE_SEARCH 9
2413 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2414 fprintf(stderr, "\n");
2415 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2416 fprintf(stderr, " versions from the repositories\n");
2417 fprintf(stderr, " erase: erase installed packages\n");
2418 fprintf(stderr, " info: display package information\n");
2419 fprintf(stderr, " install: install packages\n");
2420 fprintf(stderr, " list: list packages\n");
2421 fprintf(stderr, " repos: list enabled repositories\n");
2422 fprintf(stderr, " search: search name/summary/description\n");
2423 fprintf(stderr, " update: update installed packages\n");
2424 fprintf(stderr, " verify: check dependencies of installed packages\n");
2425 fprintf(stderr, "\n");
2430 main(int argc, char **argv)
2433 Repo *commandlinerepo = 0;
2434 Id *commandlinepkgs = 0;
2436 struct repoinfo *repoinfos;
2438 int mainmode = 0, mode = 0;
2443 char inbuf[128], *ip;
2445 Queue addedfileprovides;
2446 Queue addedfileprovides_inst;
2456 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2458 mainmode = MODE_INSTALL;
2459 mode = SOLVER_INSTALL;
2461 else if (!strcmp(argv[0], "patch"))
2463 mainmode = MODE_PATCH;
2464 mode = SOLVER_INSTALL;
2466 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2468 mainmode = MODE_ERASE;
2469 mode = SOLVER_ERASE;
2471 else if (!strcmp(argv[0], "list"))
2473 mainmode = MODE_LIST;
2476 else if (!strcmp(argv[0], "info"))
2478 mainmode = MODE_INFO;
2481 else if (!strcmp(argv[0], "search"))
2483 mainmode = MODE_SEARCH;
2486 else if (!strcmp(argv[0], "verify"))
2488 mainmode = MODE_VERIFY;
2489 mode = SOLVER_VERIFY;
2491 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2493 mainmode = MODE_UPDATE;
2494 mode = SOLVER_UPDATE;
2496 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2498 mainmode = MODE_DISTUPGRADE;
2499 mode = SOLVER_DISTUPGRADE;
2501 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2503 mainmode = MODE_REPOLIST;
2511 if (argc > 2 && !strcmp(argv[1], "--root"))
2518 else if (argc > 1 && !strcmp(argv[1], "--clean"))
2524 else if (argc > 1 && !strcmp(argv[1], "--best"))
2534 pool = pool_create();
2535 pool_set_rootdir(pool, rootdir);
2539 const char *langs[] = {"de_DE", "de", "en"};
2540 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2544 pool_setloadcallback(pool, load_stub, 0);
2545 pool->nscallback = nscallback;
2546 // pool_setdebuglevel(pool, 2);
2548 repoinfos = read_repoinfos(pool, &nrepoinfos);
2550 if (mainmode == MODE_REPOLIST)
2553 for (i = 0; i < nrepoinfos; i++)
2555 struct repoinfo *cinfo = repoinfos + i;
2556 if (!cinfo->enabled)
2558 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2563 read_repos(pool, repoinfos, nrepoinfos);
2565 queue_init(&repofilter);
2566 while (argc > 2 && !strcmp(argv[1], "-r"))
2568 const char *rname = argv[2], *rp;
2570 for (rp = rname; *rp; rp++)
2571 if (*rp <= '0' || *rp >= '9')
2575 /* repo specified by number */
2576 int rnum = atoi(rname);
2577 for (i = 0; i < nrepoinfos; i++)
2579 struct repoinfo *cinfo = repoinfos + i;
2580 if (!cinfo->enabled)
2583 repoid = cinfo->repo->repoid;
2588 /* repo specified by alias */
2592 if (!strcasecmp(rname, repo->name))
2593 repoid = repo->repoid;
2598 fprintf(stderr, "%s: no such repo\n", rname);
2601 /* SETVENDOR is actually wrong but useful */
2602 queue_push2(&repofilter, SOLVER_SOLVABLE_REPO | SOLVER_SETREPO | SOLVER_SETVENDOR, repoid);
2606 if (mainmode == MODE_SEARCH)
2612 pool_createwhatprovides(pool);
2614 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2615 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2616 dataiterator_set_search(&di, 0, 0);
2617 while (dataiterator_step(&di))
2618 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2619 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2620 dataiterator_set_search(&di, 0, 0);
2621 while (dataiterator_step(&di))
2622 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2623 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2624 dataiterator_set_search(&di, 0, 0);
2625 while (dataiterator_step(&di))
2626 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2627 dataiterator_free(&di);
2628 if (repofilter.count)
2629 selection_filter(pool, &sel, &repofilter);
2632 selection_solvables(pool, &sel, &q);
2634 for (i = 0; i < q.count; i++)
2636 Solvable *s = pool_id2solvable(pool, q.elements[i]);
2637 printf(" - %s [%s]: %s\n", pool_solvable2str(pool, s), s->repo->name, solvable_lookup_str(s, SOLVABLE_SUMMARY));
2644 if (mainmode == MODE_LIST || mainmode == MODE_INSTALL)
2646 for (i = 1; i < argc; i++)
2649 l = strlen(argv[i]);
2650 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2651 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2654 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2655 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2658 if (access(argv[i], R_OK))
2663 if (!commandlinepkgs)
2664 commandlinepkgs = solv_calloc(argc, sizeof(Id));
2665 if (!commandlinerepo)
2666 commandlinerepo = repo_create(pool, "@commandline");
2668 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2669 p = repo_add_rpm(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2671 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2672 p = repo_add_deb(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2676 fprintf(stderr, "could not add '%s'\n", argv[i]);
2679 commandlinepkgs[i] = p;
2681 if (commandlinerepo)
2682 repo_internalize(commandlinerepo);
2685 // FOR_REPOS(i, repo)
2686 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2687 queue_init(&addedfileprovides);
2688 queue_init(&addedfileprovides_inst);
2689 pool_addfileprovides_queue(pool, &addedfileprovides, &addedfileprovides_inst);
2690 if (addedfileprovides.count || addedfileprovides_inst.count)
2691 rewrite_repos(pool, &addedfileprovides, &addedfileprovides_inst);
2692 queue_free(&addedfileprovides);
2693 queue_free(&addedfileprovides_inst);
2694 pool_createwhatprovides(pool);
2697 for (i = 1; i < argc; i++)
2700 int j, flags, rflags;
2702 if (commandlinepkgs && commandlinepkgs[i])
2704 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2708 flags = SELECTION_NAME|SELECTION_PROVIDES|SELECTION_GLOB;
2709 flags |= SELECTION_CANON|SELECTION_DOTARCH|SELECTION_REL;
2710 if (mode == MODE_LIST)
2711 flags |= SELECTION_WITH_SOURCE;
2712 if (argv[i][0] == '/')
2713 flags |= SELECTION_FILELIST | (mode == MODE_ERASE ? SELECTION_INSTALLED_ONLY : 0);
2714 rflags = selection_make(pool, &job2, argv[i], flags);
2715 if (repofilter.count)
2716 selection_filter(pool, &job2, &repofilter);
2719 flags |= SELECTION_NOCASE;
2720 rflags = selection_make(pool, &job2, argv[i], flags);
2721 if (repofilter.count)
2722 selection_filter(pool, &job2, &repofilter);
2724 printf("[ignoring case for '%s']\n", argv[i]);
2728 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2731 if (rflags & SELECTION_FILELIST)
2732 printf("[using file list match for '%s']\n", argv[i]);
2733 if (rflags & SELECTION_PROVIDES)
2734 printf("[using capability match for '%s']\n", argv[i]);
2735 for (j = 0; j < job2.count; j++)
2736 queue_push(&job, job2.elements[j]);
2740 if (!job.count && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE || mainmode == MODE_VERIFY || repofilter.count))
2742 queue_push2(&job, SOLVER_SOLVABLE_ALL, 0);
2743 if (repofilter.count)
2744 selection_filter(pool, &job, &repofilter);
2746 queue_free(&repofilter);
2748 if (!job.count && mainmode != MODE_PATCH)
2750 printf("no package matched\n");
2754 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
2756 /* list mode, no solver needed */
2759 for (i = 0; i < job.count; i += 2)
2763 pool_job2solvables(pool, &q, job.elements[i], job.elements[i + 1]);
2764 for (j = 0; j < q.count; j++)
2766 Solvable *s = pool_id2solvable(pool, q.elements[j]);
2767 if (mainmode == MODE_INFO)
2770 printf("Name: %s\n", pool_solvable2str(pool, s));
2771 printf("Repo: %s\n", s->repo->name);
2772 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
2773 str = solvable_lookup_str(s, SOLVABLE_URL);
2775 printf("Url: %s\n", str);
2776 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
2778 printf("License: %s\n", str);
2779 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
2785 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
2787 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
2789 printf(" - %s [%s]\n", pool_solvable2str(pool, s), s->repo->name);
2791 printf(" %s\n", sum);
2798 free_repoinfos(repoinfos, nrepoinfos);
2799 solv_free(commandlinepkgs);
2801 yum_substitute(pool, 0);
2806 if (mainmode == MODE_PATCH)
2807 select_patches(pool, &job);
2810 for (i = 0; i < job.count; i += 2)
2812 job.elements[i] |= mode;
2813 if (mode == SOLVER_UPDATE && pool_isemptyupdatejob(pool, job.elements[i], job.elements[i + 1]))
2814 job.elements[i] ^= SOLVER_UPDATE ^ SOLVER_INSTALL;
2816 job.elements[i] |= SOLVER_CLEANDEPS;
2818 job.elements[i] |= SOLVER_FORCEBEST;
2821 // multiversion test
2822 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae", 1));
2823 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-base", 1));
2824 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-extra", 1));
2826 queue_push2(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, NAMESPACE_LANGUAGE, 0, REL_NAMESPACE, 1));
2827 queue_push2(&job, SOLVER_ERASE|SOLVER_CLEANDEPS|SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, NAMESPACE_LANGUAGE, 0, REL_NAMESPACE, 1));
2830 #ifdef SOFTLOCKS_PATH
2831 addsoftlocks(pool, &job);
2834 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2837 solv = solver_create(pool);
2838 solver_set_flag(solv, SOLVER_FLAG_SPLITPROVIDES, 1);
2840 solver_set_flag(solv, SOLVER_FLAG_ALLOW_VENDORCHANGE, 1);
2842 if (mainmode == MODE_ERASE)
2843 solver_set_flag(solv, SOLVER_FLAG_ALLOW_UNINSTALL, 1); /* don't nag */
2844 solver_set_flag(solv, SOLVER_FLAG_BEST_OBEY_POLICY, 1);
2848 Id problem, solution;
2851 if (!solver_solve(solv, &job))
2853 pcnt = solver_problem_count(solv);
2854 printf("Found %d problems:\n", pcnt);
2855 for (problem = 1; problem <= pcnt; problem++)
2858 printf("Problem %d/%d:\n", problem, pcnt);
2859 solver_printprobleminfo(solv, problem);
2861 scnt = solver_solution_count(solv, problem);
2862 for (solution = 1; solution <= scnt; solution++)
2864 printf("Solution %d:\n", solution);
2865 solver_printsolution(solv, problem, solution);
2870 printf("Please choose a solution: ");
2873 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2878 while (*ip == ' ' || *ip == '\t')
2880 if (*ip >= '0' && *ip <= '9')
2883 if (take >= 1 && take <= scnt)
2899 solver_take_solution(solv, problem, take, &job);
2903 trans = solver_create_transaction(solv);
2904 if (!trans->steps.count)
2906 printf("Nothing to do.\n");
2907 transaction_free(trans);
2911 free_repoinfos(repoinfos, nrepoinfos);
2912 solv_free(commandlinepkgs);
2914 yum_substitute(pool, 0);
2919 printf("Transaction summary:\n\n");
2920 transaction_print(trans);
2929 duc[1].path = "/usr/share/man";
2930 duc[2].path = "/sbin";
2931 duc[3].path = "/etc";
2932 transaction_calc_duchanges(trans, duc, 4);
2933 for (i = 0; i < 4; i++)
2934 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
2937 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
2940 if (!yesno("OK to continue (y/n)? "))
2943 transaction_free(trans);
2947 free_repoinfos(repoinfos, nrepoinfos);
2948 solv_free(commandlinepkgs);
2950 yum_substitute(pool, 0);
2955 queue_init(&checkq);
2956 newpkgs = transaction_installedresult(trans, &checkq);
2961 int downloadsize = 0;
2962 for (i = 0; i < newpkgs; i++)
2966 p = checkq.elements[i];
2967 s = pool_id2solvable(pool, p);
2968 downloadsize += solvable_lookup_sizek(s, SOLVABLE_DOWNLOADSIZE, 0);
2970 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
2971 newpkgsfps = solv_calloc(newpkgs, sizeof(*newpkgsfps));
2972 for (i = 0; i < newpkgs; i++)
2974 unsigned int medianr;
2977 struct repoinfo *cinfo;
2978 const unsigned char *chksum;
2982 p = checkq.elements[i];
2983 s = pool_id2solvable(pool, p);
2984 if (s->repo == commandlinerepo)
2986 loc = solvable_lookup_location(s, &medianr);
2987 if (!(newpkgsfps[i] = fopen(loc, "r")))
2995 cinfo = s->repo->appdata;
2998 printf("%s: no repository information\n", s->repo->name);
3001 loc = solvable_lookup_location(s, &medianr);
3005 if (pool->installed && pool->installed->nsolvables)
3007 /* try a delta first */
3008 char *matchname = strdup(pool_id2str(pool, s->name));
3009 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
3010 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
3011 while (dataiterator_step(&di))
3015 dataiterator_setpos_parent(&di);
3016 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
3017 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
3019 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
3020 FOR_PROVIDES(op, pp, s->name)
3022 Solvable *os = pool->solvables + op;
3023 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
3026 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
3028 /* base is installed, run sequence check */
3029 const char *seqname;
3034 const char *archstr;
3039 archstr = pool_id2str(pool, s->arch);
3040 if (strlen(archstr) > 10 || strchr(archstr, '\'') != 0)
3043 seqname = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME);
3044 seqevr = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR);
3045 seqnum = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM);
3046 seq = pool_tmpjoin(pool, seqname, "-", seqevr);
3047 seq = pool_tmpappend(pool, seq, "-", seqnum);
3048 if (strchr(seq, '\'') != 0)
3051 sprintf(cmd, "/usr/bin/applydeltarpm -a '%s' -c -s '", archstr);
3053 sprintf(cmd, "/usr/bin/applydeltarpm -c -s '");
3055 if (system(pool_tmpjoin(pool, cmd, seq, "'")) != 0)
3056 continue; /* didn't match */
3057 /* looks good, download delta */
3059 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
3061 continue; /* no way! */
3062 dloc = pool_lookup_deltalocation(pool, SOLVID_POS, 0);
3065 if (cinfo->type == TYPE_SUSETAGS)
3067 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3068 dloc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", dloc);
3070 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
3072 /* got it, now reconstruct */
3073 newfd = opentmpfile();
3075 sprintf(cmd, "applydeltarpm -a '%s' /dev/fd/%d /dev/fd/%d", archstr, fileno(fp), newfd);
3077 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
3079 fcntl(fileno(fp), F_SETFD, 0);
3086 lseek(newfd, 0, SEEK_SET);
3088 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3089 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
3095 newpkgsfps[i] = fdopen(newfd, "r");
3100 dataiterator_free(&di);
3101 solv_free(matchname);
3108 continue; /* delta worked! */
3110 if (cinfo->type == TYPE_SUSETAGS)
3112 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3113 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3116 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3117 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3119 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3128 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3132 struct fcstate fcstate;
3134 printf("Searching for file conflicts\n");
3135 queue_init(&conflicts);
3136 fcstate.rpmdbstate = 0;
3137 fcstate.newpkgscnt = newpkgs;
3138 fcstate.checkq = &checkq;
3139 fcstate.newpkgsfps = newpkgsfps;
3140 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fileconflict_cb, &fcstate);
3141 if (conflicts.count)
3144 for (i = 0; i < conflicts.count; i += 5)
3145 printf("file %s of package %s conflicts with package %s\n", pool_id2str(pool, conflicts.elements[i]), pool_solvid2str(pool, conflicts.elements[i + 1]), pool_solvid2str(pool, conflicts.elements[i + 3]));
3147 if (yesno("Re-run solver (y/n/q)? "))
3149 for (i = 0; i < newpkgs; i++)
3151 fclose(newpkgsfps[i]);
3152 newpkgsfps = solv_free(newpkgsfps);
3155 pool_add_fileconflicts_deps(pool, &conflicts);
3159 queue_free(&conflicts);
3163 printf("Committing transaction:\n\n");
3164 transaction_order(trans, 0);
3165 for (i = 0; i < trans->steps.count; i++)
3167 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3168 const char *evr, *evrp, *nvra;
3175 p = trans->steps.elements[i];
3176 s = pool_id2solvable(pool, p);
3177 type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3180 case SOLVER_TRANSACTION_ERASE:
3181 printf("erase %s\n", pool_solvid2str(pool, p));
3182 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3183 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3185 /* strip epoch from evr */
3186 evr = evrp = pool_id2str(pool, s->evr);
3187 while (*evrp >= '0' && *evrp <= '9')
3189 if (evrp > evr && evrp[0] == ':' && evrp[1])
3191 nvra = pool_tmpjoin(pool, pool_id2str(pool, s->name), "-", evr);
3192 nvra = pool_tmpappend(pool, nvra, ".", pool_id2str(pool, s->arch));
3193 runrpm("-e", nvra, -1, rootdir); /* too bad that --querybynumber doesn't work */
3195 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3196 rundpkg("--remove", pool_id2str(pool, s->name), 0, rootdir);
3199 case SOLVER_TRANSACTION_INSTALL:
3200 case SOLVER_TRANSACTION_MULTIINSTALL:
3201 printf("install %s\n", pool_solvid2str(pool, p));
3202 for (j = 0; j < newpkgs; j++)
3203 if (checkq.elements[j] == p)
3205 fp = j < newpkgs ? newpkgsfps[j] : 0;
3209 lseek(fileno(fp), 0, SEEK_SET);
3210 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3211 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp), rootdir);
3213 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3214 rundpkg("--install", "/dev/fd/3", fileno(fp), rootdir);
3224 for (i = 0; i < newpkgs; i++)
3226 fclose(newpkgsfps[i]);
3227 solv_free(newpkgsfps);
3228 queue_free(&checkq);
3229 transaction_free(trans);
3233 free_repoinfos(repoinfos, nrepoinfos);
3234 solv_free(commandlinepkgs);
3236 yum_substitute(pool, 0);