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 *cookie, unsigned char *out)
1053 void *h = solv_chksum_create(chktype);
1054 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1056 solv_chksum_add(h, cookie, 32);
1057 solv_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
1058 solv_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
1059 solv_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
1060 solv_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
1061 solv_chksum_free(h, out);
1073 pool_setarch(pool, un.machine);
1076 char *calccachepath(Repo *repo, const char *repoext)
1078 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
1081 p = pool_tmpappend(repo->pool, p, "_", repoext);
1082 p = pool_tmpappend(repo->pool, p, ".solvx", 0);
1085 p = pool_tmpappend(repo->pool, p, ".solv", 0);
1086 q = p + strlen(SOLVCACHE_PATH) + 1;
1096 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1099 unsigned char mycookie[32];
1100 unsigned char myextcookie[32];
1101 struct repoinfo *cinfo;
1104 cinfo = repo->appdata;
1105 if (!(fp = fopen(calccachepath(repo, repoext), "r")))
1107 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1112 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1117 if (cinfo && !repoext)
1119 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1130 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1131 if (strcmp(repoext, "DL") != 0)
1132 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1135 if (repo_add_solv(repo, fp, flags))
1140 if (cinfo && !repoext)
1142 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1143 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1146 futimes(fileno(fp), 0); /* try to set modification time */
1152 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1157 struct repoinfo *cinfo;
1160 cinfo = repo->appdata;
1161 mkdir(SOLVCACHE_PATH, 0755);
1162 /* use dupjoin instead of tmpjoin because tmpl must survive repo_write */
1163 tmpl = solv_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
1171 if (!(fp = fdopen(fd, "w")))
1180 for (i = repo->start; i < repo->end; i++)
1181 if (repo->pool->solvables[i].repo != repo)
1187 repo_write(repo, fp);
1189 repodata_write(info, fp);
1192 int oldnrepodata = repo->nrepodata;
1193 repo->nrepodata = oldnrepodata > 2 ? 2 : oldnrepodata; /* XXX: do this right */
1194 repo_write(repo, fp);
1195 repo->nrepodata = oldnrepodata;
1199 if (!repoext && cinfo)
1201 if (!cinfo->extcookie[0])
1203 /* create the ext cookie and append it */
1204 /* we just need some unique ID */
1206 if (!fstat(fileno(fp), &stb))
1207 memset(&stb, 0, sizeof(stb));
1208 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cookie, cinfo->extcookie);
1209 if (cinfo->extcookie[0] == 0)
1210 cinfo->extcookie[0] = 1;
1212 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1220 /* append our cookie describing the metadata state */
1221 if (fwrite(cookie, 32, 1, fp) != 1)
1236 /* switch to just saved repo to activate paging and save memory */
1237 FILE *fp = fopen(tmpl, "r");
1243 repo_empty(repo, 1);
1244 if (repo_add_solv(repo, fp, SOLV_ADD_NO_STUBS))
1246 /* oops, no way to recover from here */
1247 fprintf(stderr, "internal error\n");
1253 /* make sure repodata contains complete repo */
1254 /* (this is how repodata_write saves it) */
1255 repodata_extend_block(info, repo->start, repo->end - repo->start);
1256 info->state = REPODATA_LOADING;
1257 /* no need for LOCALPOOL as pool already contains ids */
1258 repo_add_solv(repo, fp, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1259 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1264 if (!rename(tmpl, calccachepath(repo, repoext)))
1271 /* repomd helpers */
1273 static inline const char *
1274 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1276 Pool *pool = repo->pool;
1278 const char *filename;
1283 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1284 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1285 if (dataiterator_step(&di))
1287 dataiterator_setpos_parent(&di);
1288 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1289 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1291 dataiterator_free(&di);
1292 if (filename && !*chksumtypep)
1294 printf("no %s file checksum!\n", what);
1301 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1303 Id chksumtype, handle;
1304 const unsigned char *chksum;
1305 const char *filename;
1307 filename = repomd_find(repo, what, &chksum, &chksumtype);
1310 if (!strcmp(what, "prestodelta"))
1312 handle = repodata_new_handle(data);
1313 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1314 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1315 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1316 if (!strcmp(what, "deltainfo"))
1318 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1319 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1321 if (!strcmp(what, "filelists"))
1323 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1324 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1326 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1331 repomd_load_ext(Repo *repo, Repodata *data)
1333 const char *filename, *repomdtype;
1336 struct repoinfo *cinfo;
1337 const unsigned char *filechksum;
1341 cinfo = repo->appdata;
1342 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1345 if (!strcmp(repomdtype, "filelists"))
1347 else if (!strcmp(repomdtype, "deltainfo"))
1352 printf("[%s:%s", repo->name, ext);
1354 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1356 printf(" cached]\n");fflush(stdout);
1359 printf(" fetching]\n"); fflush(stdout);
1360 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1362 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1363 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1365 if (!strcmp(ext, "FL"))
1366 r = repo_add_rpmmd(repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1367 else if (!strcmp(ext, "DL"))
1368 r = repo_add_deltainfoxml(repo, fp, REPO_USE_LOADING);
1372 printf("%s\n", pool_errstr(repo->pool));
1375 writecachedrepo(repo, data, ext, cinfo->extcookie);
1382 #ifdef ENABLE_SUSEREPO
1383 /* susetags helpers */
1385 static inline const char *
1386 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1388 Pool *pool = repo->pool;
1390 const char *filename;
1395 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
1396 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1397 if (dataiterator_step(&di))
1399 dataiterator_setpos_parent(&di);
1400 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
1403 dataiterator_free(&di);
1404 if (filename && !*chksumtypep)
1406 printf("no %s file checksum!\n", what);
1412 static Id susetags_langtags[] = {
1413 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
1414 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
1415 SOLVABLE_EULA, REPOKEY_TYPE_STR,
1416 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
1417 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
1418 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
1423 susetags_add_ext(Repo *repo, Repodata *data)
1425 Pool *pool = repo->pool;
1428 Id handle, filechksumtype;
1429 const unsigned char *filechksum;
1432 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
1433 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1434 while (dataiterator_step(&di))
1436 if (strncmp(di.kv.str, "packages.", 9) != 0)
1438 if (!strcmp(di.kv.str + 9, "gz"))
1440 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
1442 ext[0] = di.kv.str[9];
1443 ext[1] = di.kv.str[10];
1445 if (!strcmp(ext, "en"))
1447 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
1449 handle = repodata_new_handle(data);
1450 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
1452 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
1453 if (!strcmp(ext, "DU"))
1455 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
1456 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
1458 else if (!strcmp(ext, "FL"))
1460 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1461 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1465 for (i = 0; susetags_langtags[i]; i += 2)
1467 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
1468 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
1471 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1473 dataiterator_free(&di);
1477 susetags_load_ext(Repo *repo, Repodata *data)
1479 const char *filename, *descrdir;
1483 struct repoinfo *cinfo;
1484 const unsigned char *filechksum;
1487 cinfo = repo->appdata;
1488 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1492 ext[0] = filename[9];
1493 ext[1] = filename[10];
1496 printf("[%s:%s", repo->name, ext);
1498 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1500 printf(" cached]\n"); fflush(stdout);
1504 printf(" fetching]\n"); fflush(stdout);
1506 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1507 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1509 descrdir = "suse/setup/descr";
1511 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1512 if ((fp = curlfopen(cinfo, pool_tmpjoin(repo->pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1514 if (repo_add_susetags(repo, fp, defvendor, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES))
1517 printf("%s\n", pool_errstr(repo->pool));
1521 writecachedrepo(repo, data, ext, cinfo->extcookie);
1531 load_stub(Pool *pool, Repodata *data, void *dp)
1533 struct repoinfo *cinfo = data->repo->appdata;
1534 switch (cinfo->type)
1536 #ifdef ENABLE_SUSEREPO
1538 return susetags_load_ext(data->repo, data);
1542 return repomd_load_ext(data->repo, data);
1549 static unsigned char installedcookie[32];
1551 #ifdef ENABLE_DEBIAN
1554 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1558 unsigned char *chksum;
1563 static char *basearch;
1575 basearch = strdup(un.machine);
1576 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
1579 binarydir = solv_dupjoin("binary-", basearch, "/");
1580 lbinarydir = strlen(binarydir);
1581 compl = strlen(comp);
1585 chksum = solv_malloc(32);
1587 while(fgets(buf, sizeof(buf), fp))
1592 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1594 if (!strncasecmp(buf, "MD5Sum:", 7))
1596 curchksumtype = REPOKEY_TYPE_MD5;
1599 if (!strncasecmp(buf, "SHA1:", 5))
1601 curchksumtype = REPOKEY_TYPE_SHA1;
1604 if (!strncasecmp(buf, "SHA256:", 7))
1606 curchksumtype = REPOKEY_TYPE_SHA256;
1618 while (*bp && *bp != ' ' && *bp != '\t')
1623 while (*bp == ' ' || *bp == '\t')
1625 while (*bp && *bp != ' ' && *bp != '\t')
1629 while (*bp == ' ' || *bp == '\t')
1632 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1635 if (strncmp(bp, binarydir, lbinarydir))
1638 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1640 unsigned char curchksum[32];
1642 if (filename && !strcmp(bp, "Packages"))
1644 curl = solv_chksum_len(curchksumtype);
1645 if (!curl || (chksumtype && solv_chksum_len(chksumtype) > curl))
1647 if (solv_hex2bin((const char **)&ch, curchksum, sizeof(curchksum)) != curl)
1649 solv_free(filename);
1650 filename = strdup(fn);
1651 chksumtype = curchksumtype;
1652 memcpy(chksum, curchksum, curl);
1658 fn = solv_dupjoin("/", filename, 0);
1659 solv_free(filename);
1660 filename = solv_dupjoin("dists/", cinfo->name, fn);
1664 chksum = solv_free(chksum);
1666 *chksumtypep = chksumtype;
1672 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1675 struct repoinfo *cinfo;
1678 const char *filename;
1679 const unsigned char *filechksum;
1681 #ifdef ENABLE_SUSEREPO
1682 const char *descrdir;
1687 #if defined(ENABLE_SUSEREPO) || defined(ENABLE_RPMMD)
1692 #if defined(ENABLE_DEBIAN)
1697 repo = repo_create(pool, "@System");
1698 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1699 printf("rpm database:");
1700 if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/rpm/Packages"), &stb))
1701 memset(&stb, 0, sizeof(&stb));
1703 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1704 printf("dpgk database:");
1705 if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/dpkg/status"), &stb))
1706 memset(&stb, 0, sizeof(&stb));
1709 printf("no installed database:");
1710 memset(&stb, 0, sizeof(&stb));
1712 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, 0, installedcookie);
1713 if (usecachedrepo(repo, 0, installedcookie, 0))
1714 printf(" cached\n");
1717 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1721 printf(" reading\n");
1723 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1724 # if defined(ENABLE_SUSEREPO) && defined(PRODUCTS_PATH)
1725 if (repo_add_products(repo, PRODUCTS_PATH, REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
1727 fprintf(stderr, "product reading failed: %s\n", pool_errstr(pool));
1731 if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
1733 ref = repo_create(pool, "@System.old");
1734 if (repo_add_solv(ref, ofp, 0))
1741 if (repo_add_rpmdb(repo, ref, REPO_REUSE_REPODATA | REPO_USE_ROOTDIR))
1743 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
1749 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1750 if (repo_add_debdb(repo, REPO_REUSE_REPODATA | REPO_USE_ROOTDIR))
1752 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
1756 writecachedrepo(repo, 0, 0, installedcookie);
1758 pool_set_installed(pool, repo);
1760 for (i = 0; i < nrepoinfos; i++)
1762 cinfo = repoinfos + i;
1763 if (!cinfo->enabled)
1766 repo = repo_create(pool, cinfo->alias);
1768 repo->appdata = cinfo;
1769 repo->priority = 99 - cinfo->priority;
1771 dorefresh = cinfo->autorefresh;
1772 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0), &stb) == 0)
1774 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1777 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1779 printf("repo '%s':", cinfo->alias);
1780 printf(" cached\n");
1784 switch (cinfo->type)
1788 printf("rpmmd repo '%s':", cinfo->alias);
1790 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1792 printf(" no repomd.xml file, skipped\n");
1797 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1798 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1800 printf(" cached\n");
1804 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "repodata/repomd.xml.asc", &sigpool))
1809 if (repo_add_repomdxml(repo, fp, 0))
1811 printf("repomd.xml: %s\n", pool_errstr(pool));
1813 break; /* hopeless */
1816 printf(" fetching\n");
1817 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1818 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1820 if (repo_add_rpmmd(repo, fp, 0, 0))
1822 printf("primary: %s\n", pool_errstr(pool));
1828 break; /* hopeless */
1830 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1831 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1833 if (repo_add_updateinfoxml(repo, fp, 0))
1835 printf("updateinfo: %s\n", pool_errstr(pool));
1841 data = repo_add_repodata(repo, 0);
1842 if (!repomd_add_ext(repo, data, "deltainfo"))
1843 repomd_add_ext(repo, data, "prestodelta");
1844 repomd_add_ext(repo, data, "filelists");
1845 repodata_internalize(data);
1847 writecachedrepo(repo, 0, 0, cinfo->cookie);
1848 repodata_create_stubs(repo_last_repodata(repo));
1852 #ifdef ENABLE_SUSEREPO
1854 printf("susetags repo '%s':", cinfo->alias);
1858 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1860 printf(" no content file, skipped\n");
1865 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1866 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1868 printf(" cached\n");
1872 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "content.asc", &sigpool))
1877 if (repo_add_content(repo, fp, 0))
1879 printf("content: %s\n", pool_errstr(pool));
1881 break; /* hopeless */
1884 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1885 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1887 descrdir = "suse/setup/descr";
1888 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1890 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1893 printf(" no packages file entry, skipped\n");
1896 printf(" fetching\n");
1897 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) == 0)
1898 break; /* hopeless */
1899 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES))
1901 printf("packages: %s\n", pool_errstr(pool));
1903 break; /* hopeless */
1906 /* add default language */
1907 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1909 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1912 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1914 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES))
1916 printf("packages.en: %s\n", pool_errstr(pool));
1922 filename = susetags_find(repo, "patterns", &filechksum, &filechksumtype);
1925 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1928 while (fgets(pbuf, sizeof(pbuf), fp))
1930 int l = strlen(pbuf);
1932 if (l && pbuf[l - 1] == '\n')
1934 if (!*pbuf || *pbuf == '.' || strchr(pbuf, '/') != 0)
1936 filename = susetags_find(repo, pbuf, &filechksum, &filechksumtype);
1937 if (filename && (fp2 = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1939 if (repo_add_susetags(repo, fp2, defvendor, 0, REPO_NO_INTERNALIZE))
1941 printf("%s: %s\n", pbuf, pool_errstr(pool));
1950 repo_internalize(repo);
1951 data = repo_add_repodata(repo, 0);
1952 susetags_add_ext(repo, data);
1953 repodata_internalize(data);
1955 writecachedrepo(repo, 0, 0, cinfo->cookie);
1956 repodata_create_stubs(repo_last_repodata(repo));
1960 #if defined(ENABLE_DEBIAN)
1962 printf("debian repo '%s':", cinfo->alias);
1964 filename = solv_dupjoin("dists/", cinfo->name, "/Release");
1965 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
1967 printf(" no Release file, skipped\n");
1970 free((char *)filename);
1973 solv_free((char *)filename);
1974 if (cinfo->repo_gpgcheck)
1976 filename = solv_dupjoin("dists/", cinfo->name, "/Release.gpg");
1977 if (!downloadchecksig(cinfo, fp, filename, &sigpool))
1980 solv_free((char *)filename);
1983 solv_free((char *)filename);
1985 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
1986 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1988 printf(" cached\n");
1992 printf(" fetching\n");
1993 for (j = 0; j < cinfo->ncomponents; j++)
1995 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
1997 printf("[component %s not found]\n", cinfo->components[j]);
2000 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
2002 if (repo_add_debpackages(repo, fp, 0))
2004 printf("component %s: %s\n", cinfo->components[j], pool_errstr(pool));
2009 solv_free((char *)filechksum);
2010 solv_free((char *)filename);
2014 writecachedrepo(repo, 0, 0, cinfo->cookie);
2019 printf("unsupported repo '%s': skipped\n", cinfo->alias);
2030 yesno(const char *str)
2032 char inbuf[128], *ip;
2039 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2044 while (*ip == ' ' || *ip == '\t')
2051 if (*ip == 'y' || *ip == 'n')
2052 return *ip == 'y' ? 1 : 0;
2056 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2066 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2068 struct fcstate *fcstate = cbdata;
2076 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
2079 s = pool_id2solvable(pool, p);
2080 if (pool->installed && s->repo == pool->installed)
2082 if (!s->repo->rpmdbid)
2084 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2087 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
2089 for (i = 0; i < fcstate->newpkgscnt; i++)
2090 if (fcstate->checkq->elements[i] == p)
2092 if (i == fcstate->newpkgscnt)
2094 fp = fcstate->newpkgsfps[i];
2098 return rpm_byfp(fp, pool_solvable2str(pool, s), &fcstate->rpmdbstate);
2103 runrpm(const char *arg, const char *name, int dupfd3, const char *rootdir)
2108 if ((pid = fork()) == (pid_t)-1)
2117 if (dupfd3 != -1 && dupfd3 != 3)
2123 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2124 if (strcmp(arg, "-e") == 0)
2125 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2127 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2131 while (waitpid(pid, &status, 0) != pid)
2135 printf("rpm failed\n");
2142 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2145 rundpkg(const char *arg, const char *name, int dupfd3, const char *rootdir)
2150 if ((pid = fork()) == (pid_t)-1)
2159 if (dupfd3 != -1 && dupfd3 != 3)
2165 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2166 if (strcmp(arg, "--install") == 0)
2167 execlp("dpkg", "dpkg", "--install", "--root", rootdir, "--force", "all", name, (char *)0);
2169 execlp("dpkg", "dpkg", "--remove", "--root", rootdir, "--force", "all", name, (char *)0);
2173 while (waitpid(pid, &status, 0) != pid)
2177 printf("dpkg failed\n");
2185 nscallback(Pool *pool, void *data, Id name, Id evr)
2187 if (name == NAMESPACE_PRODUCTBUDDY)
2189 /* SUSE specific hack: each product has an associated rpm */
2190 Solvable *s = pool->solvables + evr;
2194 cap = pool_str2id(pool, pool_tmpjoin(pool, "product(", pool_id2str(pool, s->name) + 8, ")"), 0);
2197 cap = pool_rel2id(pool, cap, s->evr, REL_EQ, 0);
2200 FOR_PROVIDES(p, pp, cap)
2202 Solvable *ps = pool->solvables + p;
2203 if (ps->repo == s->repo && ps->arch == s->arch)
2204 if (!bestp || pool_evrcmp(pool, pool->solvables[bestp].evr, ps->evr, EVRCMP_COMPARE) < 0)
2212 #ifdef SOFTLOCKS_PATH
2215 addsoftlocks(Pool *pool, Queue *job)
2219 char *bp, *ep, buf[4096];
2221 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2223 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2225 while (*bp == ' ' || *bp == '\t')
2227 if (!*bp || *bp == '#')
2229 for (ep = bp; *ep; ep++)
2230 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2233 type = SOLVER_SOLVABLE_NAME;
2234 if (!strncmp(bp, "provides:", 9) && bp[9])
2236 type = SOLVER_SOLVABLE_PROVIDES;
2239 id = pool_str2id(pool, bp, 1);
2240 if (pool->installed)
2242 FOR_JOB_SELECT(p, pp, type, id)
2243 if (pool->solvables[p].repo == pool->installed)
2246 continue; /* ignore, as it is already installed */
2248 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2257 rewrite_repos(Pool *pool, Queue *addedfileprovides, Queue *addedfileprovides_inst)
2262 Queue fileprovidesq;
2264 struct repoinfo *cinfo;
2266 map_init(&providedids, pool->ss.nstrings);
2267 queue_init(&fileprovidesq);
2268 for (i = 0; i < addedfileprovides->count; i++)
2269 MAPSET(&providedids, addedfileprovides->elements[i]);
2272 /* make sure all repodatas but the first are extensions */
2273 if (repo->nrepodata < 2)
2275 data = repo_id2repodata(repo, 1);
2276 if (data->loadcallback)
2278 for (j = 2; j < repo->nrepodata; j++)
2280 Repodata *edata = repo_id2repodata(repo, j);
2281 if (!edata->loadcallback)
2284 if (j < repo->nrepodata)
2285 continue; /* found a non-externsion repodata, can't rewrite */
2286 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2288 if (repo == pool->installed && addedfileprovides_inst)
2290 for (j = 0; j < addedfileprovides->count; j++)
2291 MAPCLR(&providedids, addedfileprovides->elements[j]);
2292 for (j = 0; j < addedfileprovides_inst->count; j++)
2293 MAPSET(&providedids, addedfileprovides_inst->elements[j]);
2296 for (j = 0; j < fileprovidesq.count; j++)
2297 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2299 if (repo == pool->installed && addedfileprovides_inst)
2301 for (j = 0; j < addedfileprovides_inst->count; j++)
2302 MAPCLR(&providedids, addedfileprovides_inst->elements[j]);
2303 for (j = 0; j < addedfileprovides->count; j++)
2304 MAPSET(&providedids, addedfileprovides->elements[j]);
2305 if (n == addedfileprovides_inst->count)
2306 continue; /* nothing new added */
2308 else if (n == addedfileprovides->count)
2309 continue; /* nothing new added */
2311 repodata_set_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, repo == pool->installed && addedfileprovides_inst ? addedfileprovides_inst : addedfileprovides);
2312 repodata_internalize(data);
2313 cinfo = repo->appdata;
2314 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2316 queue_free(&fileprovidesq);
2317 map_free(&providedids);
2321 select_patches(Pool *pool, Queue *job)
2325 Map installedmap, noobsmap;
2328 map_init(&noobsmap, 0);
2329 map_init(&installedmap, pool->nsolvables);
2330 solver_calculate_noobsmap(pool, job, &noobsmap);
2331 if (pool->installed)
2332 FOR_REPO_SOLVABLES(pool->installed, p, s)
2333 MAPSET(&installedmap, p);
2335 /* install all patches */
2336 for (p = 1; p < pool->nsolvables; p++)
2342 s = pool->solvables + p;
2343 if (strncmp(pool_id2str(pool, s->name), "patch:", 6) != 0)
2345 FOR_PROVIDES(p2, pp, s->name)
2347 Solvable *s2 = pool->solvables + p2;
2348 if (s2->name != s->name)
2350 r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2351 if (r < 0 || (r == 0 && p > p2))
2356 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2357 if (type && !strcmp(type, "optional"))
2359 r = solvable_trivial_installable_map(s, &installedmap, 0, &noobsmap);
2362 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2369 queue_push2(job, SOLVER_SOLVABLE, p);
2371 map_free(&installedmap);
2372 map_free(&noobsmap);
2376 #define MODE_INSTALL 1
2377 #define MODE_ERASE 2
2378 #define MODE_UPDATE 3
2379 #define MODE_DISTUPGRADE 4
2380 #define MODE_VERIFY 5
2381 #define MODE_PATCH 6
2383 #define MODE_REPOLIST 8
2384 #define MODE_SEARCH 9
2389 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2390 fprintf(stderr, "\n");
2391 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2392 fprintf(stderr, " versions from the repositories\n");
2393 fprintf(stderr, " erase: erase installed packages\n");
2394 fprintf(stderr, " info: display package information\n");
2395 fprintf(stderr, " install: install packages\n");
2396 fprintf(stderr, " list: list packages\n");
2397 fprintf(stderr, " repos: list enabled repositories\n");
2398 fprintf(stderr, " search: search name/summary/description\n");
2399 fprintf(stderr, " update: update installed packages\n");
2400 fprintf(stderr, " verify: check dependencies of installed packages\n");
2401 fprintf(stderr, "\n");
2406 main(int argc, char **argv)
2409 Repo *commandlinerepo = 0;
2410 Id *commandlinepkgs = 0;
2412 struct repoinfo *repoinfos;
2414 int mainmode = 0, mode = 0;
2419 char inbuf[128], *ip;
2421 Queue addedfileprovides;
2422 Queue addedfileprovides_inst;
2431 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2433 mainmode = MODE_INSTALL;
2434 mode = SOLVER_INSTALL;
2436 else if (!strcmp(argv[0], "patch"))
2438 mainmode = MODE_PATCH;
2439 mode = SOLVER_INSTALL;
2441 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2443 mainmode = MODE_ERASE;
2444 mode = SOLVER_ERASE;
2446 else if (!strcmp(argv[0], "list"))
2448 mainmode = MODE_LIST;
2451 else if (!strcmp(argv[0], "info"))
2453 mainmode = MODE_INFO;
2456 else if (!strcmp(argv[0], "search"))
2458 mainmode = MODE_SEARCH;
2461 else if (!strcmp(argv[0], "verify"))
2463 mainmode = MODE_VERIFY;
2464 mode = SOLVER_VERIFY;
2466 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2468 mainmode = MODE_UPDATE;
2469 mode = SOLVER_UPDATE;
2471 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2473 mainmode = MODE_DISTUPGRADE;
2474 mode = SOLVER_DISTUPGRADE;
2476 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2478 mainmode = MODE_REPOLIST;
2486 if (argc > 2 && !strcmp(argv[1], "--root"))
2493 else if (argc > 1 && !strcmp(argv[1], "--clean"))
2503 pool = pool_create();
2504 pool_set_rootdir(pool, rootdir);
2508 const char *langs[] = {"de_DE", "de", "en"};
2509 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2513 pool_setloadcallback(pool, load_stub, 0);
2514 pool->nscallback = nscallback;
2515 // pool_setdebuglevel(pool, 2);
2517 repoinfos = read_repoinfos(pool, &nrepoinfos);
2519 if (mainmode == MODE_REPOLIST)
2522 for (i = 0; i < nrepoinfos; i++)
2524 struct repoinfo *cinfo = repoinfos + i;
2525 if (!cinfo->enabled)
2527 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2532 read_repos(pool, repoinfos, nrepoinfos);
2534 queue_init(&repofilter);
2535 while (argc > 2 && !strcmp(argv[1], "-r"))
2537 const char *rname = argv[2], *rp;
2539 for (rp = rname; *rp; rp++)
2540 if (*rp <= '0' || *rp >= '9')
2544 /* repo specified by number */
2545 int rnum = atoi(rname);
2546 for (i = 0; i < nrepoinfos; i++)
2548 struct repoinfo *cinfo = repoinfos + i;
2549 if (!cinfo->enabled)
2552 repoid = cinfo->repo->repoid;
2557 /* repo specified by alias */
2561 if (!strcasecmp(rname, repo->name))
2562 repoid = repo->repoid;
2567 fprintf(stderr, "%s: no such repo\n", rname);
2570 /* SETVENDOR is actually wrong but useful */
2571 queue_push2(&repofilter, SOLVER_SOLVABLE_REPO | SOLVER_SETREPO | SOLVER_SETVENDOR, repoid);
2575 if (mainmode == MODE_SEARCH)
2581 map_init(&m, pool->nsolvables);
2582 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2583 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2584 dataiterator_set_search(&di, 0, 0);
2585 while (dataiterator_step(&di))
2586 MAPSET(&m, di.solvid);
2587 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2588 dataiterator_set_search(&di, 0, 0);
2589 while (dataiterator_step(&di))
2590 MAPSET(&m, di.solvid);
2591 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2592 dataiterator_set_search(&di, 0, 0);
2593 while (dataiterator_step(&di))
2594 MAPSET(&m, di.solvid);
2595 dataiterator_free(&di);
2597 for (p = 1; p < pool->nsolvables; p++)
2599 Solvable *s = pool_id2solvable(pool, p);
2602 printf(" - %s: %s\n", pool_solvable2str(pool, s), solvable_lookup_str(s, SOLVABLE_SUMMARY));
2609 if (mainmode == MODE_LIST || mainmode == MODE_INSTALL)
2611 for (i = 1; i < argc; i++)
2614 l = strlen(argv[i]);
2615 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2616 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2619 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2620 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2623 if (access(argv[i], R_OK))
2628 if (!commandlinepkgs)
2629 commandlinepkgs = solv_calloc(argc, sizeof(Id));
2630 if (!commandlinerepo)
2631 commandlinerepo = repo_create(pool, "@commandline");
2633 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2634 p = repo_add_rpm(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2636 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2637 p = repo_add_deb(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2641 fprintf(stderr, "could not add '%s'\n", argv[i]);
2644 commandlinepkgs[i] = p;
2646 if (commandlinerepo)
2647 repo_internalize(commandlinerepo);
2650 // FOR_REPOS(i, repo)
2651 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2652 queue_init(&addedfileprovides);
2653 queue_init(&addedfileprovides_inst);
2654 pool_addfileprovides_queue(pool, &addedfileprovides, &addedfileprovides_inst);
2655 if (addedfileprovides.count || addedfileprovides_inst.count)
2656 rewrite_repos(pool, &addedfileprovides, &addedfileprovides_inst);
2657 queue_free(&addedfileprovides);
2658 queue_free(&addedfileprovides_inst);
2659 pool_createwhatprovides(pool);
2662 for (i = 1; i < argc; i++)
2665 int j, flags, rflags;
2667 if (commandlinepkgs && commandlinepkgs[i])
2669 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2673 flags = SELECTION_NAME|SELECTION_PROVIDES|SELECTION_GLOB;
2674 if (mode == MODE_LIST)
2675 flags |= SELECTION_WITH_SOURCE;
2676 if (argv[i][0] == '/')
2677 flags |= SELECTION_FILELIST | (mode == MODE_ERASE ? SELECTION_INSTALLED_ONLY : 0);
2678 rflags = selection_make(pool, &job2, argv[i], flags);
2679 if (repofilter.count)
2680 selection_limit(pool, &job2, &repofilter);
2683 flags |= SELECTION_NOCASE;
2684 rflags = selection_make(pool, &job2, argv[i], flags);
2685 if (repofilter.count)
2686 selection_limit(pool, &job2, &repofilter);
2688 printf("[ignoring case for '%s']\n", argv[i]);
2692 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2695 if (rflags & SELECTION_FILELIST)
2696 printf("[using file list match for '%s']\n", argv[i]);
2697 if (rflags & SELECTION_PROVIDES)
2698 printf("[using capability match for '%s']\n", argv[i]);
2699 for (j = 0; j < job2.count; j++)
2700 queue_push(&job, job2.elements[j]);
2704 if (!job.count && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE || mainmode == MODE_VERIFY || repofilter.count))
2706 queue_push2(&job, SOLVER_SOLVABLE_ALL, 0);
2707 if (repofilter.count)
2708 selection_limit(pool, &job, &repofilter);
2710 queue_free(&repofilter);
2712 if (!job.count && MODE_PATCH)
2714 printf("no package matched\n");
2718 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
2720 /* list mode, no solver needed */
2723 for (i = 0; i < job.count; i += 2)
2727 pool_job2solvables(pool, &q, job.elements[i], job.elements[i + 1]);
2728 for (j = 0; j < q.count; j++)
2730 Solvable *s = pool_id2solvable(pool, q.elements[j]);
2731 if (mainmode == MODE_INFO)
2734 printf("Name: %s\n", pool_solvable2str(pool, s));
2735 printf("Repo: %s\n", s->repo->name);
2736 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
2737 str = solvable_lookup_str(s, SOLVABLE_URL);
2739 printf("Url: %s\n", str);
2740 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
2742 printf("License: %s\n", str);
2743 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
2749 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
2751 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
2753 printf(" - %s [%s]\n", pool_solvable2str(pool, s), s->repo->name);
2755 printf(" %s\n", sum);
2762 free_repoinfos(repoinfos, nrepoinfos);
2763 solv_free(commandlinepkgs);
2765 yum_substitute(pool, 0);
2770 if (mainmode == MODE_PATCH)
2771 select_patches(pool, &job);
2774 for (i = 0; i < job.count; i += 2)
2776 job.elements[i] |= mode;
2777 if (mode == SOLVER_UPDATE && pool_isemptyupdatejob(pool, job.elements[i], job.elements[i + 1]))
2778 job.elements[i] ^= SOLVER_UPDATE ^ SOLVER_INSTALL;
2780 job.elements[i] |= SOLVER_CLEANDEPS;
2783 // multiversion test
2784 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae", 1));
2785 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-base", 1));
2786 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-extra", 1));
2788 #ifdef SOFTLOCKS_PATH
2789 addsoftlocks(pool, &job);
2792 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2797 Id problem, solution;
2800 solv = solver_create(pool);
2801 solver_set_flag(solv, SOLVER_FLAG_SPLITPROVIDES, 1);
2802 if (mainmode == MODE_ERASE)
2803 solver_set_flag(solv, SOLVER_FLAG_ALLOW_UNINSTALL, 1); /* don't nag */
2805 if (!solver_solve(solv, &job))
2807 pcnt = solver_problem_count(solv);
2808 printf("Found %d problems:\n", pcnt);
2809 for (problem = 1; problem <= pcnt; problem++)
2812 printf("Problem %d:\n", problem);
2813 solver_printprobleminfo(solv, problem);
2815 scnt = solver_solution_count(solv, problem);
2816 for (solution = 1; solution <= scnt; solution++)
2818 printf("Solution %d:\n", solution);
2819 solver_printsolution(solv, problem, solution);
2824 printf("Please choose a solution: ");
2827 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2832 while (*ip == ' ' || *ip == '\t')
2834 if (*ip >= '0' && *ip <= '9')
2837 if (take >= 1 && take <= scnt)
2853 solver_take_solution(solv, problem, take, &job);
2859 trans = solver_create_transaction(solv);
2860 if (!trans->steps.count)
2862 printf("Nothing to do.\n");
2863 transaction_free(trans);
2867 free_repoinfos(repoinfos, nrepoinfos);
2868 solv_free(commandlinepkgs);
2870 yum_substitute(pool, 0);
2875 printf("Transaction summary:\n\n");
2876 transaction_print(trans);
2885 duc[1].path = "/usr/share/man";
2886 duc[2].path = "/sbin";
2887 duc[3].path = "/etc";
2888 transaction_calc_duchanges(trans, duc, 4);
2889 for (i = 0; i < 4; i++)
2890 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
2893 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
2896 if (!yesno("OK to continue (y/n)? "))
2899 transaction_free(trans);
2903 free_repoinfos(repoinfos, nrepoinfos);
2904 solv_free(commandlinepkgs);
2906 yum_substitute(pool, 0);
2911 queue_init(&checkq);
2912 newpkgs = transaction_installedresult(trans, &checkq);
2917 int downloadsize = 0;
2918 for (i = 0; i < newpkgs; i++)
2922 p = checkq.elements[i];
2923 s = pool_id2solvable(pool, p);
2924 downloadsize += solvable_lookup_sizek(s, SOLVABLE_DOWNLOADSIZE, 0);
2926 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
2927 newpkgsfps = solv_calloc(newpkgs, sizeof(*newpkgsfps));
2928 for (i = 0; i < newpkgs; i++)
2930 unsigned int medianr;
2933 struct repoinfo *cinfo;
2934 const unsigned char *chksum;
2938 p = checkq.elements[i];
2939 s = pool_id2solvable(pool, p);
2940 if (s->repo == commandlinerepo)
2942 loc = solvable_lookup_location(s, &medianr);
2943 if (!(newpkgsfps[i] = fopen(loc, "r")))
2951 cinfo = s->repo->appdata;
2954 printf("%s: no repository information\n", s->repo->name);
2957 loc = solvable_lookup_location(s, &medianr);
2961 if (pool->installed && pool->installed->nsolvables)
2963 /* try a delta first */
2964 char *matchname = strdup(pool_id2str(pool, s->name));
2965 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
2966 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
2967 while (dataiterator_step(&di))
2971 dataiterator_setpos_parent(&di);
2972 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
2973 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
2975 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
2976 FOR_PROVIDES(op, pp, s->name)
2978 Solvable *os = pool->solvables + op;
2979 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
2982 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
2984 /* base is installed, run sequence check */
2985 const char *seqname;
2990 const char *archstr;
2995 archstr = pool_id2str(pool, s->arch);
2996 if (strlen(archstr) > 10 || strchr(archstr, '\'') != 0)
2999 seqname = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME);
3000 seqevr = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR);
3001 seqnum = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM);
3002 seq = pool_tmpjoin(pool, seqname, "-", seqevr);
3003 seq = pool_tmpappend(pool, seq, "-", seqnum);
3004 if (strchr(seq, '\'') != 0)
3007 sprintf(cmd, "/usr/bin/applydeltarpm -a '%s' -c -s '", archstr);
3009 sprintf(cmd, "/usr/bin/applydeltarpm -c -s '");
3011 if (system(pool_tmpjoin(pool, cmd, seq, "'")) != 0)
3012 continue; /* didn't match */
3013 /* looks good, download delta */
3015 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
3017 continue; /* no way! */
3018 dloc = pool_lookup_deltalocation(pool, SOLVID_POS);
3021 if (cinfo->type == TYPE_SUSETAGS)
3023 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3024 dloc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", dloc);
3026 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
3028 /* got it, now reconstruct */
3029 newfd = opentmpfile();
3031 sprintf(cmd, "applydeltarpm -a '%s' /dev/fd/%d /dev/fd/%d", archstr, fileno(fp), newfd);
3033 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
3035 fcntl(fileno(fp), F_SETFD, 0);
3042 lseek(newfd, 0, SEEK_SET);
3044 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3045 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
3051 newpkgsfps[i] = fdopen(newfd, "r");
3056 dataiterator_free(&di);
3057 solv_free(matchname);
3064 continue; /* delta worked! */
3066 if (cinfo->type == TYPE_SUSETAGS)
3068 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3069 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3072 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3073 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3075 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3084 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3088 struct fcstate fcstate;
3090 printf("Searching for file conflicts\n");
3091 queue_init(&conflicts);
3092 fcstate.rpmdbstate = 0;
3093 fcstate.newpkgscnt = newpkgs;
3094 fcstate.checkq = &checkq;
3095 fcstate.newpkgsfps = newpkgsfps;
3096 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fileconflict_cb, &fcstate);
3097 if (conflicts.count)
3100 for (i = 0; i < conflicts.count; i += 5)
3101 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]));
3103 if (yesno("Re-run solver (y/n/q)? "))
3105 for (i = 0; i < newpkgs; i++)
3107 fclose(newpkgsfps[i]);
3108 newpkgsfps = solv_free(newpkgsfps);
3110 pool_add_fileconflicts_deps(pool, &conflicts);
3111 pool_createwhatprovides(pool); /* Hmm... */
3115 queue_free(&conflicts);
3119 printf("Committing transaction:\n\n");
3120 transaction_order(trans, 0);
3121 for (i = 0; i < trans->steps.count; i++)
3123 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3124 const char *evr, *evrp, *nvra;
3130 p = trans->steps.elements[i];
3131 s = pool_id2solvable(pool, p);
3132 Id type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3135 case SOLVER_TRANSACTION_ERASE:
3136 printf("erase %s\n", pool_solvid2str(pool, p));
3137 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3138 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3140 /* strip epoch from evr */
3141 evr = evrp = pool_id2str(pool, s->evr);
3142 while (*evrp >= '0' && *evrp <= '9')
3144 if (evrp > evr && evrp[0] == ':' && evrp[1])
3146 nvra = pool_tmpjoin(pool, pool_id2str(pool, s->name), "-", evr);
3147 nvra = pool_tmpappend(pool, nvra, ".", pool_id2str(pool, s->arch));
3148 runrpm("-e", nvra, -1, rootdir); /* too bad that --querybynumber doesn't work */
3150 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3151 rundpkg("--remove", pool_id2str(pool, s->name), 0, rootdir);
3154 case SOLVER_TRANSACTION_INSTALL:
3155 case SOLVER_TRANSACTION_MULTIINSTALL:
3156 printf("install %s\n", pool_solvid2str(pool, p));
3157 for (j = 0; j < newpkgs; j++)
3158 if (checkq.elements[j] == p)
3160 fp = j < newpkgs ? newpkgsfps[j] : 0;
3164 lseek(fileno(fp), 0, SEEK_SET);
3165 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3166 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp), rootdir);
3168 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3169 rundpkg("--install", "/dev/fd/3", fileno(fp), rootdir);
3179 for (i = 0; i < newpkgs; i++)
3181 fclose(newpkgsfps[i]);
3182 solv_free(newpkgsfps);
3183 queue_free(&checkq);
3184 transaction_free(trans);
3188 free_repoinfos(repoinfos, nrepoinfos);
3189 solv_free(commandlinepkgs);
3191 yum_substitute(pool, 0);