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];
122 yum_substitute(Pool *pool, char *line)
125 static char *releaseevr;
126 static char *basearch;
130 solv_free(releaseevr);
137 while ((p2 = strchr(p, '$')) != 0)
139 if (!strncmp(p2, "$releasever", 11))
144 const char *rootdir = pool_get_rootdir(pool);
147 rpm_installedrpmdbids(rootdir, "Providename", "redhat-release", &q);
150 void *handle, *state = 0;
152 handle = rpm_byrpmdbid(q.elements[0], rootdir, &state);
153 releaseevr = rpm_query(handle, SOLVABLE_EVR);
154 rpm_byrpmdbid(0, 0, &state);
155 if ((p = strchr(releaseevr, '-')) != 0)
161 fprintf(stderr, "no installed package provides 'redhat-release', cannot determine $releasever\n");
166 p = pool_tmpjoin(pool, line, releaseevr, p2 + 11);
167 p2 = p + (p2 - line);
169 p = p2 + strlen(releaseevr);
172 if (!strncmp(p2, "$basearch", 9))
182 basearch = strdup(un.machine);
183 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
187 p = pool_tmpjoin(pool, line, basearch, p2 + 9);
188 p2 = p + (p2 - line);
190 p = p2 + strlen(basearch);
199 #define TYPE_UNKNOWN 0
200 #define TYPE_SUSETAGS 1
202 #define TYPE_PLAINDIR 3
203 #define TYPE_DEBIAN 4
207 read_repoinfos_sort(const void *ap, const void *bp)
209 const struct repoinfo *a = ap;
210 const struct repoinfo *b = bp;
211 return strcmp(a->alias, b->alias);
215 #if defined(SUSE) || defined(FEDORA)
218 read_repoinfos(Pool *pool, int *nrepoinfosp)
220 const char *reposdir = REPOINFO_PATH;
222 char buf2[4096], *kp, *vp, *kpe;
227 struct repoinfo *repoinfos = 0, *cinfo;
230 rdlen = strlen(reposdir);
231 dir = opendir(reposdir);
237 while ((ent = readdir(dir)) != 0)
239 if (ent->d_name[0] == '.')
241 l = strlen(ent->d_name);
242 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
244 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
245 if ((fp = fopen(buf, "r")) == 0)
251 while(fgets(buf2, sizeof(buf2), fp))
256 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
259 while (*kp == ' ' || *kp == '\t')
261 if (!*kp || *kp == '#')
265 kp = yum_substitute(pool, kp);
269 vp = strrchr(kp, ']');
273 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
274 cinfo = repoinfos + nrepoinfos++;
275 memset(cinfo, 0, sizeof(*cinfo));
276 cinfo->alias = strdup(kp + 1);
277 cinfo->type = TYPE_RPMMD;
278 cinfo->autorefresh = 1;
279 cinfo->priority = 99;
281 cinfo->repo_gpgcheck = 1;
283 cinfo->metadata_expire = METADATA_EXPIRE;
288 vp = strchr(kp, '=');
291 for (kpe = vp - 1; kpe >= kp; kpe--)
292 if (*kpe != ' ' && *kpe != '\t')
297 while (*vp == ' ' || *vp == '\t')
300 if (!strcmp(kp, "name"))
301 cinfo->name = strdup(vp);
302 else if (!strcmp(kp, "enabled"))
303 cinfo->enabled = *vp == '0' ? 0 : 1;
304 else if (!strcmp(kp, "autorefresh"))
305 cinfo->autorefresh = *vp == '0' ? 0 : 1;
306 else if (!strcmp(kp, "gpgcheck"))
307 cinfo->pkgs_gpgcheck = *vp == '0' ? 0 : 1;
308 else if (!strcmp(kp, "repo_gpgcheck"))
309 cinfo->repo_gpgcheck = *vp == '0' ? 0 : 1;
310 else if (!strcmp(kp, "baseurl"))
311 cinfo->baseurl = strdup(vp);
312 else if (!strcmp(kp, "mirrorlist"))
314 if (strstr(vp, "metalink"))
315 cinfo->metalink = strdup(vp);
317 cinfo->mirrorlist = strdup(vp);
319 else if (!strcmp(kp, "path"))
321 if (vp && strcmp(vp, "/") != 0)
322 cinfo->path = strdup(vp);
324 else if (!strcmp(kp, "type"))
326 if (!strcmp(vp, "yast2"))
327 cinfo->type = TYPE_SUSETAGS;
328 else if (!strcmp(vp, "rpm-md"))
329 cinfo->type = TYPE_RPMMD;
330 else if (!strcmp(vp, "plaindir"))
331 cinfo->type = TYPE_PLAINDIR;
333 cinfo->type = TYPE_UNKNOWN;
335 else if (!strcmp(kp, "priority"))
336 cinfo->priority = atoi(vp);
337 else if (!strcmp(kp, "keeppackages"))
338 cinfo->keeppackages = *vp == '0' ? 0 : 1;
344 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
345 *nrepoinfosp = nrepoinfos;
354 read_repoinfos(Pool *pool, int *nrepoinfosp)
360 char *kp, *url, *distro;
361 struct repoinfo *repoinfos = 0, *cinfo;
366 fp = fopen("/etc/apt/sources.list", "r");
373 dir = opendir("/etc/apt/sources.list.d");
377 if ((ent = readdir(dir)) == 0)
382 if (ent->d_name[0] == '.')
384 l = strlen(ent->d_name);
385 if (l < 5 || strcmp(ent->d_name + l - 5, ".list") != 0)
387 snprintf(buf, sizeof(buf), "%s/%s", "/etc/apt/sources.list.d", ent->d_name);
388 if (!(fp = fopen(buf, "r")))
391 while(fgets(buf2, sizeof(buf2), fp))
396 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
399 while (*kp == ' ' || *kp == '\t')
401 if (!*kp || *kp == '#')
403 if (strncmp(kp, "deb", 3) != 0)
406 if (*kp != ' ' && *kp != '\t')
408 while (*kp == ' ' || *kp == '\t')
413 while (*kp && *kp != ' ' && *kp != '\t')
417 while (*kp == ' ' || *kp == '\t')
422 while (*kp && *kp != ' ' && *kp != '\t')
426 while (*kp == ' ' || *kp == '\t')
430 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
431 cinfo = repoinfos + nrepoinfos++;
432 memset(cinfo, 0, sizeof(*cinfo));
433 cinfo->baseurl = strdup(url);
434 cinfo->alias = solv_dupjoin(url, "/", distro);
435 cinfo->name = strdup(distro);
436 cinfo->type = TYPE_DEBIAN;
438 cinfo->autorefresh = 1;
439 cinfo->repo_gpgcheck = 1;
440 cinfo->metadata_expire = METADATA_EXPIRE;
444 while (*kp == ' ' || *kp == '\t')
449 while (*kp && *kp != ' ' && *kp != '\t')
453 cinfo->components = solv_extend(cinfo->components, cinfo->ncomponents, 1, sizeof(*cinfo->components), 15);
454 cinfo->components[cinfo->ncomponents++] = strdup(compo);
460 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
461 *nrepoinfosp = nrepoinfos;
469 read_repoinfos(Pool *pool, int *nrepoinfosp)
478 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
481 for (i = 0; i < nrepoinfos; i++)
483 struct repoinfo *cinfo = repoinfos + i;
484 solv_free(cinfo->name);
485 solv_free(cinfo->alias);
486 solv_free(cinfo->path);
487 solv_free(cinfo->metalink);
488 solv_free(cinfo->mirrorlist);
489 solv_free(cinfo->baseurl);
490 for (j = 0; j < cinfo->ncomponents; j++)
491 solv_free(cinfo->components[j]);
492 solv_free(cinfo->components);
494 solv_free(repoinfos);
503 strcpy(tmpl, "/var/tmp/solvXXXXXX");
515 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
518 const unsigned char *sum;
522 h = solv_chksum_create(chksumtype);
525 printf("%s: unknown checksum type\n", file);
528 while ((l = read(fd, buf, sizeof(buf))) > 0)
529 solv_chksum_add(h, buf, l);
530 lseek(fd, 0, SEEK_SET);
532 sum = solv_chksum_get(h, &l);
533 if (memcmp(sum, chksum, l))
535 printf("%s: checksum mismatch\n", file);
536 solv_chksum_free(h, 0);
539 solv_chksum_free(h, 0);
544 findfastest(char **urls, int nurls)
551 struct addrinfo hints, *result;;
553 fds = solv_calloc(nurls, sizeof(*fds));
554 socks = solv_calloc(nurls, sizeof(*socks));
555 for (i = 0; i < nurls; i++)
558 p = strchr(urls[i], '/');
571 if ((p2 = strchr(p, '@')) != 0)
574 if (!strncmp("https:", urls[i], 6))
576 else if (!strncmp("ftp:", urls[i], 4))
578 if ((p2 = strrchr(p, ':')) != 0)
587 sprintf(portstr, "%d", port);
588 memset(&hints, 0, sizeof(struct addrinfo));
589 hints.ai_family = AF_UNSPEC;
590 hints.ai_socktype = SOCK_STREAM;
591 hints.ai_flags = AI_NUMERICSERV;
593 if (!getaddrinfo(p, portstr, &hints, &result))
595 socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
598 fcntl(socks[i], F_SETFL, O_NONBLOCK);
599 if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1)
601 if (errno != EINPROGRESS)
608 freeaddrinfo(result);
615 for (i = j = 0; i < nurls; i++)
619 fds[j].fd = socks[i];
620 fds[j].events = POLLOUT;
628 if (poll(fds, j, 10000) <= 0)
630 i = -1; /* something is wrong */
633 for (i = 0; i < j; i++)
634 if ((fds[i].revents & POLLOUT) != 0)
637 socklen_t soel = sizeof(int);
638 if (getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, &soe, &soel) == -1 || soe != 0)
640 /* connect failed, kill socket */
641 for (j = 0; j < nurls; j++)
642 if (socks[j] == fds[i].fd)
655 i = -1; /* something is wrong, no bit was set */
658 /* now i contains the fastest fd index */
661 for (j = 0; j < nurls; j++)
662 if (socks[j] == fds[i].fd)
666 char *url0 = urls[0];
671 for (i = j = 0; i < nurls; i++)
679 findmetalinkurl(FILE *fp, unsigned char *chksump, Id *chksumtypep)
681 char buf[4096], *bp, *ep;
688 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
690 while (*bp == ' ' || *bp == '\t')
692 if (chksumtypep && !*chksumtypep && !strncmp(bp, "<hash type=\"sha256\">", 20))
695 if (solv_hex2bin((const char **)&bp, chksump, 32) == 32)
696 *chksumtypep = REPOKEY_TYPE_SHA256;
699 if (strncmp(bp, "<url", 4))
701 bp = strchr(bp, '>');
705 ep = strstr(bp, "repodata/repomd.xml</url>");
709 if (strncmp(bp, "http", 4))
711 urls = solv_extend(urls, nurls, 1, sizeof(*urls), 15);
712 urls[nurls++] = strdup(bp);
717 findfastest(urls, nurls > 5 ? 5 : nurls);
720 for (i = 0; i < nurls; i++)
723 ep = strchr(bp, '/');
724 if ((ep = strchr(ep + 2, '/')) != 0)
727 printf("[using mirror %s]\n", bp);
736 findmirrorlisturl(FILE *fp)
738 char buf[4096], *bp, *ep;
743 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
745 while (*bp == ' ' || *bp == '\t')
747 if (!*bp || *bp == '#')
750 while (l > 0 && (bp[l - 1] == ' ' || bp[l - 1] == '\t' || bp[l - 1] == '\n'))
752 urls = solv_extend(urls, nurls, 1, sizeof(*urls), 15);
753 urls[nurls++] = strdup(bp);
758 findfastest(urls, nurls > 5 ? 5 : nurls);
761 for (i = 0; i < nurls; i++)
764 ep = strchr(bp, '/');
765 if ((ep = strchr(ep + 2, '/')) != 0)
768 printf("[using mirror %s]\n", bp);
777 iscompressed(const char *name)
779 return solv_xfopen_iscompressed(name) != 0;
783 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int *badchecksump)
790 const char *baseurl = cinfo->baseurl;
794 if (!cinfo->metalink && !cinfo->mirrorlist)
796 if (file != cinfo->metalink && file != cinfo->mirrorlist)
798 unsigned char mlchksum[32];
799 fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
804 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
806 cinfo->baseurl = findmirrorlisturl(fp);
811 if (strchr(cinfo->baseurl, '$'))
813 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
814 free(cinfo->baseurl);
815 cinfo->baseurl = strdup(b);
818 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
820 chksumtype = mlchksumtype;
823 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, badchecksump);
825 snprintf(url, sizeof(url), "%s", file);
830 if (l && baseurl[l - 1] == '/')
831 snprintf(url, sizeof(url), "%s%s", baseurl, file);
833 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
836 // printf("url: %s\n", url);
837 if ((pid = fork()) == (pid_t)-1)
849 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
854 while (waitpid(pid, &status, 0) != pid)
856 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
862 lseek(fd, 0, SEEK_SET);
865 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
871 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
878 fcntl(fd, F_SETFD, FD_CLOEXEC);
881 if (solv_xfopen_iscompressed(file) < 0)
883 printf("%s: unsupported compression\n", file);
889 fp = solv_xfopen_fd(file, fd, "r");
892 fp = fdopen(fd, "r");
901 cleanupgpg(char *gpgdir)
904 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
906 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
908 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
910 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
912 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
918 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
927 off_t posfp, possigfp;
930 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
933 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
934 if (!(kfp = fopen(keysfile, "w")) )
940 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
944 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
945 if (!pubkey || !*pubkey)
947 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
949 if (fputc('\n', kfp) == EOF) /* Just in case... */
953 if (fclose(kfp) || !nkeys)
958 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
961 fprintf(stderr, "key import error\n");
966 posfp = lseek(fileno(fp), 0, SEEK_CUR);
967 lseek(fileno(fp), 0, SEEK_SET);
968 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
969 lseek(fileno(sigfp), 0, SEEK_SET);
970 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
971 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
972 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
974 lseek(fileno(sigfp), possigfp, SEEK_SET);
975 lseek(fileno(fp), posfp, SEEK_SET);
976 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
977 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
979 return r == 0 ? 1 : 0;
985 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
990 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));
991 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
992 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
994 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
995 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
996 return r == 0 ? 1 : 0;
1004 Pool *sigpool = pool_create();
1005 #if defined(ENABLE_RPMDB_PUBKEY)
1006 Repo *repo = repo_create(sigpool, "rpmdbkeys");
1007 repo_add_rpmdb_pubkeys(repo, 0);
1013 downloadchecksig(struct repoinfo *cinfo, FILE *fp, const char *sigurl, Pool **sigpool)
1016 sigfp = curlfopen(cinfo, sigurl, 0, 0, 0, 0);
1019 printf(" unsigned, skipped\n");
1023 *sigpool = read_sigs();
1024 if (!checksig(*sigpool, fp, sigfp))
1026 printf(" checksig failed, skipped\n");
1034 #define CHKSUM_IDENT "1.1"
1037 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
1040 void *h = solv_chksum_create(chktype);
1043 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1044 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
1045 solv_chksum_add(h, buf, l);
1047 solv_chksum_free(h, out);
1051 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *out)
1053 void *h = solv_chksum_create(chktype);
1054 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1055 solv_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
1056 solv_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
1057 solv_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
1058 solv_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
1059 solv_chksum_free(h, out);
1071 pool_setarch(pool, un.machine);
1074 char *calccachepath(Repo *repo, const char *repoext)
1076 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
1079 p = pool_tmpappend(repo->pool, p, "_", repoext);
1080 p = pool_tmpappend(repo->pool, p, ".solvx", 0);
1083 p = pool_tmpappend(repo->pool, p, ".solv", 0);
1084 q = p + strlen(SOLVCACHE_PATH) + 1;
1094 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1097 unsigned char mycookie[32];
1098 unsigned char myextcookie[32];
1099 struct repoinfo *cinfo;
1102 cinfo = repo->appdata;
1103 if (!(fp = fopen(calccachepath(repo, repoext), "r")))
1105 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1110 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1115 if (cinfo && !repoext)
1117 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1128 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1129 if (strcmp(repoext, "DL") != 0)
1130 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1133 if (repo_add_solv(repo, fp, flags))
1138 if (cinfo && !repoext)
1140 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1141 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1144 futimes(fileno(fp), 0); /* try to set modification time */
1150 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1155 struct repoinfo *cinfo;
1158 cinfo = repo->appdata;
1159 mkdir(SOLVCACHE_PATH, 0755);
1160 /* use dupjoin instead of tmpjoin because tmpl must survive repo_write */
1161 tmpl = solv_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
1169 if (!(fp = fdopen(fd, "w")))
1178 for (i = repo->start; i < repo->end; i++)
1179 if (repo->pool->solvables[i].repo != repo)
1185 repo_write(repo, fp);
1187 repodata_write(info, fp);
1190 int oldnrepodata = repo->nrepodata;
1191 repo->nrepodata = oldnrepodata > 2 ? 2 : oldnrepodata; /* XXX: do this right */
1192 repo_write(repo, fp);
1193 repo->nrepodata = oldnrepodata;
1197 if (!repoext && cinfo)
1199 if (!cinfo->extcookie[0])
1201 /* create the ext cookie and append it */
1202 /* we just need some unique ID */
1204 if (!fstat(fileno(fp), &stb))
1208 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cinfo->extcookie);
1209 for (i = 0; i < 32; i++)
1210 cinfo->extcookie[i] ^= cookie[i];
1212 if (cinfo->extcookie[0] == 0)
1213 cinfo->extcookie[0] = 1;
1215 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1223 /* append our cookie describing the metadata state */
1224 if (fwrite(cookie, 32, 1, fp) != 1)
1239 /* switch to just saved repo to activate paging and save memory */
1240 FILE *fp = fopen(tmpl, "r");
1246 repo_empty(repo, 1);
1247 if (repo_add_solv(repo, fp, SOLV_ADD_NO_STUBS))
1249 /* oops, no way to recover from here */
1250 fprintf(stderr, "internal error\n");
1256 /* make sure repodata contains complete repo */
1257 /* (this is how repodata_write saves it) */
1258 repodata_extend_block(info, repo->start, repo->end - repo->start);
1259 info->state = REPODATA_LOADING;
1260 /* no need for LOCALPOOL as pool already contains ids */
1261 repo_add_solv(repo, fp, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1262 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1267 if (!rename(tmpl, calccachepath(repo, repoext)))
1274 /* repomd helpers */
1276 static inline const char *
1277 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1279 Pool *pool = repo->pool;
1281 const char *filename;
1286 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1287 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1288 if (dataiterator_step(&di))
1290 dataiterator_setpos_parent(&di);
1291 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1292 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1294 dataiterator_free(&di);
1295 if (filename && !*chksumtypep)
1297 printf("no %s file checksum!\n", what);
1304 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1306 Id chksumtype, handle;
1307 const unsigned char *chksum;
1308 const char *filename;
1310 filename = repomd_find(repo, what, &chksum, &chksumtype);
1313 if (!strcmp(what, "prestodelta"))
1315 handle = repodata_new_handle(data);
1316 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1317 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1318 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1319 if (!strcmp(what, "deltainfo"))
1321 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1322 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1324 if (!strcmp(what, "filelists"))
1326 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1327 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1329 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1334 repomd_load_ext(Repo *repo, Repodata *data)
1336 const char *filename, *repomdtype;
1339 struct repoinfo *cinfo;
1340 const unsigned char *filechksum;
1344 cinfo = repo->appdata;
1345 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1348 if (!strcmp(repomdtype, "filelists"))
1350 else if (!strcmp(repomdtype, "deltainfo"))
1355 printf("[%s:%s", repo->name, ext);
1357 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1359 printf(" cached]\n");fflush(stdout);
1362 printf(" fetching]\n"); fflush(stdout);
1363 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1365 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1366 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1368 if (!strcmp(ext, "FL"))
1369 r = repo_add_rpmmd(repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1370 else if (!strcmp(ext, "DL"))
1371 r = repo_add_deltainfoxml(repo, fp, REPO_USE_LOADING);
1375 printf("%s\n", pool_errstr(repo->pool));
1378 writecachedrepo(repo, data, ext, cinfo->extcookie);
1385 #ifdef ENABLE_SUSEREPO
1386 /* susetags helpers */
1388 static inline const char *
1389 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1391 Pool *pool = repo->pool;
1393 const char *filename;
1398 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
1399 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1400 if (dataiterator_step(&di))
1402 dataiterator_setpos_parent(&di);
1403 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
1406 dataiterator_free(&di);
1407 if (filename && !*chksumtypep)
1409 printf("no %s file checksum!\n", what);
1415 static Id susetags_langtags[] = {
1416 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
1417 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
1418 SOLVABLE_EULA, REPOKEY_TYPE_STR,
1419 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
1420 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
1421 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
1426 susetags_add_ext(Repo *repo, Repodata *data)
1428 Pool *pool = repo->pool;
1431 Id handle, filechksumtype;
1432 const unsigned char *filechksum;
1435 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
1436 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1437 while (dataiterator_step(&di))
1439 if (strncmp(di.kv.str, "packages.", 9) != 0)
1441 if (!strcmp(di.kv.str + 9, "gz"))
1443 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
1445 ext[0] = di.kv.str[9];
1446 ext[1] = di.kv.str[10];
1448 if (!strcmp(ext, "en"))
1450 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
1452 handle = repodata_new_handle(data);
1453 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
1455 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
1456 if (!strcmp(ext, "DU"))
1458 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
1459 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
1461 else if (!strcmp(ext, "FL"))
1463 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1464 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1468 for (i = 0; susetags_langtags[i]; i += 2)
1470 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
1471 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
1474 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1476 dataiterator_free(&di);
1480 susetags_load_ext(Repo *repo, Repodata *data)
1482 const char *filename, *descrdir;
1486 struct repoinfo *cinfo;
1487 const unsigned char *filechksum;
1490 cinfo = repo->appdata;
1491 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1495 ext[0] = filename[9];
1496 ext[1] = filename[10];
1499 printf("[%s:%s", repo->name, ext);
1501 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1503 printf(" cached]\n"); fflush(stdout);
1507 printf(" fetching]\n"); fflush(stdout);
1509 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1510 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1512 descrdir = "suse/setup/descr";
1514 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1515 if ((fp = curlfopen(cinfo, pool_tmpjoin(repo->pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1517 if (repo_add_susetags(repo, fp, defvendor, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES))
1520 printf("%s\n", pool_errstr(repo->pool));
1524 writecachedrepo(repo, data, ext, cinfo->extcookie);
1534 load_stub(Pool *pool, Repodata *data, void *dp)
1536 struct repoinfo *cinfo = data->repo->appdata;
1537 switch (cinfo->type)
1539 #ifdef ENABLE_SUSEREPO
1541 return susetags_load_ext(data->repo, data);
1545 return repomd_load_ext(data->repo, data);
1552 static unsigned char installedcookie[32];
1554 #ifdef ENABLE_DEBIAN
1557 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1561 unsigned char *chksum;
1566 static char *basearch;
1578 basearch = strdup(un.machine);
1579 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
1582 binarydir = solv_dupjoin("binary-", basearch, "/");
1583 lbinarydir = strlen(binarydir);
1584 compl = strlen(comp);
1588 chksum = solv_malloc(32);
1590 while(fgets(buf, sizeof(buf), fp))
1595 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1597 if (!strncasecmp(buf, "MD5Sum:", 7))
1599 curchksumtype = REPOKEY_TYPE_MD5;
1602 if (!strncasecmp(buf, "SHA1:", 5))
1604 curchksumtype = REPOKEY_TYPE_SHA1;
1607 if (!strncasecmp(buf, "SHA256:", 7))
1609 curchksumtype = REPOKEY_TYPE_SHA256;
1621 while (*bp && *bp != ' ' && *bp != '\t')
1626 while (*bp == ' ' || *bp == '\t')
1628 while (*bp && *bp != ' ' && *bp != '\t')
1632 while (*bp == ' ' || *bp == '\t')
1635 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1638 if (strncmp(bp, binarydir, lbinarydir))
1641 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1643 unsigned char curchksum[32];
1645 if (filename && !strcmp(bp, "Packages"))
1647 curl = solv_chksum_len(curchksumtype);
1648 if (!curl || (chksumtype && solv_chksum_len(chksumtype) > curl))
1650 if (solv_hex2bin((const char **)&ch, curchksum, sizeof(curchksum)) != curl)
1652 solv_free(filename);
1653 filename = strdup(fn);
1654 chksumtype = curchksumtype;
1655 memcpy(chksum, curchksum, curl);
1661 fn = solv_dupjoin("/", filename, 0);
1662 solv_free(filename);
1663 filename = solv_dupjoin("dists/", cinfo->name, fn);
1667 chksum = solv_free(chksum);
1669 *chksumtypep = chksumtype;
1675 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1678 struct repoinfo *cinfo;
1681 const char *filename;
1682 const unsigned char *filechksum;
1684 #ifdef ENABLE_SUSEREPO
1685 const char *descrdir;
1690 #if defined(ENABLE_SUSEREPO) || defined(ENABLE_RPMMD)
1695 #if defined(ENABLE_DEBIAN)
1700 repo = repo_create(pool, "@System");
1701 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1702 printf("rpm database:");
1703 if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/rpm/Packages"), &stb))
1704 memset(&stb, 0, sizeof(&stb));
1706 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1707 printf("dpgk database:");
1708 if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/dpkg/status"), &stb))
1709 memset(&stb, 0, sizeof(&stb));
1712 printf("no installed database:");
1713 memset(&stb, 0, sizeof(&stb));
1715 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, installedcookie);
1716 if (usecachedrepo(repo, 0, installedcookie, 0))
1717 printf(" cached\n");
1720 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1724 printf(" reading\n");
1726 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1727 # if defined(ENABLE_SUSEREPO) && defined(PRODUCTS_PATH)
1728 if (repo_add_products(repo, PRODUCTS_PATH, REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
1730 fprintf(stderr, "product reading failed: %s\n", pool_errstr(pool));
1734 if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
1736 ref = repo_create(pool, "@System.old");
1737 if (repo_add_solv(ref, ofp, 0))
1744 if (repo_add_rpmdb(repo, ref, REPO_REUSE_REPODATA | REPO_USE_ROOTDIR))
1746 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
1752 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1753 if (repo_add_debdb(repo, REPO_REUSE_REPODATA | REPO_USE_ROOTDIR))
1755 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
1759 writecachedrepo(repo, 0, 0, installedcookie);
1761 pool_set_installed(pool, repo);
1763 for (i = 0; i < nrepoinfos; i++)
1765 cinfo = repoinfos + i;
1766 if (!cinfo->enabled)
1769 repo = repo_create(pool, cinfo->alias);
1771 repo->appdata = cinfo;
1772 repo->priority = 99 - cinfo->priority;
1774 dorefresh = cinfo->autorefresh;
1775 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0), &stb) == 0)
1777 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1780 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1782 printf("repo '%s':", cinfo->alias);
1783 printf(" cached\n");
1787 switch (cinfo->type)
1791 printf("rpmmd repo '%s':", cinfo->alias);
1793 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1795 printf(" no repomd.xml file, skipped\n");
1800 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1801 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1803 printf(" cached\n");
1807 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "repodata/repomd.xml.asc", &sigpool))
1812 if (repo_add_repomdxml(repo, fp, 0))
1814 printf("repomd.xml: %s\n", pool_errstr(pool));
1816 break; /* hopeless */
1819 printf(" fetching\n");
1820 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1821 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1823 if (repo_add_rpmmd(repo, fp, 0, 0))
1825 printf("primary: %s\n", pool_errstr(pool));
1831 break; /* hopeless */
1833 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1834 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1836 if (repo_add_updateinfoxml(repo, fp, 0))
1838 printf("updateinfo: %s\n", pool_errstr(pool));
1844 data = repo_add_repodata(repo, 0);
1845 if (!repomd_add_ext(repo, data, "deltainfo"))
1846 repomd_add_ext(repo, data, "prestodelta");
1847 repomd_add_ext(repo, data, "filelists");
1848 repodata_internalize(data);
1850 writecachedrepo(repo, 0, 0, cinfo->cookie);
1851 repodata_create_stubs(repo_last_repodata(repo));
1855 #ifdef ENABLE_SUSEREPO
1857 printf("susetags repo '%s':", cinfo->alias);
1861 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1863 printf(" no content file, skipped\n");
1868 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1869 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1871 printf(" cached\n");
1875 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "content.asc", &sigpool))
1880 if (repo_add_content(repo, fp, 0))
1882 printf("content: %s\n", pool_errstr(pool));
1884 break; /* hopeless */
1887 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1888 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1890 descrdir = "suse/setup/descr";
1891 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1893 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1896 printf(" no packages file entry, skipped\n");
1899 printf(" fetching\n");
1900 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) == 0)
1901 break; /* hopeless */
1902 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES))
1904 printf("packages: %s\n", pool_errstr(pool));
1906 break; /* hopeless */
1909 /* add default language */
1910 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1912 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1915 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1917 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES))
1919 printf("packages.en: %s\n", pool_errstr(pool));
1925 filename = susetags_find(repo, "patterns", &filechksum, &filechksumtype);
1928 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1931 while (fgets(pbuf, sizeof(pbuf), fp))
1933 int l = strlen(pbuf);
1935 if (l && pbuf[l - 1] == '\n')
1937 if (!*pbuf || *pbuf == '.' || strchr(pbuf, '/') != 0)
1939 filename = susetags_find(repo, pbuf, &filechksum, &filechksumtype);
1940 if (filename && (fp2 = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1942 if (repo_add_susetags(repo, fp2, defvendor, 0, REPO_NO_INTERNALIZE))
1944 printf("%s: %s\n", pbuf, pool_errstr(pool));
1953 repo_internalize(repo);
1954 data = repo_add_repodata(repo, 0);
1955 susetags_add_ext(repo, data);
1956 repodata_internalize(data);
1958 writecachedrepo(repo, 0, 0, cinfo->cookie);
1959 repodata_create_stubs(repo_last_repodata(repo));
1963 #if defined(ENABLE_DEBIAN)
1965 printf("debian repo '%s':", cinfo->alias);
1967 filename = solv_dupjoin("dists/", cinfo->name, "/Release");
1968 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
1970 printf(" no Release file, skipped\n");
1973 free((char *)filename);
1976 solv_free((char *)filename);
1977 if (cinfo->repo_gpgcheck)
1979 filename = solv_dupjoin("dists/", cinfo->name, "/Release.gpg");
1980 if (!downloadchecksig(cinfo, fp, filename, &sigpool))
1983 solv_free((char *)filename);
1986 solv_free((char *)filename);
1988 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
1989 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1991 printf(" cached\n");
1995 printf(" fetching\n");
1996 for (j = 0; j < cinfo->ncomponents; j++)
1998 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
2000 printf("[component %s not found]\n", cinfo->components[j]);
2003 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
2005 if (repo_add_debpackages(repo, fp, 0))
2007 printf("component %s: %s\n", cinfo->components[j], pool_errstr(pool));
2012 solv_free((char *)filechksum);
2013 solv_free((char *)filename);
2017 writecachedrepo(repo, 0, 0, cinfo->cookie);
2022 printf("unsupported repo '%s': skipped\n", cinfo->alias);
2033 yesno(const char *str)
2035 char inbuf[128], *ip;
2042 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2047 while (*ip == ' ' || *ip == '\t')
2054 if (*ip == 'y' || *ip == 'n')
2055 return *ip == 'y' ? 1 : 0;
2059 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2069 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2071 struct fcstate *fcstate = cbdata;
2079 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
2082 s = pool_id2solvable(pool, p);
2083 if (pool->installed && s->repo == pool->installed)
2085 if (!s->repo->rpmdbid)
2087 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2090 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
2092 for (i = 0; i < fcstate->newpkgscnt; i++)
2093 if (fcstate->checkq->elements[i] == p)
2095 if (i == fcstate->newpkgscnt)
2097 fp = fcstate->newpkgsfps[i];
2101 return rpm_byfp(fp, pool_solvable2str(pool, s), &fcstate->rpmdbstate);
2106 runrpm(const char *arg, const char *name, int dupfd3, const char *rootdir)
2111 if ((pid = fork()) == (pid_t)-1)
2120 if (dupfd3 != -1 && dupfd3 != 3)
2126 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2127 if (strcmp(arg, "-e") == 0)
2128 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2130 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2134 while (waitpid(pid, &status, 0) != pid)
2138 printf("rpm failed\n");
2145 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2148 rundpkg(const char *arg, const char *name, int dupfd3, const char *rootdir)
2153 if ((pid = fork()) == (pid_t)-1)
2162 if (dupfd3 != -1 && dupfd3 != 3)
2168 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2169 if (strcmp(arg, "--install") == 0)
2170 execlp("dpkg", "dpkg", "--install", "--root", rootdir, "--force", "all", name, (char *)0);
2172 execlp("dpkg", "dpkg", "--remove", "--root", rootdir, "--force", "all", name, (char *)0);
2176 while (waitpid(pid, &status, 0) != pid)
2180 printf("dpkg failed\n");
2188 nscallback(Pool *pool, void *data, Id name, Id evr)
2190 if (name == NAMESPACE_PRODUCTBUDDY)
2192 /* SUSE specific hack: each product has an associated rpm */
2193 Solvable *s = pool->solvables + evr;
2197 cap = pool_str2id(pool, pool_tmpjoin(pool, "product(", pool_id2str(pool, s->name) + 8, ")"), 0);
2200 cap = pool_rel2id(pool, cap, s->evr, REL_EQ, 0);
2203 FOR_PROVIDES(p, pp, cap)
2205 Solvable *ps = pool->solvables + p;
2206 if (ps->repo == s->repo && ps->arch == s->arch)
2207 if (!bestp || pool_evrcmp(pool, pool->solvables[bestp].evr, ps->evr, EVRCMP_COMPARE) < 0)
2215 #ifdef SOFTLOCKS_PATH
2218 addsoftlocks(Pool *pool, Queue *job)
2222 char *bp, *ep, buf[4096];
2224 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2226 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2228 while (*bp == ' ' || *bp == '\t')
2230 if (!*bp || *bp == '#')
2232 for (ep = bp; *ep; ep++)
2233 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2236 type = SOLVER_SOLVABLE_NAME;
2237 if (!strncmp(bp, "provides:", 9) && bp[9])
2239 type = SOLVER_SOLVABLE_PROVIDES;
2242 id = pool_str2id(pool, bp, 1);
2243 if (pool->installed)
2245 FOR_JOB_SELECT(p, pp, type, id)
2246 if (pool->solvables[p].repo == pool->installed)
2249 continue; /* ignore, as it is already installed */
2251 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2260 rewrite_repos(Pool *pool, Queue *addedfileprovides, Queue *addedfileprovides_inst)
2265 Queue fileprovidesq;
2267 struct repoinfo *cinfo;
2269 map_init(&providedids, pool->ss.nstrings);
2270 queue_init(&fileprovidesq);
2271 for (i = 0; i < addedfileprovides->count; i++)
2272 MAPSET(&providedids, addedfileprovides->elements[i]);
2275 /* make sure all repodatas but the first are extensions */
2276 if (repo->nrepodata < 2)
2278 data = repo_id2repodata(repo, 1);
2279 if (data->loadcallback)
2281 for (j = 2; j < repo->nrepodata; j++)
2283 Repodata *edata = repo_id2repodata(repo, j);
2284 if (!edata->loadcallback)
2287 if (j < repo->nrepodata)
2288 continue; /* found a non-externsion repodata, can't rewrite */
2289 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2291 if (repo == pool->installed && addedfileprovides_inst)
2293 for (j = 0; j < addedfileprovides->count; j++)
2294 MAPCLR(&providedids, addedfileprovides->elements[j]);
2295 for (j = 0; j < addedfileprovides_inst->count; j++)
2296 MAPSET(&providedids, addedfileprovides_inst->elements[j]);
2299 for (j = 0; j < fileprovidesq.count; j++)
2300 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2302 if (repo == pool->installed && addedfileprovides_inst)
2304 for (j = 0; j < addedfileprovides_inst->count; j++)
2305 MAPCLR(&providedids, addedfileprovides_inst->elements[j]);
2306 for (j = 0; j < addedfileprovides->count; j++)
2307 MAPSET(&providedids, addedfileprovides->elements[j]);
2308 if (n == addedfileprovides_inst->count)
2309 continue; /* nothing new added */
2311 else if (n == addedfileprovides->count)
2312 continue; /* nothing new added */
2314 repodata_set_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, repo == pool->installed && addedfileprovides_inst ? addedfileprovides_inst : addedfileprovides);
2315 repodata_internalize(data);
2316 cinfo = repo->appdata;
2317 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2319 queue_free(&fileprovidesq);
2320 map_free(&providedids);
2324 select_patches(Pool *pool, Queue *job)
2328 Map installedmap, noobsmap;
2331 map_init(&noobsmap, 0);
2332 map_init(&installedmap, pool->nsolvables);
2333 solver_calculate_noobsmap(pool, job, &noobsmap);
2334 if (pool->installed)
2335 FOR_REPO_SOLVABLES(pool->installed, p, s)
2336 MAPSET(&installedmap, p);
2338 /* install all patches */
2339 for (p = 1; p < pool->nsolvables; p++)
2345 s = pool->solvables + p;
2346 if (strncmp(pool_id2str(pool, s->name), "patch:", 6) != 0)
2348 FOR_PROVIDES(p2, pp, s->name)
2350 Solvable *s2 = pool->solvables + p2;
2351 if (s2->name != s->name)
2353 r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2354 if (r < 0 || (r == 0 && p > p2))
2359 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2360 if (type && !strcmp(type, "optional"))
2362 r = solvable_trivial_installable_map(s, &installedmap, 0, &noobsmap);
2365 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2372 queue_push2(job, SOLVER_SOLVABLE, p);
2374 map_free(&installedmap);
2375 map_free(&noobsmap);
2379 #define MODE_INSTALL 1
2380 #define MODE_ERASE 2
2381 #define MODE_UPDATE 3
2382 #define MODE_DISTUPGRADE 4
2383 #define MODE_VERIFY 5
2384 #define MODE_PATCH 6
2386 #define MODE_REPOLIST 8
2387 #define MODE_SEARCH 9
2392 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2393 fprintf(stderr, "\n");
2394 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2395 fprintf(stderr, " versions from the repositories\n");
2396 fprintf(stderr, " erase: erase installed packages\n");
2397 fprintf(stderr, " info: display package information\n");
2398 fprintf(stderr, " install: install packages\n");
2399 fprintf(stderr, " list: list packages\n");
2400 fprintf(stderr, " repos: list enabled repositories\n");
2401 fprintf(stderr, " search: search name/summary/description\n");
2402 fprintf(stderr, " update: update installed packages\n");
2403 fprintf(stderr, " verify: check dependencies of installed packages\n");
2404 fprintf(stderr, "\n");
2409 main(int argc, char **argv)
2412 Repo *commandlinerepo = 0;
2413 Id *commandlinepkgs = 0;
2415 struct repoinfo *repoinfos;
2417 int mainmode = 0, mode = 0;
2422 char inbuf[128], *ip;
2424 Queue addedfileprovides;
2425 Queue addedfileprovides_inst;
2434 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2436 mainmode = MODE_INSTALL;
2437 mode = SOLVER_INSTALL;
2439 else if (!strcmp(argv[0], "patch"))
2441 mainmode = MODE_PATCH;
2442 mode = SOLVER_INSTALL;
2444 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2446 mainmode = MODE_ERASE;
2447 mode = SOLVER_ERASE;
2449 else if (!strcmp(argv[0], "list"))
2451 mainmode = MODE_LIST;
2454 else if (!strcmp(argv[0], "info"))
2456 mainmode = MODE_INFO;
2459 else if (!strcmp(argv[0], "search"))
2461 mainmode = MODE_SEARCH;
2464 else if (!strcmp(argv[0], "verify"))
2466 mainmode = MODE_VERIFY;
2467 mode = SOLVER_VERIFY;
2469 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2471 mainmode = MODE_UPDATE;
2472 mode = SOLVER_UPDATE;
2474 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2476 mainmode = MODE_DISTUPGRADE;
2477 mode = SOLVER_UPDATE;
2479 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2481 mainmode = MODE_REPOLIST;
2489 if (argc > 2 && !strcmp(argv[1], "--root"))
2496 else if (argc > 1 && !strcmp(argv[1], "--clean"))
2506 pool = pool_create();
2507 pool_set_rootdir(pool, rootdir);
2511 const char *langs[] = {"de_DE", "de", "en"};
2512 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2516 pool_setloadcallback(pool, load_stub, 0);
2517 pool->nscallback = nscallback;
2518 // pool_setdebuglevel(pool, 2);
2520 repoinfos = read_repoinfos(pool, &nrepoinfos);
2522 if (mainmode == MODE_REPOLIST)
2525 for (i = 0; i < nrepoinfos; i++)
2527 struct repoinfo *cinfo = repoinfos + i;
2528 if (!cinfo->enabled)
2530 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2535 read_repos(pool, repoinfos, nrepoinfos);
2537 queue_init(&repofilter);
2538 while (argc > 2 && !strcmp(argv[1], "-r"))
2540 const char *rname = argv[2], *rp;
2542 for (rp = rname; *rp; rp++)
2543 if (*rp <= '0' || *rp >= '9')
2547 /* repo specified by number */
2548 int rnum = atoi(rname);
2549 for (i = 0; i < nrepoinfos; i++)
2551 struct repoinfo *cinfo = repoinfos + i;
2552 if (!cinfo->enabled)
2555 repoid = cinfo->repo->repoid;
2560 /* repo specified by alias */
2564 if (!strcasecmp(rname, repo->name))
2565 repoid = repo->repoid;
2570 fprintf(stderr, "%s: no such repo\n", rname);
2573 /* SETVENDOR is actually wrong but useful */
2574 queue_push2(&repofilter, SOLVER_SOLVABLE_REPO | SOLVER_SETREPO | SOLVER_SETVENDOR, repoid);
2578 if (mainmode == MODE_SEARCH)
2584 map_init(&m, pool->nsolvables);
2585 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2586 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2587 dataiterator_set_search(&di, 0, 0);
2588 while (dataiterator_step(&di))
2589 MAPSET(&m, di.solvid);
2590 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2591 dataiterator_set_search(&di, 0, 0);
2592 while (dataiterator_step(&di))
2593 MAPSET(&m, di.solvid);
2594 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2595 dataiterator_set_search(&di, 0, 0);
2596 while (dataiterator_step(&di))
2597 MAPSET(&m, di.solvid);
2598 dataiterator_free(&di);
2600 for (p = 1; p < pool->nsolvables; p++)
2602 Solvable *s = pool_id2solvable(pool, p);
2605 printf(" - %s: %s\n", pool_solvable2str(pool, s), solvable_lookup_str(s, SOLVABLE_SUMMARY));
2612 if (mainmode == MODE_LIST || mainmode == MODE_INSTALL)
2614 for (i = 1; i < argc; i++)
2617 l = strlen(argv[i]);
2618 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2619 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2622 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2623 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2626 if (access(argv[i], R_OK))
2631 if (!commandlinepkgs)
2632 commandlinepkgs = solv_calloc(argc, sizeof(Id));
2633 if (!commandlinerepo)
2634 commandlinerepo = repo_create(pool, "@commandline");
2636 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2637 p = repo_add_rpm(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2639 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2640 p = repo_add_deb(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2644 fprintf(stderr, "could not add '%s'\n", argv[i]);
2647 commandlinepkgs[i] = p;
2649 if (commandlinerepo)
2650 repo_internalize(commandlinerepo);
2653 // FOR_REPOS(i, repo)
2654 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2655 queue_init(&addedfileprovides);
2656 queue_init(&addedfileprovides_inst);
2657 pool_addfileprovides_queue(pool, &addedfileprovides, &addedfileprovides_inst);
2658 if (addedfileprovides.count || addedfileprovides_inst.count)
2659 rewrite_repos(pool, &addedfileprovides, &addedfileprovides_inst);
2660 queue_free(&addedfileprovides);
2661 queue_free(&addedfileprovides_inst);
2662 pool_createwhatprovides(pool);
2665 for (i = 1; i < argc; i++)
2668 int j, flags, rflags;
2670 if (commandlinepkgs && commandlinepkgs[i])
2672 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2676 flags = SELECTION_NAME|SELECTION_PROVIDES|SELECTION_GLOB;
2677 if (argv[i][0] == '/')
2678 flags |= SELECTION_FILELIST | (mode == MODE_ERASE ? SELECTION_INSTALLED_ONLY : 0);
2679 rflags = selection_make(pool, &job2, argv[i], flags);
2680 if (repofilter.count)
2681 selection_limit(pool, &job2, &repofilter);
2684 flags |= SELECTION_NOCASE;
2685 rflags = selection_make(pool, &job2, argv[i], flags);
2686 if (repofilter.count)
2687 selection_limit(pool, &job2, &repofilter);
2689 printf("[ignoring case for '%s']\n", argv[i]);
2693 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2696 if (rflags & SELECTION_FILELIST)
2697 printf("[using file list match for '%s']\n", argv[i]);
2698 if (rflags & SELECTION_PROVIDES)
2699 printf("[using capability match for '%s']\n", argv[i]);
2700 for (j = 0; j < job2.count; j++)
2701 queue_push(&job, job2.elements[j]);
2705 if (!job.count && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE || mainmode == MODE_VERIFY || repofilter.count))
2707 queue_push2(&job, SOLVER_SOLVABLE_ALL, 0);
2708 if (repofilter.count)
2709 selection_limit(pool, &job, &repofilter);
2711 queue_free(&repofilter);
2713 if (!job.count && MODE_PATCH)
2715 printf("no package matched\n");
2719 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
2721 /* list mode, no solver needed */
2724 for (i = 0; i < job.count; i += 2)
2728 pool_job2solvables(pool, &q, job.elements[i], job.elements[i + 1]);
2729 for (j = 0; j < q.count; j++)
2731 Solvable *s = pool_id2solvable(pool, q.elements[j]);
2732 if (mainmode == MODE_INFO)
2735 printf("Name: %s\n", pool_solvable2str(pool, s));
2736 printf("Repo: %s\n", s->repo->name);
2737 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
2738 str = solvable_lookup_str(s, SOLVABLE_URL);
2740 printf("Url: %s\n", str);
2741 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
2743 printf("License: %s\n", str);
2744 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
2750 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
2752 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
2754 printf(" - %s [%s]\n", pool_solvable2str(pool, s), s->repo->name);
2756 printf(" %s\n", sum);
2763 free_repoinfos(repoinfos, nrepoinfos);
2764 solv_free(commandlinepkgs);
2766 yum_substitute(pool, 0);
2771 if (mainmode == MODE_PATCH)
2772 select_patches(pool, &job);
2775 for (i = 0; i < job.count; i += 2)
2777 if (mode == SOLVER_UPDATE)
2779 /* make update of not installed packages an install */
2780 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
2781 if (pool->installed && pool->solvables[p].repo == pool->installed)
2785 job.elements[i] |= SOLVER_INSTALL;
2787 job.elements[i] |= SOLVER_CLEANDEPS;
2791 job.elements[i] |= mode;
2793 job.elements[i] |= SOLVER_CLEANDEPS;
2796 // multiversion test
2797 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae", 1));
2798 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-base", 1));
2799 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-extra", 1));
2801 #ifdef SOFTLOCKS_PATH
2802 addsoftlocks(pool, &job);
2805 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2810 Id problem, solution;
2813 solv = solver_create(pool);
2814 solver_set_flag(solv, SOLVER_FLAG_SPLITPROVIDES, 1);
2815 if (mainmode == MODE_ERASE)
2816 solver_set_flag(solv, SOLVER_FLAG_ALLOW_UNINSTALL, 1); /* don't nag */
2818 if (!solver_solve(solv, &job))
2820 pcnt = solver_problem_count(solv);
2821 printf("Found %d problems:\n", pcnt);
2822 for (problem = 1; problem <= pcnt; problem++)
2825 printf("Problem %d:\n", problem);
2826 solver_printprobleminfo(solv, problem);
2828 scnt = solver_solution_count(solv, problem);
2829 for (solution = 1; solution <= scnt; solution++)
2831 printf("Solution %d:\n", solution);
2832 solver_printsolution(solv, problem, solution);
2837 printf("Please choose a solution: ");
2840 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2845 while (*ip == ' ' || *ip == '\t')
2847 if (*ip >= '0' && *ip <= '9')
2850 if (take >= 1 && take <= scnt)
2866 solver_take_solution(solv, problem, take, &job);
2872 trans = solver_create_transaction(solv);
2873 if (!trans->steps.count)
2875 printf("Nothing to do.\n");
2876 transaction_free(trans);
2880 free_repoinfos(repoinfos, nrepoinfos);
2881 solv_free(commandlinepkgs);
2883 yum_substitute(pool, 0);
2888 printf("Transaction summary:\n\n");
2889 transaction_print(trans);
2898 duc[1].path = "/usr/share/man";
2899 duc[2].path = "/sbin";
2900 duc[3].path = "/etc";
2901 transaction_calc_duchanges(trans, duc, 4);
2902 for (i = 0; i < 4; i++)
2903 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
2906 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
2909 if (!yesno("OK to continue (y/n)? "))
2912 transaction_free(trans);
2916 free_repoinfos(repoinfos, nrepoinfos);
2917 solv_free(commandlinepkgs);
2919 yum_substitute(pool, 0);
2924 queue_init(&checkq);
2925 newpkgs = transaction_installedresult(trans, &checkq);
2930 int downloadsize = 0;
2931 for (i = 0; i < newpkgs; i++)
2935 p = checkq.elements[i];
2936 s = pool_id2solvable(pool, p);
2937 downloadsize += solvable_lookup_sizek(s, SOLVABLE_DOWNLOADSIZE, 0);
2939 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
2940 newpkgsfps = solv_calloc(newpkgs, sizeof(*newpkgsfps));
2941 for (i = 0; i < newpkgs; i++)
2943 unsigned int medianr;
2946 struct repoinfo *cinfo;
2947 const unsigned char *chksum;
2951 p = checkq.elements[i];
2952 s = pool_id2solvable(pool, p);
2953 if (s->repo == commandlinerepo)
2955 loc = solvable_get_location(s, &medianr);
2956 if (!(newpkgsfps[i] = fopen(loc, "r")))
2964 cinfo = s->repo->appdata;
2967 printf("%s: no repository information\n", s->repo->name);
2970 loc = solvable_get_location(s, &medianr);
2974 if (pool->installed && pool->installed->nsolvables)
2976 /* try a delta first */
2977 char *matchname = strdup(pool_id2str(pool, s->name));
2978 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
2979 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
2980 while (dataiterator_step(&di))
2984 dataiterator_setpos_parent(&di);
2985 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
2986 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
2988 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
2989 FOR_PROVIDES(op, pp, s->name)
2991 Solvable *os = pool->solvables + op;
2992 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
2995 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
2997 /* base is installed, run sequence check */
2998 const char *seqname;
3003 const char *archstr;
3008 archstr = pool_id2str(pool, s->arch);
3009 if (strlen(archstr) > 10 || strchr(archstr, '\'') != 0)
3012 seqname = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME);
3013 seqevr = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR);
3014 seqnum = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM);
3015 seq = pool_tmpjoin(pool, seqname, "-", seqevr);
3016 seq = pool_tmpappend(pool, seq, "-", seqnum);
3017 if (strchr(seq, '\'') != 0)
3020 sprintf(cmd, "/usr/bin/applydeltarpm -a '%s' -c -s '", archstr);
3022 sprintf(cmd, "/usr/bin/applydeltarpm -c -s '");
3024 if (system(pool_tmpjoin(pool, cmd, seq, "'")) != 0)
3025 continue; /* didn't match */
3026 /* looks good, download delta */
3028 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
3030 continue; /* no way! */
3031 dloc = pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_DIR);
3032 dloc = pool_tmpappend(pool, dloc, "/", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_NAME));
3033 dloc = pool_tmpappend(pool, dloc, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_EVR));
3034 dloc = pool_tmpappend(pool, dloc, ".", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_SUFFIX));
3035 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
3037 /* got it, now reconstruct */
3038 newfd = opentmpfile();
3040 sprintf(cmd, "applydeltarpm -a '%s' /dev/fd/%d /dev/fd/%d", archstr, fileno(fp), newfd);
3042 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
3044 fcntl(fileno(fp), F_SETFD, 0);
3051 lseek(newfd, 0, SEEK_SET);
3053 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3054 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
3060 newpkgsfps[i] = fdopen(newfd, "r");
3065 dataiterator_free(&di);
3066 solv_free(matchname);
3073 continue; /* delta worked! */
3075 if (cinfo->type == TYPE_SUSETAGS)
3077 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3078 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3081 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3082 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3084 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3093 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3097 struct fcstate fcstate;
3099 printf("Searching for file conflicts\n");
3100 queue_init(&conflicts);
3101 fcstate.rpmdbstate = 0;
3102 fcstate.newpkgscnt = newpkgs;
3103 fcstate.checkq = &checkq;
3104 fcstate.newpkgsfps = newpkgsfps;
3105 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fileconflict_cb, &fcstate);
3106 if (conflicts.count)
3109 for (i = 0; i < conflicts.count; i += 5)
3110 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]));
3112 if (yesno("Re-run solver (y/n/q)? "))
3114 for (i = 0; i < newpkgs; i++)
3116 fclose(newpkgsfps[i]);
3117 newpkgsfps = solv_free(newpkgsfps);
3119 pool_add_fileconflicts_deps(pool, &conflicts);
3120 pool_createwhatprovides(pool); /* Hmm... */
3124 queue_free(&conflicts);
3128 printf("Committing transaction:\n\n");
3129 transaction_order(trans, 0);
3130 for (i = 0; i < trans->steps.count; i++)
3132 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3133 const char *evr, *evrp, *nvra;
3139 p = trans->steps.elements[i];
3140 s = pool_id2solvable(pool, p);
3141 Id type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3144 case SOLVER_TRANSACTION_ERASE:
3145 printf("erase %s\n", pool_solvid2str(pool, p));
3146 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3147 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3149 /* strip epoch from evr */
3150 evr = evrp = pool_id2str(pool, s->evr);
3151 while (*evrp >= '0' && *evrp <= '9')
3153 if (evrp > evr && evrp[0] == ':' && evrp[1])
3155 nvra = pool_tmpjoin(pool, pool_id2str(pool, s->name), "-", evr);
3156 nvra = pool_tmpappend(pool, nvra, ".", pool_id2str(pool, s->arch));
3157 runrpm("-e", nvra, -1, rootdir); /* too bad that --querybynumber doesn't work */
3159 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3160 rundpkg("--remove", pool_id2str(pool, s->name), 0, rootdir);
3163 case SOLVER_TRANSACTION_INSTALL:
3164 case SOLVER_TRANSACTION_MULTIINSTALL:
3165 printf("install %s\n", pool_solvid2str(pool, p));
3166 for (j = 0; j < newpkgs; j++)
3167 if (checkq.elements[j] == p)
3169 fp = j < newpkgs ? newpkgsfps[j] : 0;
3173 lseek(fileno(fp), 0, SEEK_SET);
3174 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3175 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp), rootdir);
3177 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3178 rundpkg("--install", "/dev/fd/3", fileno(fp), rootdir);
3188 for (i = 0; i < newpkgs; i++)
3190 fclose(newpkgsfps[i]);
3191 solv_free(newpkgsfps);
3192 queue_free(&checkq);
3193 transaction_free(trans);
3197 free_repoinfos(repoinfos, nrepoinfos);
3198 solv_free(commandlinepkgs);
3200 yum_substitute(pool, 0);