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>
43 #include <sys/socket.h>
55 #include "solverdebug.h"
57 #include "repo_solv.h"
59 #include "repo_write.h"
61 #include "repo_rpmdb.h"
65 #include "repo_products.h"
66 #include "repo_rpmmd.h"
67 #include "repo_susetags.h"
68 #include "repo_repomdxml.h"
69 #include "repo_updateinfoxml.h"
70 #include "repo_deltainfoxml.h"
71 #include "repo_content.h"
72 #include "pool_fileconflicts.h"
76 # define REPOINFO_PATH "/etc/yum.repos.d"
78 # define REPOINFO_PATH "/etc/zypp/repos.d"
79 # define PRODUCTS_PATH "/etc/products.d"
80 # define SOFTLOCKS_PATH "/var/lib/zypp/SoftLocks"
83 #define SOLVCACHE_PATH "/var/cache/solv"
85 #define METADATA_EXPIRE (60 * 90)
107 unsigned char cookie[32];
108 unsigned char extcookie[32];
113 yum_substitute(Pool *pool, char *line)
116 static char *releaseevr;
117 static char *basearch;
121 sat_free(releaseevr);
128 while ((p2 = strchr(p, '$')) != 0)
130 if (!strncmp(p2, "$releasever", 11))
137 rpm_installedrpmdbids(0, "Providename", "redhat-release", &q);
140 void *handle, *state = 0;
142 handle = rpm_byrpmdbid(q.elements[0], 0, &state);
143 releaseevr = rpm_query(handle, SOLVABLE_EVR);
144 rpm_byrpmdbid(0, 0, &state);
145 if ((p = strchr(releaseevr, '-')) != 0)
150 releaseevr = strdup("?");
153 p = pool_tmpjoin(pool, line, releaseevr, p2 + 11);
154 p2 = p + (p2 - line);
156 p = p2 + strlen(releaseevr);
159 if (!strncmp(p2, "$basearch", 9))
169 basearch = strdup(un.machine);
170 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
174 p = pool_tmpjoin(pool, line, basearch, p2 + 9);
175 p2 = p + (p2 - line);
177 p = p2 + strlen(basearch);
186 #define TYPE_UNKNOWN 0
187 #define TYPE_SUSETAGS 1
189 #define TYPE_PLAINDIR 3
190 #define TYPE_DEBIAN 4
193 read_repoinfos_sort(const void *ap, const void *bp)
195 const struct repoinfo *a = ap;
196 const struct repoinfo *b = bp;
197 return strcmp(a->alias, b->alias);
203 read_repoinfos(Pool *pool, const char *reposdir, int *nrepoinfosp)
206 char buf2[4096], *kp, *vp, *kpe;
211 struct repoinfo *repoinfos = 0, *cinfo;
214 rdlen = strlen(reposdir);
215 dir = opendir(reposdir);
221 while ((ent = readdir(dir)) != 0)
223 l = strlen(ent->d_name);
224 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
226 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
227 if ((fp = fopen(buf, "r")) == 0)
233 while(fgets(buf2, sizeof(buf2), fp))
238 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
241 while (*kp == ' ' || *kp == '\t')
243 if (!*kp || *kp == '#')
247 kp = yum_substitute(pool, kp);
251 vp = strrchr(kp, ']');
255 repoinfos = sat_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
256 cinfo = repoinfos + nrepoinfos++;
257 memset(cinfo, 0, sizeof(*cinfo));
258 cinfo->alias = strdup(kp + 1);
259 cinfo->type = TYPE_RPMMD;
260 cinfo->autorefresh = 1;
261 cinfo->priority = 99;
263 cinfo->repo_gpgcheck = 1;
265 cinfo->metadata_expire = METADATA_EXPIRE;
270 vp = strchr(kp, '=');
273 for (kpe = vp - 1; kpe >= kp; kpe--)
274 if (*kpe != ' ' && *kpe != '\t')
279 while (*vp == ' ' || *vp == '\t')
282 if (!strcmp(kp, "name"))
283 cinfo->name = strdup(vp);
284 else if (!strcmp(kp, "enabled"))
285 cinfo->enabled = *vp == '0' ? 0 : 1;
286 else if (!strcmp(kp, "autorefresh"))
287 cinfo->autorefresh = *vp == '0' ? 0 : 1;
288 else if (!strcmp(kp, "gpgcheck"))
289 cinfo->pkgs_gpgcheck = *vp == '0' ? 0 : 1;
290 else if (!strcmp(kp, "repo_gpgcheck"))
291 cinfo->repo_gpgcheck = *vp == '0' ? 0 : 1;
292 else if (!strcmp(kp, "baseurl"))
293 cinfo->baseurl = strdup(vp);
294 else if (!strcmp(kp, "mirrorlist"))
296 if (strstr(vp, "metalink"))
297 cinfo->metalink = strdup(vp);
299 cinfo->mirrorlist = strdup(vp);
301 else if (!strcmp(kp, "path"))
303 if (vp && strcmp(vp, "/") != 0)
304 cinfo->path = strdup(vp);
306 else if (!strcmp(kp, "type"))
308 if (!strcmp(vp, "yast2"))
309 cinfo->type = TYPE_SUSETAGS;
310 else if (!strcmp(vp, "rpm-md"))
311 cinfo->type = TYPE_RPMMD;
312 else if (!strcmp(vp, "plaindir"))
313 cinfo->type = TYPE_PLAINDIR;
315 cinfo->type = TYPE_UNKNOWN;
317 else if (!strcmp(kp, "priority"))
318 cinfo->priority = atoi(vp);
319 else if (!strcmp(kp, "keeppackages"))
320 cinfo->keeppackages = *vp == '0' ? 0 : 1;
326 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
327 *nrepoinfosp = nrepoinfos;
334 read_repoinfos(Pool *pool, const char *reposdir, int *nrepoinfosp)
339 char *kp, *url, *distro;
340 struct repoinfo *repoinfos = 0, *cinfo;
343 if (!(fp = fopen("/etc/apt/sources.list", "r")))
345 while(fgets(buf2, sizeof(buf2), fp))
350 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
353 while (*kp == ' ' || *kp == '\t')
355 if (!*kp || *kp == '#')
357 if (strncmp(kp, "deb", 3) != 0)
360 if (*kp != ' ' && *kp != '\t')
362 while (*kp == ' ' || *kp == '\t')
367 while (*kp && *kp != ' ' && *kp != '\t')
371 while (*kp == ' ' || *kp == '\t')
376 while (*kp && *kp != ' ' && *kp != '\t')
380 while (*kp == ' ' || *kp == '\t')
384 repoinfos = sat_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
385 cinfo = repoinfos + nrepoinfos++;
386 cinfo->baseurl = strdup(url);
387 cinfo->alias = sat_dupjoin(url, "/", distro);
388 cinfo->name = strdup(distro);
389 cinfo->type = TYPE_DEBIAN;
391 cinfo->repo_gpgcheck = 1;
395 while (*kp == ' ' || *kp == '\t')
400 while (*kp && *kp != ' ' && *kp != '\t')
404 cinfo->components = sat_extend(cinfo->components, cinfo->ncomponents, 1, sizeof(*cinfo->components), 15);
405 cinfo->components[cinfo->ncomponents++] = strdup(compo);
409 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
410 *nrepoinfosp = nrepoinfos;
417 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
420 for (i = 0; i < nrepoinfos; i++)
422 struct repoinfo *cinfo = repoinfos + i;
423 sat_free(cinfo->name);
424 sat_free(cinfo->alias);
425 sat_free(cinfo->path);
426 sat_free(cinfo->metalink);
427 sat_free(cinfo->mirrorlist);
428 sat_free(cinfo->baseurl);
429 for (j = 0; j < cinfo->ncomponents; j++)
430 sat_free(cinfo->components[j]);
431 sat_free(cinfo->components);
442 strcpy(tmpl, "/var/tmp/solvXXXXXX");
454 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
461 h = sat_chksum_create(chksumtype);
464 printf("%s: unknown checksum type\n", file);
467 while ((l = read(fd, buf, sizeof(buf))) > 0)
468 sat_chksum_add(h, buf, l);
469 lseek(fd, 0, SEEK_SET);
471 sum = sat_chksum_get(h, &l);
472 if (memcmp(sum, chksum, l))
474 printf("%s: checksum mismatch\n", file);
475 sat_chksum_free(h, 0);
478 sat_chksum_free(h, 0);
483 findfastest(char **urls, int nurls)
490 struct addrinfo hints, *result;;
492 fds = sat_calloc(nurls, sizeof(*fds));
493 socks = sat_calloc(nurls, sizeof(*socks));
494 for (i = 0; i < nurls; i++)
497 p = strchr(urls[i], '/');
510 if ((p2 = strchr(p, '@')) != 0)
513 if (!strncmp("https:", urls[i], 6))
515 else if (!strncmp("ftp:", urls[i], 4))
517 if ((p2 = strrchr(p, ':')) != 0)
526 sprintf(portstr, "%d", port);
527 memset(&hints, 0, sizeof(struct addrinfo));
528 hints.ai_family = AF_UNSPEC;
529 hints.ai_socktype = SOCK_STREAM;
530 hints.ai_flags = AI_NUMERICSERV;
532 if (!getaddrinfo(p, portstr, &hints, &result))
534 socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
537 fcntl(socks[i], F_SETFL, O_NONBLOCK);
538 if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1)
540 if (errno != EINPROGRESS)
547 freeaddrinfo(result);
554 for (i = j = 0; i < nurls; i++)
558 fds[j].fd = socks[i];
559 fds[j].events = POLLOUT;
567 if (poll(fds, j, 10000) <= 0)
569 i = -1; /* something is wrong */
572 for (i = 0; i < j; i++)
573 if ((fds[i].revents & POLLOUT) != 0)
576 socklen_t soel = sizeof(int);
577 if (getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, &soe, &soel) == -1 || soe != 0)
579 /* connect failed, kill socket */
580 for (j = 0; j < nurls; j++)
581 if (socks[j] == fds[i].fd)
594 i = -1; /* something is wrong, no bit was set */
597 /* now i contains the fastest fd index */
600 for (j = 0; j < nurls; j++)
601 if (socks[j] == fds[i].fd)
605 char *url0 = urls[0];
610 for (i = j = 0; i < nurls; i++)
618 findmetalinkurl(FILE *fp, unsigned char *chksump, Id *chksumtypep)
620 char buf[4096], *bp, *ep;
627 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
629 while (*bp == ' ' || *bp == '\t')
631 if (chksumtypep && !*chksumtypep && !strncmp(bp, "<hash type=\"sha256\">", 20))
636 memset(chksump, 0, 32);
637 for (i = 0; i < 64; i++)
640 if (c >= '0' && c <= '9')
641 chksump[i / 2] = chksump[i / 2] * 16 + (c - '0');
642 else if (c >= 'a' && c <= 'f')
643 chksump[i / 2] = chksump[i / 2] * 16 + (c - ('a' - 10));
644 else if (c >= 'A' && c <= 'F')
645 chksump[i / 2] = chksump[i / 2] * 16 + (c - ('A' - 10));
650 *chksumtypep = REPOKEY_TYPE_SHA256;
653 if (strncmp(bp, "<url", 4))
655 bp = strchr(bp, '>');
659 ep = strstr(bp, "repodata/repomd.xml</url>");
663 if (strncmp(bp, "http", 4))
665 urls = sat_extend(urls, nurls, 1, sizeof(*urls), 15);
666 urls[nurls++] = strdup(bp);
671 findfastest(urls, nurls > 5 ? 5 : nurls);
674 for (i = 0; i < nurls; i++)
677 ep = strchr(bp, '/');
678 if ((ep = strchr(ep + 2, '/')) != 0)
681 printf("[using mirror %s]\n", bp);
690 findmirrorlisturl(FILE *fp)
692 char buf[4096], *bp, *ep;
697 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
699 while (*bp == ' ' || *bp == '\t')
701 if (!*bp || *bp == '#')
704 while (l > 0 && (bp[l - 1] == ' ' || bp[l - 1] == '\t' || bp[l - 1] == '\n'))
706 urls = sat_extend(urls, nurls, 1, sizeof(*urls), 15);
707 urls[nurls++] = strdup(bp);
712 findfastest(urls, nurls > 5 ? 5 : nurls);
715 for (i = 0; i < nurls; i++)
718 ep = strchr(bp, '/');
719 if ((ep = strchr(ep + 2, '/')) != 0)
722 printf("[using mirror %s]\n", bp);
731 cookie_gzread(void *cookie, char *buf, size_t nbytes)
733 return gzread((gzFile *)cookie, buf, nbytes);
737 cookie_gzclose(void *cookie)
739 return gzclose((gzFile *)cookie);
743 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int *badchecksump)
749 const char *baseurl = cinfo->baseurl;
753 if (!cinfo->metalink && !cinfo->mirrorlist)
755 if (file != cinfo->metalink && file != cinfo->mirrorlist)
757 FILE *fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
758 unsigned char mlchksum[32];
763 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
765 cinfo->baseurl = findmirrorlisturl(fp);
770 if (strchr(cinfo->baseurl, '$'))
772 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
773 free(cinfo->baseurl);
774 cinfo->baseurl = strdup(b);
777 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
779 chksumtype = mlchksumtype;
782 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, badchecksump);
784 snprintf(url, sizeof(url), "%s", file);
789 if (l && baseurl[l - 1] == '/')
790 snprintf(url, sizeof(url), "%s%s", baseurl, file);
792 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
795 // printf("url: %s\n", url);
796 if ((pid = fork()) == (pid_t)-1)
808 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
813 while (waitpid(pid, &status, 0) != pid)
815 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
821 lseek(fd, 0, SEEK_SET);
824 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
830 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
840 cookie_io_functions_t cio;
843 sprintf(tmpl, "/dev/fd/%d", fd);
844 gzf = gzopen(tmpl, "r");
848 fprintf(stderr, "could not open /dev/fd/%d, /proc not mounted?\n", fd);
851 memset(&cio, 0, sizeof(cio));
852 cio.read = cookie_gzread;
853 cio.close = cookie_gzclose;
854 return fopencookie(gzf, "r", cio);
856 fcntl(fd, F_SETFD, FD_CLOEXEC);
857 return fdopen(fd, "r");
863 cleanupgpg(char *gpgdir)
866 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
868 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
870 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
872 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
874 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
880 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
889 off_t posfp, possigfp;
892 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
895 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
896 if (!(kfp = fopen(keysfile, "w")) )
902 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
906 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
907 if (!pubkey || !*pubkey)
909 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
911 if (fputc('\n', kfp) == EOF) /* Just in case... */
915 if (fclose(kfp) || !nkeys)
920 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
923 fprintf(stderr, "key import error\n");
928 posfp = lseek(fileno(fp), 0, SEEK_CUR);
929 lseek(fileno(fp), 0, SEEK_SET);
930 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
931 lseek(fileno(sigfp), 0, SEEK_SET);
932 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
933 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
934 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
936 lseek(fileno(sigfp), possigfp, SEEK_SET);
937 lseek(fileno(fp), posfp, SEEK_SET);
938 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
939 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
941 return r == 0 ? 1 : 0;
947 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
952 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));
953 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
954 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
956 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
957 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
958 return r == 0 ? 1 : 0;
963 #define CHKSUM_IDENT "1.1"
966 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
969 void *h = sat_chksum_create(chktype);
972 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
973 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
974 sat_chksum_add(h, buf, l);
976 sat_chksum_free(h, out);
980 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *out)
982 void *h = sat_chksum_create(chktype);
983 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
984 sat_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
985 sat_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
986 sat_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
987 sat_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
988 sat_chksum_free(h, out);
1000 pool_setarch(pool, un.machine);
1003 char *calccachepath(Repo *repo, const char *repoext)
1005 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
1008 p = pool_tmpjoin(repo->pool, p, "_", repoext);
1009 p = pool_tmpjoin(repo->pool, p, ".solvx", 0);
1012 p = pool_tmpjoin(repo->pool, p, ".solv", 0);
1013 q = p + strlen(SOLVCACHE_PATH) + 1;
1023 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1026 unsigned char mycookie[32];
1027 unsigned char myextcookie[32];
1028 struct repoinfo *cinfo;
1031 cinfo = repo->appdata;
1032 if (!(fp = fopen(calccachepath(repo, repoext), "r")))
1034 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1039 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1044 if (cinfo && !repoext)
1046 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1057 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1058 if (strcmp(repoext, "DL") != 0)
1059 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1062 if (repo_add_solv_flags(repo, fp, flags))
1067 if (cinfo && !repoext)
1069 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1070 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1073 futimes(fileno(fp), 0); /* try to set modification time */
1079 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1084 struct repoinfo *cinfo;
1087 cinfo = repo->appdata;
1088 mkdir(SOLVCACHE_PATH, 0755);
1089 tmpl = sat_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
1097 if (!(fp = fdopen(fd, "w")))
1106 for (i = repo->start; i < repo->end; i++)
1107 if (repo->pool->solvables[i].repo != repo)
1113 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
1115 repodata_write(info, fp, repo_write_stdkeyfilter, 0);
1118 int oldnrepodata = repo->nrepodata;
1119 repo->nrepodata = 1; /* XXX: do this right */
1120 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
1121 repo->nrepodata = oldnrepodata;
1125 if (!repoext && cinfo)
1127 if (!cinfo->extcookie[0])
1129 /* create the ext cookie and append it */
1130 /* we just need some unique ID */
1132 if (!fstat(fileno(fp), &stb))
1136 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cinfo->extcookie);
1137 for (i = 0; i < 32; i++)
1138 cinfo->extcookie[i] ^= cookie[i];
1140 if (cinfo->extcookie[0] == 0)
1141 cinfo->extcookie[0] = 1;
1143 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1151 /* append our cookie describing the metadata state */
1152 if (fwrite(cookie, 32, 1, fp) != 1)
1167 /* switch to just saved repo to activate paging and save memory */
1168 FILE *fp = fopen(tmpl, "r");
1174 repo_empty(repo, 1);
1175 if (repo_add_solv_flags(repo, fp, SOLV_ADD_NO_STUBS))
1177 /* oops, no way to recover from here */
1178 fprintf(stderr, "internal error\n");
1184 /* make sure repodata contains complete repo */
1185 /* (this is how repodata_write saves it) */
1186 repodata_extend_block(info, repo->start, repo->end - repo->start);
1187 info->state = REPODATA_LOADING;
1188 /* no need for LOCALPOOL as pool already contains ids */
1189 repo_add_solv_flags(repo, fp, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1190 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1195 if (!rename(tmpl, calccachepath(repo, repoext)))
1204 Pool *sigpool = pool_create();
1206 Repo *repo = repo_create(sigpool, "rpmdbkeys");
1207 repo_add_rpmdb_pubkeys(repo, 0, 0);
1213 /* repomd helpers */
1215 static inline const char *
1216 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1218 Pool *pool = repo->pool;
1220 const char *filename;
1225 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1226 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1227 if (dataiterator_step(&di))
1229 dataiterator_setpos_parent(&di);
1230 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1231 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1233 dataiterator_free(&di);
1234 if (filename && !*chksumtypep)
1236 printf("no %s file checksum!\n", what);
1243 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1245 Pool *pool = repo->pool;
1247 Id chksumtype, handle;
1248 const unsigned char *chksum;
1249 const char *filename;
1251 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1252 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1253 if (!dataiterator_step(&di))
1255 dataiterator_free(&di);
1258 if (!strcmp(what, "prestodelta"))
1260 dataiterator_setpos_parent(&di);
1261 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1262 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, &chksumtype);
1263 if (!filename || !chksum)
1265 dataiterator_free(&di);
1268 handle = repodata_new_handle(data);
1269 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1270 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1272 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1273 if (!strcmp(what, "deltainfo"))
1275 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1276 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1278 if (!strcmp(what, "filelists"))
1280 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1281 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1283 dataiterator_free(&di);
1284 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1289 /* susetags helpers */
1291 static inline const char *
1292 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1294 Pool *pool = repo->pool;
1296 const char *filename;
1301 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
1302 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1303 if (dataiterator_step(&di))
1305 dataiterator_setpos_parent(&di);
1306 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
1309 dataiterator_free(&di);
1310 if (filename && !*chksumtypep)
1312 printf("no %s file checksum!\n", what);
1318 static Id susetags_langtags[] = {
1319 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
1320 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
1321 SOLVABLE_EULA, REPOKEY_TYPE_STR,
1322 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
1323 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
1324 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
1329 susetags_add_ext(Repo *repo, Repodata *data)
1331 Pool *pool = repo->pool;
1334 Id handle, filechksumtype;
1335 const unsigned char *filechksum;
1338 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
1339 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1340 while (dataiterator_step(&di))
1342 if (strncmp(di.kv.str, "packages.", 9) != 0)
1344 if (!strcmp(di.kv.str + 9, "gz"))
1346 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
1348 ext[0] = di.kv.str[9];
1349 ext[1] = di.kv.str[10];
1351 if (!strcmp(ext, "en"))
1353 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
1355 handle = repodata_new_handle(data);
1356 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
1358 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
1359 if (!strcmp(ext, "DU"))
1361 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
1362 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
1364 else if (!strcmp(ext, "FL"))
1366 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1367 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1371 for (i = 0; susetags_langtags[i]; i += 2)
1373 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
1374 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
1377 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1379 dataiterator_free(&di);
1384 iscompressed(const char *name)
1386 int l = strlen(name);
1387 return l > 3 && !strcmp(name + l - 3, ".gz") ? 1 : 0;
1394 load_stub(Pool *pool, Repodata *data, void *dp)
1396 const char *filename, *descrdir, *repomdtype;
1397 const unsigned char *filechksum;
1399 struct repoinfo *cinfo;
1404 cinfo = data->repo->appdata;
1406 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1410 ext[0] = filename[9];
1411 ext[1] = filename[10];
1414 printf("[%s:%s", data->repo->name, ext);
1416 if (usecachedrepo(data->repo, ext, cinfo->extcookie, 0))
1418 printf(" cached]\n"); fflush(stdout);
1422 printf(" fetching]\n"); fflush(stdout);
1424 defvendor = repo_lookup_id(data->repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1425 descrdir = repo_lookup_str(data->repo, SOLVID_META, SUSETAGS_DESCRDIR);
1427 descrdir = "suse/setup/descr";
1429 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1430 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1432 repo_add_susetags(data->repo, fp, defvendor, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1434 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
1438 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1441 if (!strcmp(repomdtype, "filelists"))
1443 else if (!strcmp(repomdtype, "deltainfo"))
1448 printf("[%s:%s", data->repo->name, ext);
1450 if (usecachedrepo(data->repo, ext, cinfo->extcookie, 0))
1452 printf(" cached]\n");fflush(stdout);
1455 printf(" fetching]\n"); fflush(stdout);
1456 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1458 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1459 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1461 if (!strcmp(ext, "FL"))
1462 repo_add_rpmmd(data->repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1463 else if (!strcmp(ext, "DL"))
1464 repo_add_deltainfoxml(data->repo, fp, REPO_USE_LOADING);
1466 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
1473 static unsigned char installedcookie[32];
1477 repo_add_debdb(Repo *repo, int flags)
1480 if ((fp = fopen("/var/lib/dpkg/status", "r")) == 0)
1482 perror("/var/lib/dpkg/status");
1485 repo_add_debpackages(repo, fp, flags);
1490 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1494 unsigned char *chksum;
1500 compl = strlen(comp);
1506 while(fgets(buf, sizeof(buf), fp))
1511 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1513 if (!strncasecmp(buf, "MD5Sum:", 7))
1515 curchksumtype = REPOKEY_TYPE_MD5;
1518 if (!strncasecmp(buf, "SHA1:", 5))
1520 curchksumtype = REPOKEY_TYPE_SHA1;
1523 if (!strncasecmp(buf, "SHA256:", 7))
1525 curchksumtype = REPOKEY_TYPE_SHA256;
1537 while (*bp && *bp != ' ' && *bp != '\t')
1542 while (*bp == ' ' || *bp == '\t')
1544 while (*bp && *bp != ' ' && *bp != '\t')
1548 while (*bp == ' ' || *bp == '\t')
1551 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1554 if (strncmp(bp, "binary-i386/", 12))
1557 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1559 if (filename && !strcmp(bp, "Packages"))
1562 filename = strdup(fn);
1567 fn = sat_dupjoin("/", filename, 0);
1569 filename = sat_dupjoin("dists/", cinfo->name, fn);
1573 *chksumtypep = chksumtype;
1579 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1582 struct repoinfo *cinfo;
1586 const char *filename;
1587 const unsigned char *filechksum;
1589 const char *descrdir;
1601 repo = repo_create(pool, "@System");
1603 printf("rpm database:");
1604 if (stat("/var/lib/rpm/Packages", &stb))
1605 memset(&stb, 0, sizeof(&stb));
1607 printf("dpgk database:");
1608 if (stat("/var/lib/dpkg/status", &stb))
1609 memset(&stb, 0, sizeof(&stb));
1611 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, installedcookie);
1612 if (usecachedrepo(repo, 0, installedcookie, 0))
1613 printf(" cached\n");
1620 printf(" reading\n");
1622 #ifdef PRODUCTS_PATH
1623 repo_add_products(repo, PRODUCTS_PATH, 0, REPO_NO_INTERNALIZE);
1626 if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
1628 Repo *ref = repo_create(pool, "@System.old");
1629 if (!repo_add_solv(ref, ofp))
1631 repo_add_rpmdb(repo, ref, 0, REPO_REUSE_REPODATA);
1638 repo_add_rpmdb(repo, 0, 0, REPO_REUSE_REPODATA);
1640 repo_add_debdb(repo, REPO_REUSE_REPODATA);
1642 writecachedrepo(repo, 0, 0, installedcookie);
1644 pool_set_installed(pool, repo);
1646 for (i = 0; i < nrepoinfos; i++)
1648 cinfo = repoinfos + i;
1649 if (!cinfo->enabled)
1652 repo = repo_create(pool, cinfo->alias);
1654 repo->appdata = cinfo;
1655 repo->priority = 99 - cinfo->priority;
1657 dorefresh = cinfo->autorefresh;
1658 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0), &stb) == 0)
1660 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1663 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1665 printf("repo '%s':", cinfo->alias);
1666 printf(" cached\n");
1670 switch (cinfo->type)
1673 printf("rpmmd repo '%s':", cinfo->alias);
1675 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1677 printf(" no repomd.xml file, skipped\n");
1682 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1683 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1685 printf(" cached\n");
1689 if (cinfo->repo_gpgcheck)
1691 sigfp = curlfopen(cinfo, "repodata/repomd.xml.asc", 0, 0, 0, 0);
1694 printf(" unsigned, skipped\n");
1699 sigpool = read_sigs();
1700 if (!checksig(sigpool, fp, sigfp))
1702 printf(" checksig failed, skipped\n");
1709 repo_add_repomdxml(repo, fp, 0);
1711 printf(" fetching\n");
1712 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1713 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1715 repo_add_rpmmd(repo, fp, 0, 0);
1719 break; /* hopeless */
1721 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1722 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1724 repo_add_updateinfoxml(repo, fp, 0);
1728 data = repo_add_repodata(repo, 0);
1729 if (!repomd_add_ext(repo, data, "deltainfo"))
1730 repomd_add_ext(repo, data, "prestodelta");
1731 repomd_add_ext(repo, data, "filelists");
1732 repodata_internalize(data);
1734 writecachedrepo(repo, 0, 0, cinfo->cookie);
1735 repodata_create_stubs(repo_last_repodata(repo));
1739 printf("susetags repo '%s':", cinfo->alias);
1743 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1745 printf(" no content file, skipped\n");
1750 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1751 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1753 printf(" cached\n");
1757 if (cinfo->repo_gpgcheck)
1759 sigfp = curlfopen(cinfo, "content.asc", 0, 0, 0, 0);
1762 printf(" unsigned, skipped\n");
1769 sigpool = read_sigs();
1770 if (!checksig(sigpool, fp, sigfp))
1772 printf(" checksig failed, skipped\n");
1780 repo_add_content(repo, fp, 0);
1782 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1783 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1785 descrdir = "suse/setup/descr";
1786 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1788 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1791 printf(" no packages file entry, skipped\n");
1794 printf(" fetching\n");
1795 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) == 0)
1796 break; /* hopeless */
1797 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE);
1799 /* add default language */
1800 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1802 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1805 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1807 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES);
1811 repo_internalize(repo);
1812 data = repo_add_repodata(repo, 0);
1813 susetags_add_ext(repo, data);
1814 repodata_internalize(data);
1816 writecachedrepo(repo, 0, 0, cinfo->cookie);
1817 repodata_create_stubs(repo_last_repodata(repo));
1822 printf("debian repo '%s':", cinfo->alias);
1824 filename = sat_dupjoin("dists/", cinfo->name, "/Release");
1825 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
1827 printf(" no Release file, skipped\n");
1830 free((char *)filename);
1833 sat_free((char *)filename);
1834 if (cinfo->repo_gpgcheck)
1836 filename = sat_dupjoin("dists/", cinfo->name, "/Release.gpg");
1837 sigfp = curlfopen(cinfo, filename, 0, 0, 0, 0);
1838 sat_free((char *)filename);
1841 printf(" unsigned, skipped\n");
1846 sigpool = read_sigs();
1847 if (!checksig(sigpool, fpr, sigfp))
1849 printf(" checksig failed, skipped\n");
1856 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
1857 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1859 printf(" cached\n");
1863 printf(" fetching\n");
1864 for (j = 0; j < cinfo->ncomponents; j++)
1866 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
1868 printf("[component %s not found]\n", cinfo->components[j]);
1871 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1873 repo_add_debpackages(repo, fp, 0);
1876 sat_free((char *)filechksum);
1877 sat_free((char *)filename);
1881 writecachedrepo(repo, 0, 0, cinfo->cookie);
1886 printf("unsupported repo '%s': skipped\n", cinfo->alias);
1898 str2archid(Pool *pool, char *arch)
1903 id = str2id(pool, arch, 0);
1904 if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH)
1906 if (pool->id2arch && (id > pool->lastarch || !pool->id2arch[id]))
1912 #define DEPGLOB_NAME 1
1913 #define DEPGLOB_DEP 2
1914 #define DEPGLOB_NAMEDEP 3
1917 depglob(Pool *pool, char *name, Queue *job, int what)
1920 Id id = str2id(pool, name, 0);
1925 FOR_PROVIDES(p, pp, id)
1927 Solvable *s = pool->solvables + p;
1929 if (s->name == id && (what & DEPGLOB_NAME) != 0)
1931 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
1937 if (what == DEPGLOB_NAMEDEP)
1938 printf("[using capability match for '%s']\n", name);
1939 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
1944 if (strpbrk(name, "[*?") == 0)
1947 if ((what & DEPGLOB_NAME) != 0)
1949 /* looks like a name glob. hard work. */
1950 for (p = 1; p < pool->nsolvables; p++)
1952 Solvable *s = pool->solvables + p;
1953 if (!s->repo || !pool_installable(pool, s))
1956 if (fnmatch(name, id2str(pool, id), 0) == 0)
1958 for (i = 0; i < job->count; i += 2)
1959 if (job->elements[i] == SOLVER_SOLVABLE_NAME && job->elements[i + 1] == id)
1961 if (i == job->count)
1962 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
1969 if ((what & DEPGLOB_DEP))
1971 /* looks like a dep glob. really hard work. */
1972 for (id = 1; id < pool->ss.nstrings; id++)
1974 if (!pool->whatprovides[id])
1976 if (fnmatch(name, id2str(pool, id), 0) == 0)
1978 if (!match && what == DEPGLOB_NAMEDEP)
1979 printf("[using capability match for '%s']\n", name);
1980 for (i = 0; i < job->count; i += 2)
1981 if (job->elements[i] == SOLVER_SOLVABLE_PROVIDES && job->elements[i + 1] == id)
1983 if (i == job->count)
1984 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
1995 limitrelation(Pool *pool, Queue *job, int flags, Id evr)
1999 for (i = j = 0; i < job->count; i += 2)
2001 Id select = job->elements[i] & SOLVER_SELECTMASK;
2002 if (select != SOLVER_SOLVABLE_NAME && select != SOLVER_SOLVABLE_PROVIDES)
2004 fprintf(stderr, "limitrelation only works on name/provides jobs\n");
2007 job->elements[i + 1] = rel2id(pool, job->elements[i + 1], evr, flags, 1);
2008 if (flags == REL_ARCH)
2009 job->elements[i] |= SOLVER_SETARCH;
2010 if (flags == REL_EQ && select == SOLVER_SOLVABLE_NAME && job->elements[i])
2013 const char *evrstr = id2str(pool, evr);
2014 if (!strchr(evrstr, '-'))
2015 job->elements[i] |= SOLVER_SETEV;
2018 job->elements[i] |= SOLVER_SETEVR;
2020 /* make sure we still have matches */
2021 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2025 job->elements[j] = job->elements[i];
2026 job->elements[j + 1] = job->elements[i + 1];
2030 queue_truncate(job, j);
2035 limitrelation_arch(Pool *pool, Queue *job, int flags, char *evr)
2039 if ((r = strrchr(evr, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2042 limitrelation(pool, job, REL_ARCH, archid);
2043 limitrelation(pool, job, flags, str2id(pool, evr, 1));
2047 limitrelation(pool, job, flags, str2id(pool, evr, 1));
2048 return job->count / 2;
2052 limitrepo(Pool *pool, Id repofilter, Queue *job)
2060 for (i = j = 0; i < job->count; i += 2)
2063 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2065 s = pool_id2solvable(pool, p);
2066 if (s->repo && s->repo->repoid == repofilter)
2071 /* here we assume that repo == vendor, so we also set SOLVER_SETVENDOR */
2074 job->elements[j] = SOLVER_SOLVABLE | (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO | SOLVER_NOAUTOSET;
2075 job->elements[j + 1] = mq.elements[0];
2079 job->elements[j] = SOLVER_SOLVABLE_ONE_OF | (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO;
2080 job->elements[j + 1] = pool_queuetowhatprovides(pool, &mq);
2085 queue_truncate(job, j);
2091 mkselect(Pool *pool, int mode, char *name, Queue *job)
2102 dataiterator_init(&di, pool, mode == SOLVER_ERASE ? pool->installed : 0, 0, SOLVABLE_FILELIST, name, SEARCH_STRING|SEARCH_FILES|SEARCH_COMPLETE_FILELIST);
2103 while (dataiterator_step(&di))
2105 Solvable *s = pool->solvables + di.solvid;
2106 if (!s->repo || !pool_installable(pool, s))
2108 queue_push(&q, di.solvid);
2109 dataiterator_skip_solvable(&di);
2111 dataiterator_free(&di);
2114 printf("[using file list match for '%s']\n", name);
2116 queue_push2(job, SOLVER_SOLVABLE_ONE_OF, pool_queuetowhatprovides(pool, &q));
2118 queue_push2(job, SOLVER_SOLVABLE | SOLVER_NOAUTOSET, q.elements[0]);
2120 return job->count / 2;
2123 if ((r = strpbrk(name, "<=>")) != 0)
2125 /* relation case, support:
2130 int nend = r - name;
2143 while (*r && *r == ' ' && *r == '\t')
2145 while (nend && (name[nend - 1] == ' ' || name[nend -1 ] == '\t'))
2149 fprintf(stderr, "bad relation\n");
2152 oldnend = name[nend];
2154 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2156 name[nend] = oldnend;
2157 limitrelation(pool, job, rflags, str2id(pool, r, 1));
2158 return job->count / 2;
2160 if ((r2 = strrchr(name, '.')) != 0 && r2[1] && (archid = str2archid(pool, r2 + 1)) != 0)
2163 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2165 name[nend] = oldnend;
2167 limitrelation(pool, job, REL_ARCH, archid);
2168 limitrelation(pool, job, rflags, str2id(pool, r, 1));
2169 return job->count / 2;
2173 name[nend] = oldnend;
2177 /* no relation case, support:
2181 * nameglob-version.arch
2182 * nameglob-version-release
2183 * nameglob-version-release.arch
2185 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2186 return job->count / 2;
2187 if ((r = strrchr(name, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2190 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2193 limitrelation(pool, job, REL_ARCH, archid);
2194 return job->count / 2;
2198 if ((r = strrchr(name, '-')) != 0)
2201 if (depglob(pool, name, job, DEPGLOB_NAME))
2203 /* have just the version */
2204 limitrelation_arch(pool, job, REL_EQ, r + 1);
2206 return job->count / 2;
2208 if ((r2 = strrchr(name, '-')) != 0)
2213 if (depglob(pool, name, job, DEPGLOB_NAME))
2215 /* have version-release */
2216 limitrelation_arch(pool, job, REL_EQ, r + 1);
2218 return job->count / 2;
2229 yesno(const char *str)
2231 char inbuf[128], *ip;
2238 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2243 while (*ip == ' ' || *ip == '\t')
2250 if (*ip == 'y' || *ip == 'n')
2251 return *ip == 'y' ? 1 : 0;
2265 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2267 struct fcstate *fcstate = cbdata;
2275 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
2278 s = pool_id2solvable(pool, p);
2279 if (pool->installed && s->repo == pool->installed)
2281 if (!s->repo->rpmdbid)
2283 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2286 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
2288 for (i = 0; i < fcstate->newpkgscnt; i++)
2289 if (fcstate->checkq->elements[i] == p)
2291 if (i == fcstate->newpkgscnt)
2293 fp = fcstate->newpkgsfps[i];
2297 return rpm_byfp(fp, solvable2str(pool, s), &fcstate->rpmdbstate);
2302 runrpm(const char *arg, const char *name, int dupfd3)
2307 if ((pid = fork()) == (pid_t)-1)
2314 if (dupfd3 != -1 && dupfd3 != 3)
2320 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2321 if (strcmp(arg, "-e") == 0)
2322 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2324 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2328 while (waitpid(pid, &status, 0) != pid)
2332 printf("rpm failed\n");
2342 rundpkg(const char *arg, const char *name, int dupfd3)
2347 if ((pid = fork()) == (pid_t)-1)
2354 if (dupfd3 != -1 && dupfd3 != 3)
2360 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2361 if (strcmp(arg, "--install") == 0)
2362 execlp("dpkg", "dpkg", "--install", "--force", "all", name, (char *)0);
2364 execlp("dpkg", "dpkg", "--remove", "--force", "all", name, (char *)0);
2368 while (waitpid(pid, &status, 0) != pid)
2372 printf("dpkg failed\n");
2380 nscallback(Pool *pool, void *data, Id name, Id evr)
2382 if (name == NAMESPACE_PRODUCTBUDDY)
2384 /* SUSE specific hack: each product has an associated rpm */
2385 Solvable *s = pool->solvables + evr;
2388 cap = str2id(pool, pool_tmpjoin(pool, "product(", id2str(pool, s->name) + 8, ")"), 0);
2391 cap = rel2id(pool, cap, s->evr, REL_EQ, 0);
2394 FOR_PROVIDES(p, pp, cap)
2396 Solvable *ps = pool->solvables + p;
2397 if (ps->repo == s->repo && ps->arch == s->arch)
2405 #ifdef SOFTLOCKS_PATH
2408 addsoftlocks(Pool *pool, Queue *job)
2412 char *bp, *ep, buf[4096];
2414 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2416 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2418 while (*bp == ' ' || *bp == '\t')
2420 if (!*bp || *bp == '#')
2422 for (ep = bp; *ep; ep++)
2423 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2426 type = SOLVER_SOLVABLE_NAME;
2427 if (!strncmp(bp, "provides:", 9) && bp[9])
2429 type = SOLVER_SOLVABLE_PROVIDES;
2432 id = str2id(pool, bp, 1);
2433 if (pool->installed)
2435 FOR_JOB_SELECT(p, pp, type, id)
2436 if (pool->solvables[p].repo == pool->installed)
2439 continue; /* ignore, as it is already installed */
2441 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2450 rewrite_repos(Pool *pool, Id *addedfileprovides)
2455 Queue fileprovidesq;
2457 int i, j, n, nprovidedids;
2458 struct repoinfo *cinfo;
2460 map_init(&providedids, pool->ss.nstrings);
2461 queue_init(&fileprovidesq);
2462 for (nprovidedids = 0; (id = addedfileprovides[nprovidedids]) != 0; nprovidedids++)
2463 MAPSET(&providedids, id);
2466 /* make sure this repo has just one main repodata */
2467 if (!repo->nrepodata)
2469 cinfo = repo->appdata;
2470 data = repo->repodata + 0;
2471 if (data->store.pagefd == -1)
2473 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2476 for (j = 0; j < fileprovidesq.count; j++)
2477 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2479 if (n == nprovidedids)
2480 continue; /* nothing new added */
2483 for (j = 0; addedfileprovides[j]; j++)
2484 repodata_add_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, addedfileprovides[j]);
2485 repodata_internalize(data);
2486 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2488 queue_free(&fileprovidesq);
2489 map_free(&providedids);
2493 #define MODE_INSTALL 1
2494 #define MODE_ERASE 2
2495 #define MODE_UPDATE 3
2496 #define MODE_DISTUPGRADE 4
2497 #define MODE_VERIFY 5
2498 #define MODE_PATCH 6
2500 #define MODE_REPOLIST 8
2501 #define MODE_SEARCH 9
2502 #define MODE_ERASECLEAN 10
2507 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2508 fprintf(stderr, "\n");
2509 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2510 fprintf(stderr, " versions from the repositories\n");
2511 fprintf(stderr, " erase: erase installed packages\n");
2512 fprintf(stderr, " info: display package information\n");
2513 fprintf(stderr, " install: install packages\n");
2514 fprintf(stderr, " list: list packages\n");
2515 fprintf(stderr, " repos: list enabled repositories\n");
2516 fprintf(stderr, " search: search name/summary/description\n");
2517 fprintf(stderr, " update: update installed packages\n");
2518 fprintf(stderr, " verify: check dependencies of installed packages\n");
2519 fprintf(stderr, "\n");
2524 main(int argc, char **argv)
2527 Repo *commandlinerepo = 0;
2528 Id *commandlinepkgs = 0;
2530 struct repoinfo *repoinfos;
2532 int mainmode = 0, mode = 0;
2537 char inbuf[128], *ip;
2540 Id *addedfileprovides = 0;
2547 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2549 mainmode = MODE_INSTALL;
2550 mode = SOLVER_INSTALL;
2552 else if (!strcmp(argv[0], "patch"))
2554 mainmode = MODE_PATCH;
2555 mode = SOLVER_INSTALL;
2557 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2559 mainmode = MODE_ERASE;
2560 mode = SOLVER_ERASE;
2562 else if (!strcmp(argv[0], "eraseclean") || !strcmp(argv[0], "rmclean"))
2564 mainmode = MODE_ERASECLEAN;
2565 mode = SOLVER_ERASE;
2567 else if (!strcmp(argv[0], "list"))
2569 mainmode = MODE_LIST;
2572 else if (!strcmp(argv[0], "info"))
2574 mainmode = MODE_INFO;
2577 else if (!strcmp(argv[0], "search"))
2579 mainmode = MODE_SEARCH;
2582 else if (!strcmp(argv[0], "verify"))
2584 mainmode = MODE_VERIFY;
2585 mode = SOLVER_VERIFY;
2587 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2589 mainmode = MODE_UPDATE;
2590 mode = SOLVER_UPDATE;
2592 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2594 mainmode = MODE_DISTUPGRADE;
2595 mode = SOLVER_UPDATE;
2597 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2599 mainmode = MODE_REPOLIST;
2605 pool = pool_create();
2609 const char *langs[] = {"de_DE", "de", "en"};
2610 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2615 pool->obsoleteusescolors = 1;
2617 pool_setloadcallback(pool, load_stub, 0);
2618 pool->nscallback = nscallback;
2619 // pool_setdebuglevel(pool, 2);
2621 repoinfos = read_repoinfos(pool, REPOINFO_PATH, &nrepoinfos);
2623 if (mainmode == MODE_REPOLIST)
2626 for (i = 0; i < nrepoinfos; i++)
2628 struct repoinfo *cinfo = repoinfos + i;
2629 if (!cinfo->enabled)
2631 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2636 read_repos(pool, repoinfos, nrepoinfos);
2638 if (argc > 2 && !strcmp(argv[1], "-r"))
2640 const char *rname = argv[2], *rp;
2641 for (rp = rname; *rp; rp++)
2642 if (*rp <= '0' || *rp >= '9')
2646 /* repo specified by number */
2647 int rnum = atoi(rname);
2648 for (i = 0; i < nrepoinfos; i++)
2650 struct repoinfo *cinfo = repoinfos + i;
2651 if (!cinfo->enabled)
2654 repofilter = cinfo->repo->repoid;
2659 /* repo specified by alias */
2663 if (!strcasecmp(rname, repo->name))
2664 repofilter = repo->repoid;
2669 fprintf(stderr, "%s: no such repo\n", rname);
2675 if (mainmode == MODE_SEARCH)
2681 map_init(&m, pool->nsolvables);
2682 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2683 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2684 dataiterator_set_search(&di, 0, 0);
2685 while (dataiterator_step(&di))
2686 MAPSET(&m, di.solvid);
2687 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2688 dataiterator_set_search(&di, 0, 0);
2689 while (dataiterator_step(&di))
2690 MAPSET(&m, di.solvid);
2691 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2692 dataiterator_set_search(&di, 0, 0);
2693 while (dataiterator_step(&di))
2694 MAPSET(&m, di.solvid);
2695 dataiterator_free(&di);
2697 for (p = 1; p < pool->nsolvables; p++)
2699 Solvable *s = pool_id2solvable(pool, p);
2702 printf(" - %s: %s\n", solvable2str(pool, s), solvable_lookup_str(s, SOLVABLE_SUMMARY));
2709 if (mainmode == MODE_LIST || mainmode == MODE_INSTALL)
2711 for (i = 1; i < argc; i++)
2714 l = strlen(argv[i]);
2716 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2719 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2722 if (access(argv[i], R_OK))
2727 if (!commandlinepkgs)
2728 commandlinepkgs = sat_calloc(argc, sizeof(Id));
2729 if (!commandlinerepo)
2730 commandlinerepo = repo_create(pool, "@commandline");
2732 repo_add_rpms(commandlinerepo, (const char **)argv + i, 1, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2734 repo_add_debs(commandlinerepo, (const char **)argv + i, 1, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2736 commandlinepkgs[i] = commandlinerepo->end - 1;
2738 if (commandlinerepo)
2739 repo_internalize(commandlinerepo);
2742 // FOR_REPOS(i, repo)
2743 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2744 addedfileprovides = 0;
2745 pool_addfileprovides_ids(pool, 0, &addedfileprovides);
2746 if (addedfileprovides && *addedfileprovides)
2747 rewrite_repos(pool, addedfileprovides);
2748 sat_free(addedfileprovides);
2749 pool_createwhatprovides(pool);
2752 for (i = 1; i < argc; i++)
2757 if (commandlinepkgs && commandlinepkgs[i])
2759 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2763 if (!mkselect(pool, mode, argv[i], &job2))
2765 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2768 if (repofilter && !limitrepo(pool, repofilter, &job2))
2770 fprintf(stderr, "nothing in repo matches '%s'\n", argv[i]);
2773 for (j = 0; j < job2.count; j++)
2774 queue_push(&job, job2.elements[j]);
2778 if (!job.count && mainmode != MODE_UPDATE && mainmode != MODE_DISTUPGRADE && mainmode != MODE_VERIFY && mainmode != MODE_PATCH)
2780 printf("no package matched\n");
2787 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
2789 /* list mode, no solver needed */
2790 for (i = 0; i < job.count; i += 2)
2792 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
2794 Solvable *s = pool_id2solvable(pool, p);
2795 if (mainmode == MODE_INFO)
2798 printf("Name: %s\n", solvable2str(pool, s));
2799 printf("Repo: %s\n", s->repo->name);
2800 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
2801 str = solvable_lookup_str(s, SOLVABLE_URL);
2803 printf("Url: %s\n", str);
2804 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
2806 printf("License: %s\n", str);
2807 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
2813 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
2815 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
2817 printf(" - %s [%s]\n", solvable2str(pool, s), s->repo->name);
2819 printf(" %s\n", sum);
2825 free_repoinfos(repoinfos, nrepoinfos);
2826 sat_free(commandlinepkgs);
2828 yum_substitute(pool, 0);
2833 if (mainmode == MODE_PATCH)
2839 map_init(&installedmap, pool->nsolvables);
2840 if (pool->installed)
2841 FOR_REPO_SOLVABLES(pool->installed, p, s)
2842 MAPSET(&installedmap, p);
2844 /* install all patches */
2845 for (p = 1; p < pool->nsolvables; p++)
2851 s = pool->solvables + p;
2852 if (strncmp(id2str(pool, s->name), "patch:", 6) != 0)
2854 FOR_PROVIDES(p2, pp, s->name)
2856 Solvable *s2 = pool->solvables + p2;
2857 if (s2->name != s->name)
2859 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2860 if (r < 0 || (r == 0 && p > p2))
2865 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2866 if (type && !strcmp(type, "optional"))
2868 r = solvable_trivial_installable_map(s, &installedmap, 0);
2871 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2878 queue_push2(&job, SOLVER_SOLVABLE, p);
2880 map_free(&installedmap);
2884 for (i = 0; i < job.count; i += 2)
2886 if (mode == SOLVER_UPDATE)
2888 /* make update of not installed packages an install */
2889 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
2890 if (pool->installed && pool->solvables[p].repo == pool->installed)
2894 job.elements[i] |= SOLVER_INSTALL;
2898 job.elements[i] |= mode;
2899 if (mainmode == MODE_ERASECLEAN)
2900 job.elements[i] |= SOLVER_CLEANDEPS;
2903 if (mainmode == MODE_DISTUPGRADE && allpkgs && repofilter)
2904 queue_push2(&job, SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_REPO, repofilter);
2906 // multiversion test
2907 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae", 1));
2908 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-base", 1));
2909 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-extra", 1));
2911 #ifdef SOFTLOCKS_PATH
2912 addsoftlocks(pool, &job);
2920 Id problem, solution;
2923 solv = solver_create(pool);
2924 solv->ignorealreadyrecommended = 1;
2925 solv->updatesystem = allpkgs && !repofilter && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE);
2926 solv->dosplitprovides = solv->updatesystem;
2927 solv->fixsystem = allpkgs && !repofilter && mainmode == MODE_VERIFY;
2928 if (mainmode == MODE_DISTUPGRADE && allpkgs && !repofilter)
2930 solv->distupgrade = 1;
2931 solv->allowdowngrade = 1;
2932 solv->allowarchchange = 1;
2933 solv->allowvendorchange = 1;
2935 if (mainmode == MODE_ERASE || mainmode == MODE_ERASECLEAN)
2936 solv->allowuninstall = 1; /* don't nag */
2938 solver_solve(solv, &job);
2939 if (!solv->problems.count)
2941 pcnt = solver_problem_count(solv);
2942 printf("Found %d problems:\n", pcnt);
2943 for (problem = 1; problem <= pcnt; problem++)
2946 printf("Problem %d:\n", problem);
2947 solver_printprobleminfo(solv, problem);
2949 scnt = solver_solution_count(solv, problem);
2950 for (solution = 1; solution <= scnt; solution++)
2952 printf("Solution %d:\n", solution);
2953 solver_printsolution(solv, problem, solution);
2958 printf("Please choose a solution: ");
2961 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2966 while (*ip == ' ' || *ip == '\t')
2968 if (*ip >= '0' && *ip <= '9')
2971 if (take >= 1 && take <= scnt)
2987 solver_take_solution(solv, problem, take, &job);
2993 trans = &solv->trans;
2994 if (!trans->steps.count)
2996 printf("Nothing to do.\n");
3000 printf("Transaction summary:\n\n");
3001 solver_printtransaction(solv);
3003 #if !defined(FEDORA) && !defined(DEBIAN)
3010 duc[1].path = "/usr/share/man";
3011 duc[2].path = "/sbin";
3012 duc[3].path = "/etc";
3013 transaction_calc_duchanges(trans, duc, 4);
3014 for (i = 0; i < 4; i++)
3015 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
3018 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
3021 if (!yesno("OK to continue (y/n)? "))
3027 free_repoinfos(repoinfos, nrepoinfos);
3028 sat_free(commandlinepkgs);
3030 yum_substitute(pool, 0);
3035 queue_init(&checkq);
3036 newpkgs = transaction_installedresult(trans, &checkq);
3041 int downloadsize = 0;
3042 for (i = 0; i < newpkgs; i++)
3046 p = checkq.elements[i];
3047 s = pool_id2solvable(pool, p);
3048 downloadsize += solvable_lookup_num(s, SOLVABLE_DOWNLOADSIZE, 0);
3050 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
3051 newpkgsfps = sat_calloc(newpkgs, sizeof(*newpkgsfps));
3052 for (i = 0; i < newpkgs; i++)
3054 unsigned int medianr;
3057 struct repoinfo *cinfo;
3058 const unsigned char *chksum;
3062 p = checkq.elements[i];
3063 s = pool_id2solvable(pool, p);
3064 if (s->repo == commandlinerepo)
3066 loc = solvable_get_location(s, &medianr);
3067 if (!(newpkgsfps[i] = fopen(loc, "r")))
3075 cinfo = s->repo->appdata;
3078 printf("%s: no repository information\n", s->repo->name);
3081 loc = solvable_get_location(s, &medianr);
3085 if (pool->installed && pool->installed->nsolvables)
3087 /* try a delta first */
3088 char *matchname = strdup(id2str(pool, s->name));
3089 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
3090 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
3091 while (dataiterator_step(&di))
3095 dataiterator_setpos_parent(&di);
3096 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
3097 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
3099 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
3100 FOR_PROVIDES(op, pp, s->name)
3102 Solvable *os = pool->solvables + op;
3103 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
3106 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
3108 /* base is installed, run sequence check */
3109 const char *seqname;
3118 seqname = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME);
3119 seqevr = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR);
3120 seqnum = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM);
3121 seq = pool_tmpjoin(pool, seqname, "-", seqevr);
3122 seq = pool_tmpjoin(pool, seq, "-", seqnum);
3124 sprintf(cmd, "/usr/bin/applydeltarpm -a %s -c -s ", id2str(pool, s->arch));
3126 sprintf(cmd, "/usr/bin/applydeltarpm -c -s ");
3128 if (system(pool_tmpjoin(pool, cmd, seq, 0)) != 0)
3129 continue; /* didn't match */
3130 /* looks good, download delta */
3132 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
3134 continue; /* no way! */
3135 dloc = pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_DIR);
3136 dloc = pool_tmpjoin(pool, dloc, "/", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_NAME));
3137 dloc = pool_tmpjoin(pool, dloc, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_EVR));
3138 dloc = pool_tmpjoin(pool, dloc, ".", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_SUFFIX));
3139 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
3141 /* got it, now reconstruct */
3142 newfd = opentmpfile();
3144 sprintf(cmd, "applydeltarpm -a %s /dev/fd/%d /dev/fd/%d", id2str(pool, s->arch), fileno(fp), newfd);
3146 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
3148 fcntl(fileno(fp), F_SETFD, 0);
3155 lseek(newfd, 0, SEEK_SET);
3157 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3158 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
3164 newpkgsfps[i] = fdopen(newfd, "r");
3169 dataiterator_free(&di);
3170 sat_free(matchname);
3177 continue; /* delta worked! */
3179 if (cinfo->type == TYPE_SUSETAGS)
3181 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3182 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3185 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3186 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3188 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3201 struct fcstate fcstate;
3203 printf("Searching for file conflicts\n");
3204 queue_init(&conflicts);
3205 fcstate.rpmdbstate = 0;
3206 fcstate.newpkgscnt = newpkgs;
3207 fcstate.checkq = &checkq;
3208 fcstate.newpkgsfps = newpkgsfps;
3209 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fileconflict_cb, &fcstate);
3210 if (conflicts.count)
3213 for (i = 0; i < conflicts.count; i += 5)
3214 printf("file %s of package %s conflicts with package %s\n", id2str(pool, conflicts.elements[i]), solvid2str(pool, conflicts.elements[i + 1]), solvid2str(pool, conflicts.elements[i + 3]));
3216 if (yesno("Re-run solver (y/n/q)? "))
3218 for (i = 0; i < newpkgs; i++)
3220 fclose(newpkgsfps[i]);
3221 newpkgsfps = sat_free(newpkgsfps);
3223 pool_add_fileconflicts_deps(pool, &conflicts);
3224 pool_createwhatprovides(pool); /* Hmm... */
3228 queue_free(&conflicts);
3232 printf("Committing transaction:\n\n");
3233 transaction_order(trans, 0);
3234 for (i = 0; i < trans->steps.count; i++)
3237 const char *evr, *evrp, *nvra;
3243 p = trans->steps.elements[i];
3244 s = pool_id2solvable(pool, p);
3245 Id type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3248 case SOLVER_TRANSACTION_ERASE:
3249 printf("erase %s\n", solvid2str(pool, p));
3251 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3253 /* strip epoch from evr */
3254 evr = evrp = id2str(pool, s->evr);
3255 while (*evrp >= '0' && *evrp <= '9')
3257 if (evrp > evr && evrp[0] == ':' && evrp[1])
3259 nvra = pool_tmpjoin(pool, id2str(pool, s->name), "-", evr);
3260 nvra = pool_tmpjoin(pool, nvra, ".", id2str(pool, s->arch));
3261 runrpm("-e", nvra, -1); /* too bad that --querybynumber doesn't work */
3263 rundpkg("--remove", id2str(pool, s->name), 0);
3266 case SOLVER_TRANSACTION_INSTALL:
3267 case SOLVER_TRANSACTION_MULTIINSTALL:
3268 printf("install %s\n", solvid2str(pool, p));
3269 for (j = 0; j < newpkgs; j++)
3270 if (checkq.elements[j] == p)
3272 fp = j < newpkgs ? newpkgsfps[j] : 0;
3276 lseek(fileno(fp), 0, SEEK_SET);
3278 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp));
3280 rundpkg("--install", "/dev/fd/3", fileno(fp));
3290 for (i = 0; i < newpkgs; i++)
3292 fclose(newpkgsfps[i]);
3293 sat_free(newpkgsfps);
3294 queue_free(&checkq);
3298 free_repoinfos(repoinfos, nrepoinfos);
3299 sat_free(commandlinepkgs);
3301 yum_substitute(pool, 0);