2 * Copyright (c) 2009, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
8 /* solv, a little software installer demoing the sat solver library */
11 * - understands globs for package names / dependencies
12 * - understands .arch suffix
13 * - installation of commandline packages
14 * - repository data caching
15 * - on demand loading of secondary repository data
16 * - gpg and checksum verification
19 * - fastestmirror implementation
21 * things available in the library but missing from solv:
22 * - vendor policy loading
23 * - soft locks file handling
24 * - multi version handling
37 #include <sys/utsname.h>
38 #include <sys/types.h>
45 #include <sys/socket.h>
57 #include "solverdebug.h"
59 #include "repo_solv.h"
61 #include "repo_write.h"
63 #include "repo_rpmdb.h"
64 #include "pool_fileconflicts.h"
70 #include "repo_rpmmd.h"
71 #include "repo_repomdxml.h"
72 #include "repo_updateinfoxml.h"
73 #include "repo_deltainfoxml.h"
75 #ifdef ENABLE_SUSEREPO
76 #include "repo_products.h"
77 #include "repo_susetags.h"
78 #include "repo_content.h"
80 #include "solv_xfopen.h"
83 # define REPOINFO_PATH "/etc/yum.repos.d"
86 # define REPOINFO_PATH "/etc/zypp/repos.d"
87 # define PRODUCTS_PATH "/etc/products.d"
88 # define SOFTLOCKS_PATH "/var/lib/zypp/SoftLocks"
91 #define SOLVCACHE_PATH "/var/cache/solv"
93 #define METADATA_EXPIRE (60 * 15)
115 unsigned char cookie[32];
116 unsigned char extcookie[32];
121 yum_substitute(Pool *pool, char *line)
124 static char *releaseevr;
125 static char *basearch;
129 solv_free(releaseevr);
136 while ((p2 = strchr(p, '$')) != 0)
138 if (!strncmp(p2, "$releasever", 11))
145 rpm_installedrpmdbids(0, "Providename", "redhat-release", &q);
148 void *handle, *state = 0;
150 handle = rpm_byrpmdbid(q.elements[0], 0, &state);
151 releaseevr = rpm_query(handle, SOLVABLE_EVR);
152 rpm_byrpmdbid(0, 0, &state);
153 if ((p = strchr(releaseevr, '-')) != 0)
158 releaseevr = strdup("?");
161 p = pool_tmpjoin(pool, line, releaseevr, p2 + 11);
162 p2 = p + (p2 - line);
164 p = p2 + strlen(releaseevr);
167 if (!strncmp(p2, "$basearch", 9))
177 basearch = strdup(un.machine);
178 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
182 p = pool_tmpjoin(pool, line, basearch, p2 + 9);
183 p2 = p + (p2 - line);
185 p = p2 + strlen(basearch);
194 #define TYPE_UNKNOWN 0
195 #define TYPE_SUSETAGS 1
197 #define TYPE_PLAINDIR 3
198 #define TYPE_DEBIAN 4
202 read_repoinfos_sort(const void *ap, const void *bp)
204 const struct repoinfo *a = ap;
205 const struct repoinfo *b = bp;
206 return strcmp(a->alias, b->alias);
210 #if defined(SUSE) || defined(FEDORA)
213 read_repoinfos(Pool *pool, int *nrepoinfosp)
215 const char *reposdir = REPOINFO_PATH;
217 char buf2[4096], *kp, *vp, *kpe;
222 struct repoinfo *repoinfos = 0, *cinfo;
225 rdlen = strlen(reposdir);
226 dir = opendir(reposdir);
232 while ((ent = readdir(dir)) != 0)
234 if (ent->d_name[0] == '.')
236 l = strlen(ent->d_name);
237 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
239 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
240 if ((fp = fopen(buf, "r")) == 0)
246 while(fgets(buf2, sizeof(buf2), fp))
251 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
254 while (*kp == ' ' || *kp == '\t')
256 if (!*kp || *kp == '#')
260 kp = yum_substitute(pool, kp);
264 vp = strrchr(kp, ']');
268 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
269 cinfo = repoinfos + nrepoinfos++;
270 memset(cinfo, 0, sizeof(*cinfo));
271 cinfo->alias = strdup(kp + 1);
272 cinfo->type = TYPE_RPMMD;
273 cinfo->autorefresh = 1;
274 cinfo->priority = 99;
276 cinfo->repo_gpgcheck = 1;
278 cinfo->metadata_expire = METADATA_EXPIRE;
283 vp = strchr(kp, '=');
286 for (kpe = vp - 1; kpe >= kp; kpe--)
287 if (*kpe != ' ' && *kpe != '\t')
292 while (*vp == ' ' || *vp == '\t')
295 if (!strcmp(kp, "name"))
296 cinfo->name = strdup(vp);
297 else if (!strcmp(kp, "enabled"))
298 cinfo->enabled = *vp == '0' ? 0 : 1;
299 else if (!strcmp(kp, "autorefresh"))
300 cinfo->autorefresh = *vp == '0' ? 0 : 1;
301 else if (!strcmp(kp, "gpgcheck"))
302 cinfo->pkgs_gpgcheck = *vp == '0' ? 0 : 1;
303 else if (!strcmp(kp, "repo_gpgcheck"))
304 cinfo->repo_gpgcheck = *vp == '0' ? 0 : 1;
305 else if (!strcmp(kp, "baseurl"))
306 cinfo->baseurl = strdup(vp);
307 else if (!strcmp(kp, "mirrorlist"))
309 if (strstr(vp, "metalink"))
310 cinfo->metalink = strdup(vp);
312 cinfo->mirrorlist = strdup(vp);
314 else if (!strcmp(kp, "path"))
316 if (vp && strcmp(vp, "/") != 0)
317 cinfo->path = strdup(vp);
319 else if (!strcmp(kp, "type"))
321 if (!strcmp(vp, "yast2"))
322 cinfo->type = TYPE_SUSETAGS;
323 else if (!strcmp(vp, "rpm-md"))
324 cinfo->type = TYPE_RPMMD;
325 else if (!strcmp(vp, "plaindir"))
326 cinfo->type = TYPE_PLAINDIR;
328 cinfo->type = TYPE_UNKNOWN;
330 else if (!strcmp(kp, "priority"))
331 cinfo->priority = atoi(vp);
332 else if (!strcmp(kp, "keeppackages"))
333 cinfo->keeppackages = *vp == '0' ? 0 : 1;
339 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
340 *nrepoinfosp = nrepoinfos;
349 read_repoinfos(Pool *pool, int *nrepoinfosp)
355 char *kp, *url, *distro;
356 struct repoinfo *repoinfos = 0, *cinfo;
361 fp = fopen("/etc/apt/sources.list", "r");
368 dir = opendir("/etc/apt/sources.list.d");
372 if ((ent = readdir(dir)) == 0)
377 if (ent->d_name[0] == '.')
379 l = strlen(ent->d_name);
380 if (l < 5 || strcmp(ent->d_name + l - 5, ".list") != 0)
382 snprintf(buf, sizeof(buf), "%s/%s", "/etc/apt/sources.list.d", ent->d_name);
383 if (!(fp = fopen(buf, "r")))
386 while(fgets(buf2, sizeof(buf2), fp))
391 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
394 while (*kp == ' ' || *kp == '\t')
396 if (!*kp || *kp == '#')
398 if (strncmp(kp, "deb", 3) != 0)
401 if (*kp != ' ' && *kp != '\t')
403 while (*kp == ' ' || *kp == '\t')
408 while (*kp && *kp != ' ' && *kp != '\t')
412 while (*kp == ' ' || *kp == '\t')
417 while (*kp && *kp != ' ' && *kp != '\t')
421 while (*kp == ' ' || *kp == '\t')
425 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
426 cinfo = repoinfos + nrepoinfos++;
427 memset(cinfo, 0, sizeof(*cinfo));
428 cinfo->baseurl = strdup(url);
429 cinfo->alias = solv_dupjoin(url, "/", distro);
430 cinfo->name = strdup(distro);
431 cinfo->type = TYPE_DEBIAN;
433 cinfo->autorefresh = 1;
434 cinfo->repo_gpgcheck = 1;
435 cinfo->metadata_expire = METADATA_EXPIRE;
439 while (*kp == ' ' || *kp == '\t')
444 while (*kp && *kp != ' ' && *kp != '\t')
448 cinfo->components = solv_extend(cinfo->components, cinfo->ncomponents, 1, sizeof(*cinfo->components), 15);
449 cinfo->components[cinfo->ncomponents++] = strdup(compo);
455 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
456 *nrepoinfosp = nrepoinfos;
464 read_repoinfos(Pool *pool, int *nrepoinfosp)
473 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
476 for (i = 0; i < nrepoinfos; i++)
478 struct repoinfo *cinfo = repoinfos + i;
479 solv_free(cinfo->name);
480 solv_free(cinfo->alias);
481 solv_free(cinfo->path);
482 solv_free(cinfo->metalink);
483 solv_free(cinfo->mirrorlist);
484 solv_free(cinfo->baseurl);
485 for (j = 0; j < cinfo->ncomponents; j++)
486 solv_free(cinfo->components[j]);
487 solv_free(cinfo->components);
489 solv_free(repoinfos);
498 strcpy(tmpl, "/var/tmp/solvXXXXXX");
510 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
513 const unsigned char *sum;
517 h = solv_chksum_create(chksumtype);
520 printf("%s: unknown checksum type\n", file);
523 while ((l = read(fd, buf, sizeof(buf))) > 0)
524 solv_chksum_add(h, buf, l);
525 lseek(fd, 0, SEEK_SET);
527 sum = solv_chksum_get(h, &l);
528 if (memcmp(sum, chksum, l))
530 printf("%s: checksum mismatch\n", file);
531 solv_chksum_free(h, 0);
534 solv_chksum_free(h, 0);
539 findfastest(char **urls, int nurls)
546 struct addrinfo hints, *result;;
548 fds = solv_calloc(nurls, sizeof(*fds));
549 socks = solv_calloc(nurls, sizeof(*socks));
550 for (i = 0; i < nurls; i++)
553 p = strchr(urls[i], '/');
566 if ((p2 = strchr(p, '@')) != 0)
569 if (!strncmp("https:", urls[i], 6))
571 else if (!strncmp("ftp:", urls[i], 4))
573 if ((p2 = strrchr(p, ':')) != 0)
582 sprintf(portstr, "%d", port);
583 memset(&hints, 0, sizeof(struct addrinfo));
584 hints.ai_family = AF_UNSPEC;
585 hints.ai_socktype = SOCK_STREAM;
586 hints.ai_flags = AI_NUMERICSERV;
588 if (!getaddrinfo(p, portstr, &hints, &result))
590 socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
593 fcntl(socks[i], F_SETFL, O_NONBLOCK);
594 if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1)
596 if (errno != EINPROGRESS)
603 freeaddrinfo(result);
610 for (i = j = 0; i < nurls; i++)
614 fds[j].fd = socks[i];
615 fds[j].events = POLLOUT;
623 if (poll(fds, j, 10000) <= 0)
625 i = -1; /* something is wrong */
628 for (i = 0; i < j; i++)
629 if ((fds[i].revents & POLLOUT) != 0)
632 socklen_t soel = sizeof(int);
633 if (getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, &soe, &soel) == -1 || soe != 0)
635 /* connect failed, kill socket */
636 for (j = 0; j < nurls; j++)
637 if (socks[j] == fds[i].fd)
650 i = -1; /* something is wrong, no bit was set */
653 /* now i contains the fastest fd index */
656 for (j = 0; j < nurls; j++)
657 if (socks[j] == fds[i].fd)
661 char *url0 = urls[0];
666 for (i = j = 0; i < nurls; i++)
674 findmetalinkurl(FILE *fp, unsigned char *chksump, Id *chksumtypep)
676 char buf[4096], *bp, *ep;
683 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
685 while (*bp == ' ' || *bp == '\t')
687 if (chksumtypep && !*chksumtypep && !strncmp(bp, "<hash type=\"sha256\">", 20))
690 if (solv_hex2bin((const char **)&bp, chksump, 32) == 32)
691 *chksumtypep = REPOKEY_TYPE_SHA256;
694 if (strncmp(bp, "<url", 4))
696 bp = strchr(bp, '>');
700 ep = strstr(bp, "repodata/repomd.xml</url>");
704 if (strncmp(bp, "http", 4))
706 urls = solv_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 findmirrorlisturl(FILE *fp)
733 char buf[4096], *bp, *ep;
738 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
740 while (*bp == ' ' || *bp == '\t')
742 if (!*bp || *bp == '#')
745 while (l > 0 && (bp[l - 1] == ' ' || bp[l - 1] == '\t' || bp[l - 1] == '\n'))
747 urls = solv_extend(urls, nurls, 1, sizeof(*urls), 15);
748 urls[nurls++] = strdup(bp);
753 findfastest(urls, nurls > 5 ? 5 : nurls);
756 for (i = 0; i < nurls; i++)
759 ep = strchr(bp, '/');
760 if ((ep = strchr(ep + 2, '/')) != 0)
763 printf("[using mirror %s]\n", bp);
772 iscompressed(const char *name)
774 int l = strlen(name);
775 return l > 3 && !strcmp(name + l - 3, ".gz") ? 1 : 0;
779 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int *badchecksump)
785 const char *baseurl = cinfo->baseurl;
789 if (!cinfo->metalink && !cinfo->mirrorlist)
791 if (file != cinfo->metalink && file != cinfo->mirrorlist)
793 FILE *fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
794 unsigned char mlchksum[32];
799 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
801 cinfo->baseurl = findmirrorlisturl(fp);
806 if (strchr(cinfo->baseurl, '$'))
808 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
809 free(cinfo->baseurl);
810 cinfo->baseurl = strdup(b);
813 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
815 chksumtype = mlchksumtype;
818 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, badchecksump);
820 snprintf(url, sizeof(url), "%s", file);
825 if (l && baseurl[l - 1] == '/')
826 snprintf(url, sizeof(url), "%s%s", baseurl, file);
828 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
831 // printf("url: %s\n", url);
832 if ((pid = fork()) == (pid_t)-1)
844 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
849 while (waitpid(pid, &status, 0) != pid)
851 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
857 lseek(fd, 0, SEEK_SET);
860 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
866 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
874 return solv_xfopen_fd(".gz", fd, "r");
875 fcntl(fd, F_SETFD, FD_CLOEXEC);
876 return fdopen(fd, "r");
882 cleanupgpg(char *gpgdir)
885 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
887 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
889 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
891 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
893 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
899 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
908 off_t posfp, possigfp;
911 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
914 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
915 if (!(kfp = fopen(keysfile, "w")) )
921 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
925 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
926 if (!pubkey || !*pubkey)
928 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
930 if (fputc('\n', kfp) == EOF) /* Just in case... */
934 if (fclose(kfp) || !nkeys)
939 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
942 fprintf(stderr, "key import error\n");
947 posfp = lseek(fileno(fp), 0, SEEK_CUR);
948 lseek(fileno(fp), 0, SEEK_SET);
949 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
950 lseek(fileno(sigfp), 0, SEEK_SET);
951 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
952 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
953 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
955 lseek(fileno(sigfp), possigfp, SEEK_SET);
956 lseek(fileno(fp), posfp, SEEK_SET);
957 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
958 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
960 return r == 0 ? 1 : 0;
966 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
971 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));
972 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
973 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
975 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
976 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
977 return r == 0 ? 1 : 0;
982 #define CHKSUM_IDENT "1.1"
985 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
988 void *h = solv_chksum_create(chktype);
991 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
992 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
993 solv_chksum_add(h, buf, l);
995 solv_chksum_free(h, out);
999 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *out)
1001 void *h = solv_chksum_create(chktype);
1002 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1003 solv_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
1004 solv_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
1005 solv_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
1006 solv_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
1007 solv_chksum_free(h, out);
1019 pool_setarch(pool, un.machine);
1022 char *calccachepath(Repo *repo, const char *repoext)
1024 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
1027 p = pool_tmpappend(repo->pool, p, "_", repoext);
1028 p = pool_tmpappend(repo->pool, p, ".solvx", 0);
1031 p = pool_tmpappend(repo->pool, p, ".solv", 0);
1032 q = p + strlen(SOLVCACHE_PATH) + 1;
1042 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1045 unsigned char mycookie[32];
1046 unsigned char myextcookie[32];
1047 struct repoinfo *cinfo;
1050 cinfo = repo->appdata;
1051 if (!(fp = fopen(calccachepath(repo, repoext), "r")))
1053 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1058 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1063 if (cinfo && !repoext)
1065 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1076 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1077 if (strcmp(repoext, "DL") != 0)
1078 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1081 if (repo_add_solv(repo, fp, flags))
1086 if (cinfo && !repoext)
1088 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1089 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1092 futimes(fileno(fp), 0); /* try to set modification time */
1098 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1103 struct repoinfo *cinfo;
1106 cinfo = repo->appdata;
1107 mkdir(SOLVCACHE_PATH, 0755);
1108 /* use dupjoin instead of tmpjoin because tmpl must survive repo_write */
1109 tmpl = solv_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
1117 if (!(fp = fdopen(fd, "w")))
1126 for (i = repo->start; i < repo->end; i++)
1127 if (repo->pool->solvables[i].repo != repo)
1133 repo_write(repo, fp);
1135 repodata_write(info, fp);
1138 int oldnrepodata = repo->nrepodata;
1139 repo->nrepodata = oldnrepodata > 2 ? 2 : oldnrepodata; /* XXX: do this right */
1140 repo_write(repo, fp);
1141 repo->nrepodata = oldnrepodata;
1145 if (!repoext && cinfo)
1147 if (!cinfo->extcookie[0])
1149 /* create the ext cookie and append it */
1150 /* we just need some unique ID */
1152 if (!fstat(fileno(fp), &stb))
1156 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cinfo->extcookie);
1157 for (i = 0; i < 32; i++)
1158 cinfo->extcookie[i] ^= cookie[i];
1160 if (cinfo->extcookie[0] == 0)
1161 cinfo->extcookie[0] = 1;
1163 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1171 /* append our cookie describing the metadata state */
1172 if (fwrite(cookie, 32, 1, fp) != 1)
1187 /* switch to just saved repo to activate paging and save memory */
1188 FILE *fp = fopen(tmpl, "r");
1194 repo_empty(repo, 1);
1195 if (repo_add_solv(repo, fp, SOLV_ADD_NO_STUBS))
1197 /* oops, no way to recover from here */
1198 fprintf(stderr, "internal error\n");
1204 /* make sure repodata contains complete repo */
1205 /* (this is how repodata_write saves it) */
1206 repodata_extend_block(info, repo->start, repo->end - repo->start);
1207 info->state = REPODATA_LOADING;
1208 /* no need for LOCALPOOL as pool already contains ids */
1209 repo_add_solv(repo, fp, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1210 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1215 if (!rename(tmpl, calccachepath(repo, repoext)))
1224 Pool *sigpool = pool_create();
1225 #if defined(ENABLE_RPMDB_PUBKEY)
1226 Repo *repo = repo_create(sigpool, "rpmdbkeys");
1227 repo_add_rpmdb_pubkeys(repo, 0, 0);
1234 /* repomd helpers */
1236 static inline const char *
1237 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1239 Pool *pool = repo->pool;
1241 const char *filename;
1246 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1247 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1248 if (dataiterator_step(&di))
1250 dataiterator_setpos_parent(&di);
1251 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1252 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1254 dataiterator_free(&di);
1255 if (filename && !*chksumtypep)
1257 printf("no %s file checksum!\n", what);
1264 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1266 Id chksumtype, handle;
1267 const unsigned char *chksum;
1268 const char *filename;
1270 filename = repomd_find(repo, what, &chksum, &chksumtype);
1273 if (!strcmp(what, "prestodelta"))
1275 handle = repodata_new_handle(data);
1276 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1277 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1278 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1279 if (!strcmp(what, "deltainfo"))
1281 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1282 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1284 if (!strcmp(what, "filelists"))
1286 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1287 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1289 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1294 repomd_load_ext(Repo *repo, Repodata *data)
1296 const char *filename, *repomdtype;
1299 struct repoinfo *cinfo;
1300 const unsigned char *filechksum;
1303 cinfo = repo->appdata;
1304 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1307 if (!strcmp(repomdtype, "filelists"))
1309 else if (!strcmp(repomdtype, "deltainfo"))
1314 printf("[%s:%s", repo->name, ext);
1316 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1318 printf(" cached]\n");fflush(stdout);
1321 printf(" fetching]\n"); fflush(stdout);
1322 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1324 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1325 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1327 if (!strcmp(ext, "FL"))
1328 repo_add_rpmmd(repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1329 else if (!strcmp(ext, "DL"))
1330 repo_add_deltainfoxml(repo, fp, REPO_USE_LOADING);
1332 writecachedrepo(repo, data, ext, cinfo->extcookie);
1339 #ifdef ENABLE_SUSEREPO
1340 /* susetags helpers */
1342 static inline const char *
1343 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1345 Pool *pool = repo->pool;
1347 const char *filename;
1352 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
1353 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1354 if (dataiterator_step(&di))
1356 dataiterator_setpos_parent(&di);
1357 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
1360 dataiterator_free(&di);
1361 if (filename && !*chksumtypep)
1363 printf("no %s file checksum!\n", what);
1369 static Id susetags_langtags[] = {
1370 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
1371 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
1372 SOLVABLE_EULA, REPOKEY_TYPE_STR,
1373 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
1374 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
1375 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
1380 susetags_add_ext(Repo *repo, Repodata *data)
1382 Pool *pool = repo->pool;
1385 Id handle, filechksumtype;
1386 const unsigned char *filechksum;
1389 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
1390 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1391 while (dataiterator_step(&di))
1393 if (strncmp(di.kv.str, "packages.", 9) != 0)
1395 if (!strcmp(di.kv.str + 9, "gz"))
1397 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
1399 ext[0] = di.kv.str[9];
1400 ext[1] = di.kv.str[10];
1402 if (!strcmp(ext, "en"))
1404 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
1406 handle = repodata_new_handle(data);
1407 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
1409 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
1410 if (!strcmp(ext, "DU"))
1412 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
1413 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
1415 else if (!strcmp(ext, "FL"))
1417 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1418 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1422 for (i = 0; susetags_langtags[i]; i += 2)
1424 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
1425 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
1428 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1430 dataiterator_free(&di);
1434 susetags_load_ext(Repo *repo, Repodata *data)
1436 const char *filename, *descrdir;
1440 struct repoinfo *cinfo;
1441 const unsigned char *filechksum;
1444 cinfo = repo->appdata;
1445 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1449 ext[0] = filename[9];
1450 ext[1] = filename[10];
1453 printf("[%s:%s", repo->name, ext);
1455 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1457 printf(" cached]\n"); fflush(stdout);
1461 printf(" fetching]\n"); fflush(stdout);
1463 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1464 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1466 descrdir = "suse/setup/descr";
1468 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1469 if ((fp = curlfopen(cinfo, pool_tmpjoin(repo->pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1471 repo_add_susetags(repo, fp, defvendor, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1473 writecachedrepo(repo, data, ext, cinfo->extcookie);
1483 load_stub(Pool *pool, Repodata *data, void *dp)
1485 struct repoinfo *cinfo = data->repo->appdata;
1486 #ifdef ENABLE_SUSEREPO
1487 if (cinfo->type == TYPE_SUSETAGS)
1488 return susetags_load_ext(data->repo, data);
1491 if (cinfo->type == TYPE_RPMMD)
1492 return repomd_load_ext(data->repo, data);
1497 static unsigned char installedcookie[32];
1499 #ifdef ENABLE_DEBIAN
1502 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1506 unsigned char *chksum;
1511 static char *basearch;
1523 basearch = strdup(un.machine);
1524 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
1527 binarydir = solv_dupjoin("binary-", basearch, "/");
1528 lbinarydir = strlen(binarydir);
1529 compl = strlen(comp);
1533 chksum = solv_malloc(32);
1535 while(fgets(buf, sizeof(buf), fp))
1540 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1542 if (!strncasecmp(buf, "MD5Sum:", 7))
1544 curchksumtype = REPOKEY_TYPE_MD5;
1547 if (!strncasecmp(buf, "SHA1:", 5))
1549 curchksumtype = REPOKEY_TYPE_SHA1;
1552 if (!strncasecmp(buf, "SHA256:", 7))
1554 curchksumtype = REPOKEY_TYPE_SHA256;
1566 while (*bp && *bp != ' ' && *bp != '\t')
1571 while (*bp == ' ' || *bp == '\t')
1573 while (*bp && *bp != ' ' && *bp != '\t')
1577 while (*bp == ' ' || *bp == '\t')
1580 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1583 if (strncmp(bp, binarydir, lbinarydir))
1586 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1588 unsigned char curchksum[32];
1590 if (filename && !strcmp(bp, "Packages"))
1592 curl = solv_chksum_len(curchksumtype);
1593 if (!curl || (chksumtype && solv_chksum_len(chksumtype) > curl))
1595 if (solv_hex2bin((const char **)&ch, curchksum, sizeof(curchksum)) != curl)
1597 solv_free(filename);
1598 filename = strdup(fn);
1599 chksumtype = curchksumtype;
1600 memcpy(chksum, curchksum, curl);
1606 fn = solv_dupjoin("/", filename, 0);
1607 solv_free(filename);
1608 filename = solv_dupjoin("dists/", cinfo->name, fn);
1612 chksum = solv_free(chksum);
1614 *chksumtypep = chksumtype;
1620 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1623 struct repoinfo *cinfo;
1627 const char *filename;
1628 const unsigned char *filechksum;
1630 #ifdef ENABLE_SUSEREPO
1631 const char *descrdir;
1639 #if defined(ENABLE_DEBIAN)
1644 repo = repo_create(pool, "@System");
1645 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1646 printf("rpm database:");
1647 if (stat("/var/lib/rpm/Packages", &stb))
1648 memset(&stb, 0, sizeof(&stb));
1650 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1651 printf("dpgk database:");
1652 if (stat("/var/lib/dpkg/status", &stb))
1653 memset(&stb, 0, sizeof(&stb));
1656 printf("no installed database:");
1657 memset(&stb, 0, sizeof(&stb));
1659 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, installedcookie);
1660 if (usecachedrepo(repo, 0, installedcookie, 0))
1661 printf(" cached\n");
1664 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1668 printf(" reading\n");
1670 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1671 # if defined(ENABLE_SUSEREPO) && defined(PRODUCTS_PATH)
1672 repo_add_products(repo, PRODUCTS_PATH, 0, REPO_NO_INTERNALIZE);
1674 if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
1676 Repo *ref = repo_create(pool, "@System.old");
1677 if (!repo_add_solv(ref, ofp, 0))
1679 repo_add_rpmdb(repo, ref, 0, REPO_REUSE_REPODATA);
1686 repo_add_rpmdb(repo, 0, 0, REPO_REUSE_REPODATA);
1688 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1689 repo_add_debdb(repo, 0, REPO_REUSE_REPODATA);
1691 writecachedrepo(repo, 0, 0, installedcookie);
1693 pool_set_installed(pool, repo);
1695 for (i = 0; i < nrepoinfos; i++)
1697 cinfo = repoinfos + i;
1698 if (!cinfo->enabled)
1701 repo = repo_create(pool, cinfo->alias);
1703 repo->appdata = cinfo;
1704 repo->priority = 99 - cinfo->priority;
1706 dorefresh = cinfo->autorefresh;
1707 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0), &stb) == 0)
1709 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1712 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1714 printf("repo '%s':", cinfo->alias);
1715 printf(" cached\n");
1719 switch (cinfo->type)
1723 printf("rpmmd repo '%s':", cinfo->alias);
1725 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1727 printf(" no repomd.xml file, skipped\n");
1732 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1733 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1735 printf(" cached\n");
1739 if (cinfo->repo_gpgcheck)
1741 sigfp = curlfopen(cinfo, "repodata/repomd.xml.asc", 0, 0, 0, 0);
1744 printf(" unsigned, skipped\n");
1749 sigpool = read_sigs();
1750 if (!checksig(sigpool, fp, sigfp))
1752 printf(" checksig failed, skipped\n");
1759 repo_add_repomdxml(repo, fp, 0);
1761 printf(" fetching\n");
1762 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1763 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1765 repo_add_rpmmd(repo, fp, 0, 0);
1769 break; /* hopeless */
1771 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1772 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1774 repo_add_updateinfoxml(repo, fp, 0);
1778 data = repo_add_repodata(repo, 0);
1779 if (!repomd_add_ext(repo, data, "deltainfo"))
1780 repomd_add_ext(repo, data, "prestodelta");
1781 repomd_add_ext(repo, data, "filelists");
1782 repodata_internalize(data);
1784 writecachedrepo(repo, 0, 0, cinfo->cookie);
1785 repodata_create_stubs(repo_last_repodata(repo));
1789 #ifdef ENABLE_SUSEREPO
1791 printf("susetags repo '%s':", cinfo->alias);
1795 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1797 printf(" no content file, skipped\n");
1802 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1803 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1805 printf(" cached\n");
1809 if (cinfo->repo_gpgcheck)
1811 sigfp = curlfopen(cinfo, "content.asc", 0, 0, 0, 0);
1814 printf(" unsigned, skipped\n");
1821 sigpool = read_sigs();
1822 if (!checksig(sigpool, fp, sigfp))
1824 printf(" checksig failed, skipped\n");
1832 repo_add_content(repo, fp, 0);
1834 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1835 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1837 descrdir = "suse/setup/descr";
1838 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1840 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1843 printf(" no packages file entry, skipped\n");
1846 printf(" fetching\n");
1847 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) == 0)
1848 break; /* hopeless */
1849 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES);
1851 /* add default language */
1852 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1854 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1857 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1859 repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES);
1863 filename = susetags_find(repo, "patterns", &filechksum, &filechksumtype);
1866 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1869 while (fgets(pbuf, sizeof(pbuf), fp))
1871 int l = strlen(pbuf);
1873 if (l && pbuf[l - 1] == '\n')
1875 if (!*pbuf || *pbuf == '.' || strchr(pbuf, '/') != 0)
1877 filename = susetags_find(repo, pbuf, &filechksum, &filechksumtype);
1878 if (filename && (fp2 = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1880 repo_add_susetags(repo, fp2, defvendor, 0, REPO_NO_INTERNALIZE);
1887 repo_internalize(repo);
1888 data = repo_add_repodata(repo, 0);
1889 susetags_add_ext(repo, data);
1890 repodata_internalize(data);
1892 writecachedrepo(repo, 0, 0, cinfo->cookie);
1893 repodata_create_stubs(repo_last_repodata(repo));
1897 #if defined(ENABLE_DEBIAN)
1899 printf("debian repo '%s':", cinfo->alias);
1901 filename = solv_dupjoin("dists/", cinfo->name, "/Release");
1902 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
1904 printf(" no Release file, skipped\n");
1907 free((char *)filename);
1910 solv_free((char *)filename);
1911 if (cinfo->repo_gpgcheck)
1913 filename = solv_dupjoin("dists/", cinfo->name, "/Release.gpg");
1914 sigfp = curlfopen(cinfo, filename, 0, 0, 0, 0);
1915 solv_free((char *)filename);
1918 printf(" unsigned, skipped\n");
1923 sigpool = read_sigs();
1924 if (!checksig(sigpool, fpr, sigfp))
1926 printf(" checksig failed, skipped\n");
1933 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
1934 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1936 printf(" cached\n");
1940 printf(" fetching\n");
1941 for (j = 0; j < cinfo->ncomponents; j++)
1943 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
1945 printf("[component %s not found]\n", cinfo->components[j]);
1948 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1950 repo_add_debpackages(repo, fp, 0);
1953 solv_free((char *)filechksum);
1954 solv_free((char *)filename);
1958 writecachedrepo(repo, 0, 0, cinfo->cookie);
1963 printf("unsupported repo '%s': skipped\n", cinfo->alias);
1975 str2archid(Pool *pool, char *arch)
1980 id = pool_str2id(pool, arch, 0);
1981 if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH)
1983 if (pool->id2arch && (id > pool->lastarch || !pool->id2arch[id]))
1989 #define DEPGLOB_NAME 1
1990 #define DEPGLOB_DEP 2
1991 #define DEPGLOB_NAMEDEP 3
1994 depglob(Pool *pool, char *name, Queue *job, int what)
1997 Id id = pool_str2id(pool, name, 0);
2002 FOR_PROVIDES(p, pp, id)
2004 Solvable *s = pool->solvables + p;
2006 if (s->name == id && (what & DEPGLOB_NAME) != 0)
2008 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
2014 if (what == DEPGLOB_NAMEDEP)
2015 printf("[using capability match for '%s']\n", name);
2016 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
2021 if (strpbrk(name, "[*?") == 0)
2024 if ((what & DEPGLOB_NAME) != 0)
2026 /* looks like a name glob. hard work. */
2027 for (p = 1; p < pool->nsolvables; p++)
2029 Solvable *s = pool->solvables + p;
2030 if (!s->repo || !pool_installable(pool, s))
2033 if (fnmatch(name, pool_id2str(pool, id), 0) == 0)
2035 for (i = 0; i < job->count; i += 2)
2036 if (job->elements[i] == SOLVER_SOLVABLE_NAME && job->elements[i + 1] == id)
2038 if (i == job->count)
2039 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
2046 if ((what & DEPGLOB_DEP))
2048 /* looks like a dep glob. really hard work. */
2049 for (id = 1; id < pool->ss.nstrings; id++)
2051 if (!pool->whatprovides[id])
2053 if (fnmatch(name, pool_id2str(pool, id), 0) == 0)
2055 if (!match && what == DEPGLOB_NAMEDEP)
2056 printf("[using capability match for '%s']\n", name);
2057 for (i = 0; i < job->count; i += 2)
2058 if (job->elements[i] == SOLVER_SOLVABLE_PROVIDES && job->elements[i + 1] == id)
2060 if (i == job->count)
2061 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
2072 limitrelation(Pool *pool, Queue *job, int flags, Id evr)
2076 for (i = j = 0; i < job->count; i += 2)
2078 Id select = job->elements[i] & SOLVER_SELECTMASK;
2079 if (select != SOLVER_SOLVABLE_NAME && select != SOLVER_SOLVABLE_PROVIDES)
2081 fprintf(stderr, "limitrelation only works on name/provides jobs\n");
2084 job->elements[i + 1] = pool_rel2id(pool, job->elements[i + 1], evr, flags, 1);
2085 if (flags == REL_ARCH)
2086 job->elements[i] |= SOLVER_SETARCH;
2087 if (flags == REL_EQ && select == SOLVER_SOLVABLE_NAME && job->elements[i])
2090 const char *evrstr = pool_id2str(pool, evr);
2091 if (!strchr(evrstr, '-'))
2092 job->elements[i] |= SOLVER_SETEV;
2095 job->elements[i] |= SOLVER_SETEVR;
2097 /* make sure we still have matches */
2098 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2102 job->elements[j] = job->elements[i];
2103 job->elements[j + 1] = job->elements[i + 1];
2107 queue_truncate(job, j);
2112 limitrelation_arch(Pool *pool, Queue *job, int flags, char *evr)
2116 if ((r = strrchr(evr, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2119 limitrelation(pool, job, REL_ARCH, archid);
2120 limitrelation(pool, job, flags, pool_str2id(pool, evr, 1));
2124 limitrelation(pool, job, flags, pool_str2id(pool, evr, 1));
2125 return job->count / 2;
2129 limitrepo(Pool *pool, Id repofilter, Queue *job)
2137 for (i = j = 0; i < job->count; i += 2)
2140 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
2142 s = pool_id2solvable(pool, p);
2143 if (s->repo && s->repo->repoid == repofilter)
2148 /* here we assume that repo == vendor, so we also set SOLVER_SETVENDOR */
2149 Id flags = (job->elements[i] & SOLVER_SETMASK) | SOLVER_SETVENDOR | SOLVER_SETREPO;
2150 if ((job->elements[i] & SOLVER_SELECTMASK) == SOLVER_SOLVABLE_NAME)
2151 flags |= SOLVER_SETNAME;
2154 job->elements[j] = SOLVER_SOLVABLE | SOLVER_NOAUTOSET | flags;
2155 job->elements[j + 1] = mq.elements[0];
2159 job->elements[j] = SOLVER_SOLVABLE_ONE_OF | flags;
2160 job->elements[j + 1] = pool_queuetowhatprovides(pool, &mq);
2165 queue_truncate(job, j);
2171 mkselect(Pool *pool, int mode, char *name, Queue *job)
2179 int type = strpbrk(name, "[*?") == 0 ? SEARCH_STRING : SEARCH_GLOB;
2182 dataiterator_init(&di, pool, mode == SOLVER_ERASE ? pool->installed : 0, 0, SOLVABLE_FILELIST, name, type|SEARCH_FILES|SEARCH_COMPLETE_FILELIST);
2183 while (dataiterator_step(&di))
2185 Solvable *s = pool->solvables + di.solvid;
2186 if (!s->repo || !pool_installable(pool, s))
2188 queue_push(&q, di.solvid);
2189 dataiterator_skip_solvable(&di);
2191 dataiterator_free(&di);
2194 printf("[using file list match for '%s']\n", name);
2196 queue_push2(job, SOLVER_SOLVABLE_ONE_OF, pool_queuetowhatprovides(pool, &q));
2198 queue_push2(job, SOLVER_SOLVABLE | SOLVER_NOAUTOSET, q.elements[0]);
2200 return job->count / 2;
2203 if ((r = strpbrk(name, "<=>")) != 0)
2205 /* relation case, support:
2210 int nend = r - name;
2223 while (*r && *r == ' ' && *r == '\t')
2225 while (nend && (name[nend - 1] == ' ' || name[nend -1 ] == '\t'))
2229 fprintf(stderr, "bad relation\n");
2232 oldnend = name[nend];
2234 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2236 name[nend] = oldnend;
2237 limitrelation(pool, job, rflags, pool_str2id(pool, r, 1));
2238 return job->count / 2;
2240 if ((r2 = strrchr(name, '.')) != 0 && r2[1] && (archid = str2archid(pool, r2 + 1)) != 0)
2243 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2245 name[nend] = oldnend;
2247 limitrelation(pool, job, REL_ARCH, archid);
2248 limitrelation(pool, job, rflags, pool_str2id(pool, r, 1));
2249 return job->count / 2;
2253 name[nend] = oldnend;
2257 /* no relation case, support:
2261 * nameglob-version.arch
2262 * nameglob-version-release
2263 * nameglob-version-release.arch
2265 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2266 return job->count / 2;
2267 if ((r = strrchr(name, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
2270 if (depglob(pool, name, job, DEPGLOB_NAMEDEP))
2273 limitrelation(pool, job, REL_ARCH, archid);
2274 return job->count / 2;
2278 if ((r = strrchr(name, '-')) != 0)
2281 if (depglob(pool, name, job, DEPGLOB_NAME))
2283 /* have just the version */
2284 limitrelation_arch(pool, job, REL_EQ, r + 1);
2286 return job->count / 2;
2288 if ((r2 = strrchr(name, '-')) != 0)
2293 if (depglob(pool, name, job, DEPGLOB_NAME))
2295 /* have version-release */
2296 limitrelation_arch(pool, job, REL_EQ, r + 1);
2298 return job->count / 2;
2309 yesno(const char *str)
2311 char inbuf[128], *ip;
2318 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2323 while (*ip == ' ' || *ip == '\t')
2330 if (*ip == 'y' || *ip == 'n')
2331 return *ip == 'y' ? 1 : 0;
2335 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2345 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2347 struct fcstate *fcstate = cbdata;
2355 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
2358 s = pool_id2solvable(pool, p);
2359 if (pool->installed && s->repo == pool->installed)
2361 if (!s->repo->rpmdbid)
2363 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2366 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
2368 for (i = 0; i < fcstate->newpkgscnt; i++)
2369 if (fcstate->checkq->elements[i] == p)
2371 if (i == fcstate->newpkgscnt)
2373 fp = fcstate->newpkgsfps[i];
2377 return rpm_byfp(fp, pool_solvable2str(pool, s), &fcstate->rpmdbstate);
2382 runrpm(const char *arg, const char *name, int dupfd3)
2387 if ((pid = fork()) == (pid_t)-1)
2394 if (dupfd3 != -1 && dupfd3 != 3)
2400 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2401 if (strcmp(arg, "-e") == 0)
2402 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2404 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
2408 while (waitpid(pid, &status, 0) != pid)
2412 printf("rpm failed\n");
2419 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2422 rundpkg(const char *arg, const char *name, int dupfd3)
2427 if ((pid = fork()) == (pid_t)-1)
2434 if (dupfd3 != -1 && dupfd3 != 3)
2440 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2441 if (strcmp(arg, "--install") == 0)
2442 execlp("dpkg", "dpkg", "--install", "--force", "all", name, (char *)0);
2444 execlp("dpkg", "dpkg", "--remove", "--force", "all", name, (char *)0);
2448 while (waitpid(pid, &status, 0) != pid)
2452 printf("dpkg failed\n");
2460 nscallback(Pool *pool, void *data, Id name, Id evr)
2462 if (name == NAMESPACE_PRODUCTBUDDY)
2464 /* SUSE specific hack: each product has an associated rpm */
2465 Solvable *s = pool->solvables + evr;
2469 cap = pool_str2id(pool, pool_tmpjoin(pool, "product(", pool_id2str(pool, s->name) + 8, ")"), 0);
2472 cap = pool_rel2id(pool, cap, s->evr, REL_EQ, 0);
2475 FOR_PROVIDES(p, pp, cap)
2477 Solvable *ps = pool->solvables + p;
2478 if (ps->repo == s->repo && ps->arch == s->arch)
2479 if (!bestp || pool_evrcmp(pool, pool->solvables[bestp].evr, ps->evr, EVRCMP_COMPARE) < 0)
2487 #ifdef SOFTLOCKS_PATH
2490 addsoftlocks(Pool *pool, Queue *job)
2494 char *bp, *ep, buf[4096];
2496 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2498 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2500 while (*bp == ' ' || *bp == '\t')
2502 if (!*bp || *bp == '#')
2504 for (ep = bp; *ep; ep++)
2505 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2508 type = SOLVER_SOLVABLE_NAME;
2509 if (!strncmp(bp, "provides:", 9) && bp[9])
2511 type = SOLVER_SOLVABLE_PROVIDES;
2514 id = pool_str2id(pool, bp, 1);
2515 if (pool->installed)
2517 FOR_JOB_SELECT(p, pp, type, id)
2518 if (pool->solvables[p].repo == pool->installed)
2521 continue; /* ignore, as it is already installed */
2523 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2532 rewrite_repos(Pool *pool, Queue *addedfileprovides, Queue *addedfileprovides_inst)
2537 Queue fileprovidesq;
2539 struct repoinfo *cinfo;
2541 map_init(&providedids, pool->ss.nstrings);
2542 queue_init(&fileprovidesq);
2543 for (i = 0; i < addedfileprovides->count; i++)
2544 MAPSET(&providedids, addedfileprovides->elements[i]);
2547 /* make sure all repodatas but the first are extensions */
2548 if (repo->nrepodata < 2)
2550 data = repo_id2repodata(repo, 1);
2551 if (data->loadcallback)
2553 for (j = 2; j < repo->nrepodata; j++)
2555 Repodata *edata = repo_id2repodata(repo, j);
2556 if (!edata->loadcallback)
2559 if (j < repo->nrepodata)
2560 continue; /* found a non-externsion repodata, can't rewrite */
2561 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2563 if (repo == pool->installed && addedfileprovides_inst)
2565 for (j = 0; j < addedfileprovides->count; j++)
2566 MAPCLR(&providedids, addedfileprovides->elements[j]);
2567 for (j = 0; j < addedfileprovides_inst->count; j++)
2568 MAPSET(&providedids, addedfileprovides_inst->elements[j]);
2571 for (j = 0; j < fileprovidesq.count; j++)
2572 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2574 if (repo == pool->installed && addedfileprovides_inst)
2576 for (j = 0; j < addedfileprovides_inst->count; j++)
2577 MAPCLR(&providedids, addedfileprovides_inst->elements[j]);
2578 for (j = 0; j < addedfileprovides->count; j++)
2579 MAPSET(&providedids, addedfileprovides->elements[j]);
2580 if (n == addedfileprovides_inst->count)
2581 continue; /* nothing new added */
2583 else if (n == addedfileprovides->count)
2584 continue; /* nothing new added */
2586 repodata_set_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, repo == pool->installed && addedfileprovides_inst ? addedfileprovides_inst : addedfileprovides);
2587 repodata_internalize(data);
2588 cinfo = repo->appdata;
2589 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2591 queue_free(&fileprovidesq);
2592 map_free(&providedids);
2596 select_patches(Pool *pool, Queue *job)
2600 Map installedmap, noobsmap;
2603 map_init(&noobsmap, 0);
2604 map_init(&installedmap, pool->nsolvables);
2605 solver_calculate_noobsmap(pool, job, &noobsmap);
2606 if (pool->installed)
2607 FOR_REPO_SOLVABLES(pool->installed, p, s)
2608 MAPSET(&installedmap, p);
2610 /* install all patches */
2611 for (p = 1; p < pool->nsolvables; p++)
2617 s = pool->solvables + p;
2618 if (strncmp(pool_id2str(pool, s->name), "patch:", 6) != 0)
2620 FOR_PROVIDES(p2, pp, s->name)
2622 Solvable *s2 = pool->solvables + p2;
2623 if (s2->name != s->name)
2625 r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2626 if (r < 0 || (r == 0 && p > p2))
2631 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2632 if (type && !strcmp(type, "optional"))
2634 r = solvable_trivial_installable_map(s, &installedmap, 0, &noobsmap);
2637 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2644 queue_push2(job, SOLVER_SOLVABLE, p);
2646 map_free(&installedmap);
2647 map_free(&noobsmap);
2651 #define MODE_INSTALL 1
2652 #define MODE_ERASE 2
2653 #define MODE_UPDATE 3
2654 #define MODE_DISTUPGRADE 4
2655 #define MODE_VERIFY 5
2656 #define MODE_PATCH 6
2658 #define MODE_REPOLIST 8
2659 #define MODE_SEARCH 9
2664 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2665 fprintf(stderr, "\n");
2666 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2667 fprintf(stderr, " versions from the repositories\n");
2668 fprintf(stderr, " erase: erase installed packages\n");
2669 fprintf(stderr, " info: display package information\n");
2670 fprintf(stderr, " install: install packages\n");
2671 fprintf(stderr, " list: list packages\n");
2672 fprintf(stderr, " repos: list enabled repositories\n");
2673 fprintf(stderr, " search: search name/summary/description\n");
2674 fprintf(stderr, " update: update installed packages\n");
2675 fprintf(stderr, " verify: check dependencies of installed packages\n");
2676 fprintf(stderr, "\n");
2681 main(int argc, char **argv)
2684 Repo *commandlinerepo = 0;
2685 Id *commandlinepkgs = 0;
2687 struct repoinfo *repoinfos;
2689 int mainmode = 0, mode = 0;
2694 char inbuf[128], *ip;
2697 Queue addedfileprovides;
2698 Queue addedfileprovides_inst;
2706 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2708 mainmode = MODE_INSTALL;
2709 mode = SOLVER_INSTALL;
2711 else if (!strcmp(argv[0], "patch"))
2713 mainmode = MODE_PATCH;
2714 mode = SOLVER_INSTALL;
2716 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2718 mainmode = MODE_ERASE;
2719 mode = SOLVER_ERASE;
2721 else if (!strcmp(argv[0], "list"))
2723 mainmode = MODE_LIST;
2726 else if (!strcmp(argv[0], "info"))
2728 mainmode = MODE_INFO;
2731 else if (!strcmp(argv[0], "search"))
2733 mainmode = MODE_SEARCH;
2736 else if (!strcmp(argv[0], "verify"))
2738 mainmode = MODE_VERIFY;
2739 mode = SOLVER_VERIFY;
2741 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2743 mainmode = MODE_UPDATE;
2744 mode = SOLVER_UPDATE;
2746 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2748 mainmode = MODE_DISTUPGRADE;
2749 mode = SOLVER_UPDATE;
2751 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2753 mainmode = MODE_REPOLIST;
2759 if (argc > 1 && !strcmp(argv[1], "--clean"))
2766 pool = pool_create();
2770 const char *langs[] = {"de_DE", "de", "en"};
2771 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2775 pool_setloadcallback(pool, load_stub, 0);
2776 pool->nscallback = nscallback;
2777 // pool_setdebuglevel(pool, 2);
2779 repoinfos = read_repoinfos(pool, &nrepoinfos);
2781 if (mainmode == MODE_REPOLIST)
2784 for (i = 0; i < nrepoinfos; i++)
2786 struct repoinfo *cinfo = repoinfos + i;
2787 if (!cinfo->enabled)
2789 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2794 read_repos(pool, repoinfos, nrepoinfos);
2796 if (argc > 2 && !strcmp(argv[1], "-r"))
2798 const char *rname = argv[2], *rp;
2799 for (rp = rname; *rp; rp++)
2800 if (*rp <= '0' || *rp >= '9')
2804 /* repo specified by number */
2805 int rnum = atoi(rname);
2806 for (i = 0; i < nrepoinfos; i++)
2808 struct repoinfo *cinfo = repoinfos + i;
2809 if (!cinfo->enabled)
2812 repofilter = cinfo->repo->repoid;
2817 /* repo specified by alias */
2821 if (!strcasecmp(rname, repo->name))
2822 repofilter = repo->repoid;
2827 fprintf(stderr, "%s: no such repo\n", rname);
2833 if (mainmode == MODE_SEARCH)
2839 map_init(&m, pool->nsolvables);
2840 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2841 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2842 dataiterator_set_search(&di, 0, 0);
2843 while (dataiterator_step(&di))
2844 MAPSET(&m, di.solvid);
2845 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2846 dataiterator_set_search(&di, 0, 0);
2847 while (dataiterator_step(&di))
2848 MAPSET(&m, di.solvid);
2849 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2850 dataiterator_set_search(&di, 0, 0);
2851 while (dataiterator_step(&di))
2852 MAPSET(&m, di.solvid);
2853 dataiterator_free(&di);
2855 for (p = 1; p < pool->nsolvables; p++)
2857 Solvable *s = pool_id2solvable(pool, p);
2860 printf(" - %s: %s\n", pool_solvable2str(pool, s), solvable_lookup_str(s, SOLVABLE_SUMMARY));
2867 if (mainmode == MODE_LIST || mainmode == MODE_INSTALL)
2869 for (i = 1; i < argc; i++)
2872 l = strlen(argv[i]);
2873 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2874 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2877 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2878 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2881 if (access(argv[i], R_OK))
2886 if (!commandlinepkgs)
2887 commandlinepkgs = solv_calloc(argc, sizeof(Id));
2888 if (!commandlinerepo)
2889 commandlinerepo = repo_create(pool, "@commandline");
2891 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2892 p = repo_add_rpm(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2894 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2895 p = repo_add_deb(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2899 fprintf(stderr, "could not add '%s'\n", argv[i]);
2902 commandlinepkgs[i] = p;
2904 if (commandlinerepo)
2905 repo_internalize(commandlinerepo);
2908 // FOR_REPOS(i, repo)
2909 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2910 queue_init(&addedfileprovides);
2911 queue_init(&addedfileprovides_inst);
2912 pool_addfileprovides_queue(pool, &addedfileprovides, &addedfileprovides_inst);
2913 if (addedfileprovides.count || addedfileprovides_inst.count)
2914 rewrite_repos(pool, &addedfileprovides, &addedfileprovides_inst);
2915 queue_free(&addedfileprovides);
2916 queue_free(&addedfileprovides_inst);
2917 pool_createwhatprovides(pool);
2920 for (i = 1; i < argc; i++)
2925 if (commandlinepkgs && commandlinepkgs[i])
2927 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2931 if (!mkselect(pool, mode, argv[i], &job2))
2933 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2936 if (repofilter && !limitrepo(pool, repofilter, &job2))
2938 fprintf(stderr, "nothing in repo matches '%s'\n", argv[i]);
2941 for (j = 0; j < job2.count; j++)
2942 queue_push(&job, job2.elements[j]);
2946 if (!job.count && mainmode != MODE_UPDATE && mainmode != MODE_DISTUPGRADE && mainmode != MODE_VERIFY && mainmode != MODE_PATCH)
2948 printf("no package matched\n");
2955 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
2957 /* list mode, no solver needed */
2958 for (i = 0; i < job.count; i += 2)
2960 Id how = job.elements[i] & SOLVER_SELECTMASK;
2961 FOR_JOB_SELECT(p, pp, how, job.elements[i + 1])
2963 Solvable *s = pool_id2solvable(pool, p);
2964 if (mainmode == MODE_INFO)
2967 printf("Name: %s\n", pool_solvable2str(pool, s));
2968 printf("Repo: %s\n", s->repo->name);
2969 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
2970 str = solvable_lookup_str(s, SOLVABLE_URL);
2972 printf("Url: %s\n", str);
2973 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
2975 printf("License: %s\n", str);
2976 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
2982 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
2984 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
2986 printf(" - %s [%s]\n", pool_solvable2str(pool, s), s->repo->name);
2988 printf(" %s\n", sum);
2994 free_repoinfos(repoinfos, nrepoinfos);
2995 solv_free(commandlinepkgs);
2997 yum_substitute(pool, 0);
3002 if (mainmode == MODE_PATCH)
3003 select_patches(pool, &job);
3006 for (i = 0; i < job.count; i += 2)
3008 if (mode == SOLVER_UPDATE)
3010 /* make update of not installed packages an install */
3011 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
3012 if (pool->installed && pool->solvables[p].repo == pool->installed)
3016 job.elements[i] |= SOLVER_INSTALL;
3018 job.elements[i] |= SOLVER_CLEANDEPS;
3022 job.elements[i] |= mode;
3024 job.elements[i] |= SOLVER_CLEANDEPS;
3027 if (mainmode == MODE_DISTUPGRADE && allpkgs)
3030 queue_push2(&job, SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_REPO, repofilter);
3032 queue_push2(&job, SOLVER_DISTUPGRADE|SOLVER_SOLVABLE_ALL, 0);
3034 if (mainmode == MODE_UPDATE && allpkgs)
3037 queue_push2(&job, SOLVER_UPDATE|SOLVER_SOLVABLE_REPO, repofilter);
3039 queue_push2(&job, SOLVER_UPDATE|SOLVER_SOLVABLE_ALL, 0);
3041 if (mainmode == MODE_VERIFY && allpkgs)
3044 queue_push2(&job, SOLVER_VERIFY|SOLVER_SOLVABLE_REPO, repofilter);
3046 queue_push2(&job, SOLVER_VERIFY|SOLVER_SOLVABLE_ALL, 0);
3049 // multiversion test
3050 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae", 1));
3051 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-base", 1));
3052 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-extra", 1));
3054 #ifdef SOFTLOCKS_PATH
3055 addsoftlocks(pool, &job);
3058 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3063 Id problem, solution;
3066 solv = solver_create(pool);
3067 solver_set_flag(solv, SOLVER_FLAG_SPLITPROVIDES, 1);
3068 if (mainmode == MODE_ERASE)
3069 solver_set_flag(solv, SOLVER_FLAG_ALLOW_UNINSTALL, 1); /* don't nag */
3071 if (!solver_solve(solv, &job))
3073 pcnt = solver_problem_count(solv);
3074 printf("Found %d problems:\n", pcnt);
3075 for (problem = 1; problem <= pcnt; problem++)
3078 printf("Problem %d:\n", problem);
3079 solver_printprobleminfo(solv, problem);
3081 scnt = solver_solution_count(solv, problem);
3082 for (solution = 1; solution <= scnt; solution++)
3084 printf("Solution %d:\n", solution);
3085 solver_printsolution(solv, problem, solution);
3090 printf("Please choose a solution: ");
3093 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
3098 while (*ip == ' ' || *ip == '\t')
3100 if (*ip >= '0' && *ip <= '9')
3103 if (take >= 1 && take <= scnt)
3119 solver_take_solution(solv, problem, take, &job);
3125 trans = solver_create_transaction(solv);
3126 if (!trans->steps.count)
3128 printf("Nothing to do.\n");
3129 transaction_free(trans);
3133 free_repoinfos(repoinfos, nrepoinfos);
3134 solv_free(commandlinepkgs);
3136 yum_substitute(pool, 0);
3141 printf("Transaction summary:\n\n");
3142 transaction_print(trans);
3151 duc[1].path = "/usr/share/man";
3152 duc[2].path = "/sbin";
3153 duc[3].path = "/etc";
3154 transaction_calc_duchanges(trans, duc, 4);
3155 for (i = 0; i < 4; i++)
3156 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
3159 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
3162 if (!yesno("OK to continue (y/n)? "))
3165 transaction_free(trans);
3169 free_repoinfos(repoinfos, nrepoinfos);
3170 solv_free(commandlinepkgs);
3172 yum_substitute(pool, 0);
3177 queue_init(&checkq);
3178 newpkgs = transaction_installedresult(trans, &checkq);
3183 int downloadsize = 0;
3184 for (i = 0; i < newpkgs; i++)
3188 p = checkq.elements[i];
3189 s = pool_id2solvable(pool, p);
3190 downloadsize += solvable_lookup_sizek(s, SOLVABLE_DOWNLOADSIZE, 0);
3192 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
3193 newpkgsfps = solv_calloc(newpkgs, sizeof(*newpkgsfps));
3194 for (i = 0; i < newpkgs; i++)
3196 unsigned int medianr;
3199 struct repoinfo *cinfo;
3200 const unsigned char *chksum;
3204 p = checkq.elements[i];
3205 s = pool_id2solvable(pool, p);
3206 if (s->repo == commandlinerepo)
3208 loc = solvable_get_location(s, &medianr);
3209 if (!(newpkgsfps[i] = fopen(loc, "r")))
3217 cinfo = s->repo->appdata;
3220 printf("%s: no repository information\n", s->repo->name);
3223 loc = solvable_get_location(s, &medianr);
3227 if (pool->installed && pool->installed->nsolvables)
3229 /* try a delta first */
3230 char *matchname = strdup(pool_id2str(pool, s->name));
3231 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
3232 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
3233 while (dataiterator_step(&di))
3237 dataiterator_setpos_parent(&di);
3238 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
3239 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
3241 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
3242 FOR_PROVIDES(op, pp, s->name)
3244 Solvable *os = pool->solvables + op;
3245 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
3248 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
3250 /* base is installed, run sequence check */
3251 const char *seqname;
3256 const char *archstr;
3261 archstr = pool_id2str(pool, s->arch);
3262 if (strlen(archstr) > 10 || strchr(archstr, '\'') != 0)
3265 seqname = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME);
3266 seqevr = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR);
3267 seqnum = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM);
3268 seq = pool_tmpjoin(pool, seqname, "-", seqevr);
3269 seq = pool_tmpappend(pool, seq, "-", seqnum);
3270 if (strchr(seq, '\'') != 0)
3273 sprintf(cmd, "/usr/bin/applydeltarpm -a '%s' -c -s '", archstr);
3275 sprintf(cmd, "/usr/bin/applydeltarpm -c -s '");
3277 if (system(pool_tmpjoin(pool, cmd, seq, "'")) != 0)
3278 continue; /* didn't match */
3279 /* looks good, download delta */
3281 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
3283 continue; /* no way! */
3284 dloc = pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_DIR);
3285 dloc = pool_tmpappend(pool, dloc, "/", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_NAME));
3286 dloc = pool_tmpappend(pool, dloc, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_EVR));
3287 dloc = pool_tmpappend(pool, dloc, ".", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_SUFFIX));
3288 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
3290 /* got it, now reconstruct */
3291 newfd = opentmpfile();
3293 sprintf(cmd, "applydeltarpm -a '%s' /dev/fd/%d /dev/fd/%d", archstr, fileno(fp), newfd);
3295 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
3297 fcntl(fileno(fp), F_SETFD, 0);
3304 lseek(newfd, 0, SEEK_SET);
3306 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3307 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
3313 newpkgsfps[i] = fdopen(newfd, "r");
3318 dataiterator_free(&di);
3319 solv_free(matchname);
3326 continue; /* delta worked! */
3328 if (cinfo->type == TYPE_SUSETAGS)
3330 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3331 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3334 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3335 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3337 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3346 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3350 struct fcstate fcstate;
3352 printf("Searching for file conflicts\n");
3353 queue_init(&conflicts);
3354 fcstate.rpmdbstate = 0;
3355 fcstate.newpkgscnt = newpkgs;
3356 fcstate.checkq = &checkq;
3357 fcstate.newpkgsfps = newpkgsfps;
3358 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fileconflict_cb, &fcstate);
3359 if (conflicts.count)
3362 for (i = 0; i < conflicts.count; i += 5)
3363 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]));
3365 if (yesno("Re-run solver (y/n/q)? "))
3367 for (i = 0; i < newpkgs; i++)
3369 fclose(newpkgsfps[i]);
3370 newpkgsfps = solv_free(newpkgsfps);
3372 pool_add_fileconflicts_deps(pool, &conflicts);
3373 pool_createwhatprovides(pool); /* Hmm... */
3377 queue_free(&conflicts);
3381 printf("Committing transaction:\n\n");
3382 transaction_order(trans, 0);
3383 for (i = 0; i < trans->steps.count; i++)
3385 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3386 const char *evr, *evrp, *nvra;
3392 p = trans->steps.elements[i];
3393 s = pool_id2solvable(pool, p);
3394 Id type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3397 case SOLVER_TRANSACTION_ERASE:
3398 printf("erase %s\n", pool_solvid2str(pool, p));
3399 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3400 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3402 /* strip epoch from evr */
3403 evr = evrp = pool_id2str(pool, s->evr);
3404 while (*evrp >= '0' && *evrp <= '9')
3406 if (evrp > evr && evrp[0] == ':' && evrp[1])
3408 nvra = pool_tmpjoin(pool, pool_id2str(pool, s->name), "-", evr);
3409 nvra = pool_tmpappend(pool, nvra, ".", pool_id2str(pool, s->arch));
3410 runrpm("-e", nvra, -1); /* too bad that --querybynumber doesn't work */
3412 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3413 rundpkg("--remove", pool_id2str(pool, s->name), 0);
3416 case SOLVER_TRANSACTION_INSTALL:
3417 case SOLVER_TRANSACTION_MULTIINSTALL:
3418 printf("install %s\n", pool_solvid2str(pool, p));
3419 for (j = 0; j < newpkgs; j++)
3420 if (checkq.elements[j] == p)
3422 fp = j < newpkgs ? newpkgsfps[j] : 0;
3426 lseek(fileno(fp), 0, SEEK_SET);
3427 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3428 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp));
3430 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3431 rundpkg("--install", "/dev/fd/3", fileno(fp));
3441 for (i = 0; i < newpkgs; i++)
3443 fclose(newpkgsfps[i]);
3444 solv_free(newpkgsfps);
3445 queue_free(&checkq);
3446 transaction_free(trans);
3450 free_repoinfos(repoinfos, nrepoinfos);
3451 solv_free(commandlinepkgs);
3453 yum_substitute(pool, 0);