2 * Copyright (c) 2009-2013, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
8 /* solv, a little software installer demoing the sat solver library */
11 * - understands globs for package names / dependencies
12 * - understands .arch suffix
13 * - installation of commandline packages
14 * - repository data caching
15 * - on demand loading of secondary repository data
16 * - gpg and checksum verification
19 * - fastestmirror implementation
21 * things available in the library but missing from solv:
22 * - vendor policy loading
23 * - soft locks file handling
24 * - multi version handling
37 #include <sys/utsname.h>
38 #include <sys/types.h>
45 #include <sys/socket.h>
57 #include "solverdebug.h"
59 #include "repo_solv.h"
60 #include "selection.h"
62 #include "repo_write.h"
64 #include "repo_rpmdb.h"
65 #include "pool_fileconflicts.h"
68 #include "repo_pubkey.h"
74 #include "repo_rpmmd.h"
75 #include "repo_repomdxml.h"
76 #include "repo_updateinfoxml.h"
77 #include "repo_deltainfoxml.h"
80 #include "repo_appdata.h"
82 #ifdef ENABLE_SUSEREPO
83 #include "repo_products.h"
84 #include "repo_susetags.h"
85 #include "repo_content.h"
87 #include "solv_xfopen.h"
90 # define REPOINFO_PATH "/etc/yum.repos.d"
93 # define REPOINFO_PATH "/etc/zypp/repos.d"
94 # define PRODUCTS_PATH "/etc/products.d"
95 # define SOFTLOCKS_PATH "/var/lib/zypp/SoftLocks"
98 # define APPDATA_PATH "/usr/share/appdata"
101 #define SOLVCACHE_PATH "/var/cache/solv"
103 #define METADATA_EXPIRE (60 * 15)
125 unsigned char cookie[32];
126 unsigned char extcookie[32];
132 yum_substitute(Pool *pool, char *line)
135 static char *releaseevr;
136 static char *basearch;
140 solv_free(releaseevr);
147 while ((p2 = strchr(p, '$')) != 0)
149 if (!strncmp(p2, "$releasever", 11))
157 rpmstate = rpm_state_create(pool, pool_get_rootdir(pool));
158 rpm_installedrpmdbids(rpmstate, "Providename", "redhat-release", &q);
163 handle = rpm_byrpmdbid(rpmstate, q.elements[0]);
164 releaseevr = handle ? rpm_query(handle, SOLVABLE_EVR) : 0;
165 if (releaseevr && (p = strchr(releaseevr, '-')) != 0)
168 rpm_state_free(rpmstate);
172 fprintf(stderr, "no installed package provides 'redhat-release', cannot determine $releasever\n");
177 p = pool_tmpjoin(pool, line, releaseevr, p2 + 11);
178 p2 = p + (p2 - line);
180 p = p2 + strlen(releaseevr);
183 if (!strncmp(p2, "$basearch", 9))
193 basearch = strdup(un.machine);
194 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
198 p = pool_tmpjoin(pool, line, basearch, p2 + 9);
199 p2 = p + (p2 - line);
201 p = p2 + strlen(basearch);
210 #define TYPE_UNKNOWN 0
211 #define TYPE_SUSETAGS 1
213 #define TYPE_PLAINDIR 3
214 #define TYPE_DEBIAN 4
218 read_repoinfos_sort(const void *ap, const void *bp)
220 const struct repoinfo *a = ap;
221 const struct repoinfo *b = bp;
222 return strcmp(a->alias, b->alias);
226 #if defined(SUSE) || defined(FEDORA)
229 read_repoinfos(Pool *pool, int *nrepoinfosp)
231 const char *reposdir = REPOINFO_PATH;
233 char buf2[4096], *kp, *vp, *kpe;
238 struct repoinfo *repoinfos = 0, *cinfo;
241 rdlen = strlen(reposdir);
242 dir = opendir(reposdir);
248 while ((ent = readdir(dir)) != 0)
250 if (ent->d_name[0] == '.')
252 l = strlen(ent->d_name);
253 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
255 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
256 if ((fp = fopen(buf, "r")) == 0)
262 while(fgets(buf2, sizeof(buf2), fp))
267 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
270 while (*kp == ' ' || *kp == '\t')
272 if (!*kp || *kp == '#')
276 kp = yum_substitute(pool, kp);
280 vp = strrchr(kp, ']');
284 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
285 cinfo = repoinfos + nrepoinfos++;
286 memset(cinfo, 0, sizeof(*cinfo));
287 cinfo->alias = strdup(kp + 1);
288 cinfo->type = TYPE_RPMMD;
289 cinfo->autorefresh = 1;
290 cinfo->priority = 99;
292 cinfo->repo_gpgcheck = 1;
294 cinfo->metadata_expire = METADATA_EXPIRE;
299 vp = strchr(kp, '=');
302 for (kpe = vp - 1; kpe >= kp; kpe--)
303 if (*kpe != ' ' && *kpe != '\t')
308 while (*vp == ' ' || *vp == '\t')
311 if (!strcmp(kp, "name"))
312 cinfo->name = strdup(vp);
313 else if (!strcmp(kp, "enabled"))
314 cinfo->enabled = *vp == '0' ? 0 : 1;
315 else if (!strcmp(kp, "autorefresh"))
316 cinfo->autorefresh = *vp == '0' ? 0 : 1;
317 else if (!strcmp(kp, "gpgcheck"))
318 cinfo->pkgs_gpgcheck = *vp == '0' ? 0 : 1;
319 else if (!strcmp(kp, "repo_gpgcheck"))
320 cinfo->repo_gpgcheck = *vp == '0' ? 0 : 1;
321 else if (!strcmp(kp, "baseurl"))
322 cinfo->baseurl = strdup(vp);
323 else if (!strcmp(kp, "mirrorlist"))
325 if (strstr(vp, "metalink"))
326 cinfo->metalink = strdup(vp);
328 cinfo->mirrorlist = strdup(vp);
330 else if (!strcmp(kp, "path"))
332 if (vp && strcmp(vp, "/") != 0)
333 cinfo->path = strdup(vp);
335 else if (!strcmp(kp, "type"))
337 if (!strcmp(vp, "yast2"))
338 cinfo->type = TYPE_SUSETAGS;
339 else if (!strcmp(vp, "rpm-md"))
340 cinfo->type = TYPE_RPMMD;
341 else if (!strcmp(vp, "plaindir"))
342 cinfo->type = TYPE_PLAINDIR;
344 cinfo->type = TYPE_UNKNOWN;
346 else if (!strcmp(kp, "priority"))
347 cinfo->priority = atoi(vp);
348 else if (!strcmp(kp, "keeppackages"))
349 cinfo->keeppackages = *vp == '0' ? 0 : 1;
355 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
356 *nrepoinfosp = nrepoinfos;
365 read_repoinfos(Pool *pool, int *nrepoinfosp)
371 char *kp, *url, *distro;
372 struct repoinfo *repoinfos = 0, *cinfo;
377 fp = fopen("/etc/apt/sources.list", "r");
384 dir = opendir("/etc/apt/sources.list.d");
388 if ((ent = readdir(dir)) == 0)
393 if (ent->d_name[0] == '.')
395 l = strlen(ent->d_name);
396 if (l < 5 || strcmp(ent->d_name + l - 5, ".list") != 0)
398 snprintf(buf, sizeof(buf), "%s/%s", "/etc/apt/sources.list.d", ent->d_name);
399 if (!(fp = fopen(buf, "r")))
402 while(fgets(buf2, sizeof(buf2), fp))
407 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
410 while (*kp == ' ' || *kp == '\t')
412 if (!*kp || *kp == '#')
414 if (strncmp(kp, "deb", 3) != 0)
417 if (*kp != ' ' && *kp != '\t')
419 while (*kp == ' ' || *kp == '\t')
424 while (*kp && *kp != ' ' && *kp != '\t')
428 while (*kp == ' ' || *kp == '\t')
433 while (*kp && *kp != ' ' && *kp != '\t')
437 while (*kp == ' ' || *kp == '\t')
441 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
442 cinfo = repoinfos + nrepoinfos++;
443 memset(cinfo, 0, sizeof(*cinfo));
444 cinfo->baseurl = strdup(url);
445 cinfo->alias = solv_dupjoin(url, "/", distro);
446 cinfo->name = strdup(distro);
447 cinfo->type = TYPE_DEBIAN;
449 cinfo->autorefresh = 1;
450 cinfo->repo_gpgcheck = 1;
451 cinfo->metadata_expire = METADATA_EXPIRE;
455 while (*kp == ' ' || *kp == '\t')
460 while (*kp && *kp != ' ' && *kp != '\t')
464 cinfo->components = solv_extend(cinfo->components, cinfo->ncomponents, 1, sizeof(*cinfo->components), 15);
465 cinfo->components[cinfo->ncomponents++] = strdup(compo);
471 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
472 *nrepoinfosp = nrepoinfos;
480 read_repoinfos(Pool *pool, int *nrepoinfosp)
489 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
492 for (i = 0; i < nrepoinfos; i++)
494 struct repoinfo *cinfo = repoinfos + i;
495 solv_free(cinfo->name);
496 solv_free(cinfo->alias);
497 solv_free(cinfo->path);
498 solv_free(cinfo->metalink);
499 solv_free(cinfo->mirrorlist);
500 solv_free(cinfo->baseurl);
501 for (j = 0; j < cinfo->ncomponents; j++)
502 solv_free(cinfo->components[j]);
503 solv_free(cinfo->components);
505 solv_free(repoinfos);
514 strcpy(tmpl, "/var/tmp/solvXXXXXX");
526 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
529 const unsigned char *sum;
533 h = solv_chksum_create(chksumtype);
536 printf("%s: unknown checksum type\n", file);
539 while ((l = read(fd, buf, sizeof(buf))) > 0)
540 solv_chksum_add(h, buf, l);
541 lseek(fd, 0, SEEK_SET);
543 sum = solv_chksum_get(h, &l);
544 if (memcmp(sum, chksum, l))
546 printf("%s: checksum mismatch\n", file);
547 solv_chksum_free(h, 0);
550 solv_chksum_free(h, 0);
555 findfastest(char **urls, int nurls)
562 struct addrinfo hints, *result;;
564 fds = solv_calloc(nurls, sizeof(*fds));
565 socks = solv_calloc(nurls, sizeof(*socks));
566 for (i = 0; i < nurls; i++)
569 p = strchr(urls[i], '/');
582 if ((p2 = strchr(p, '@')) != 0)
585 if (!strncmp("https:", urls[i], 6))
587 else if (!strncmp("ftp:", urls[i], 4))
589 if ((p2 = strrchr(p, ':')) != 0)
598 sprintf(portstr, "%d", port);
599 memset(&hints, 0, sizeof(struct addrinfo));
600 hints.ai_family = AF_UNSPEC;
601 hints.ai_socktype = SOCK_STREAM;
602 hints.ai_flags = AI_NUMERICSERV;
604 if (!getaddrinfo(p, portstr, &hints, &result))
606 socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
609 fcntl(socks[i], F_SETFL, O_NONBLOCK);
610 if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1)
612 if (errno != EINPROGRESS)
619 freeaddrinfo(result);
626 for (i = j = 0; i < nurls; i++)
630 fds[j].fd = socks[i];
631 fds[j].events = POLLOUT;
639 if (poll(fds, j, 10000) <= 0)
641 i = -1; /* something is wrong */
644 for (i = 0; i < j; i++)
645 if ((fds[i].revents & POLLOUT) != 0)
648 socklen_t soel = sizeof(int);
649 if (getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, &soe, &soel) == -1 || soe != 0)
651 /* connect failed, kill socket */
652 for (j = 0; j < nurls; j++)
653 if (socks[j] == fds[i].fd)
666 i = -1; /* something is wrong, no bit was set */
669 /* now i contains the fastest fd index */
672 for (j = 0; j < nurls; j++)
673 if (socks[j] == fds[i].fd)
677 char *url0 = urls[0];
682 for (i = j = 0; i < nurls; i++)
690 findmetalinkurl(FILE *fp, unsigned char *chksump, Id *chksumtypep)
692 char buf[4096], *bp, *ep;
699 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
701 while (*bp == ' ' || *bp == '\t')
703 if (chksumtypep && !*chksumtypep && !strncmp(bp, "<hash type=\"sha256\">", 20))
706 if (solv_hex2bin((const char **)&bp, chksump, 32) == 32)
707 *chksumtypep = REPOKEY_TYPE_SHA256;
710 if (strncmp(bp, "<url", 4))
712 bp = strchr(bp, '>');
716 ep = strstr(bp, "repodata/repomd.xml</url>");
720 if (strncmp(bp, "http", 4))
722 urls = solv_extend(urls, nurls, 1, sizeof(*urls), 15);
723 urls[nurls++] = strdup(bp);
728 findfastest(urls, nurls > 5 ? 5 : nurls);
731 for (i = 0; i < nurls; i++)
734 ep = strchr(bp, '/');
735 if ((ep = strchr(ep + 2, '/')) != 0)
738 printf("[using mirror %s]\n", bp);
747 findmirrorlisturl(FILE *fp)
749 char buf[4096], *bp, *ep;
754 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
756 while (*bp == ' ' || *bp == '\t')
758 if (!*bp || *bp == '#')
761 while (l > 0 && (bp[l - 1] == ' ' || bp[l - 1] == '\t' || bp[l - 1] == '\n'))
763 urls = solv_extend(urls, nurls, 1, sizeof(*urls), 15);
764 urls[nurls++] = strdup(bp);
769 findfastest(urls, nurls > 5 ? 5 : nurls);
772 for (i = 0; i < nurls; i++)
775 ep = strchr(bp, '/');
776 if ((ep = strchr(ep + 2, '/')) != 0)
779 printf("[using mirror %s]\n", bp);
788 iscompressed(const char *name)
790 return solv_xfopen_iscompressed(name) != 0;
794 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int markincomplete)
801 const char *baseurl = cinfo->baseurl;
805 if (!cinfo->metalink && !cinfo->mirrorlist)
807 if (file != cinfo->metalink && file != cinfo->mirrorlist)
809 unsigned char mlchksum[32];
811 fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
816 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
818 cinfo->baseurl = findmirrorlisturl(fp);
823 if (strchr(cinfo->baseurl, '$'))
825 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
826 free(cinfo->baseurl);
827 cinfo->baseurl = strdup(b);
830 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
832 chksumtype = mlchksumtype;
835 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, markincomplete);
837 snprintf(url, sizeof(url), "%s", file);
842 if (l && baseurl[l - 1] == '/')
843 snprintf(url, sizeof(url), "%s%s", baseurl, file);
845 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
848 // printf("url: %s\n", url);
849 if ((pid = fork()) == (pid_t)-1)
861 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
866 while (waitpid(pid, &status, 0) != pid)
868 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
874 lseek(fd, 0, SEEK_SET);
877 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
879 cinfo->incomplete = 1;
883 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
886 cinfo->incomplete = 1;
890 fcntl(fd, F_SETFD, FD_CLOEXEC);
893 if (solv_xfopen_iscompressed(file) < 0)
895 printf("%s: unsupported compression\n", file);
897 cinfo->incomplete = 1;
901 fp = solv_xfopen_fd(file, fd, "r");
904 fp = fdopen(fd, "r");
913 cleanupgpg(char *gpgdir)
916 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
918 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
920 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
922 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
924 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
930 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
939 off_t posfp, possigfp;
942 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
945 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
946 if (!(kfp = fopen(keysfile, "w")) )
952 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
956 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
957 if (!pubkey || !*pubkey)
959 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
961 if (fputc('\n', kfp) == EOF) /* Just in case... */
965 if (fclose(kfp) || !nkeys)
970 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
973 fprintf(stderr, "key import error\n");
978 posfp = lseek(fileno(fp), 0, SEEK_CUR);
979 lseek(fileno(fp), 0, SEEK_SET);
980 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
981 lseek(fileno(sigfp), 0, SEEK_SET);
982 snprintf(cmd, sizeof(cmd), "gpgv -q --homedir %s --keyring %s/pubring.gpg /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, gpgdir, fileno(sigfp), fileno(fp));
983 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
984 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
986 lseek(fileno(sigfp), possigfp, SEEK_SET);
987 lseek(fileno(fp), posfp, SEEK_SET);
988 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
989 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
991 return r == 0 ? 1 : 0;
997 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
1002 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));
1003 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
1004 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
1006 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
1007 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
1008 return r == 0 ? 1 : 0;
1016 Pool *sigpool = pool_create();
1017 #if defined(ENABLE_PUBKEY) && defined(ENABLE_RPMDB)
1018 Repo *repo = repo_create(sigpool, "pubkeys");
1019 repo_add_rpmdb_pubkeys(repo, 0);
1025 downloadchecksig(struct repoinfo *cinfo, FILE *fp, const char *sigurl, Pool **sigpool)
1028 sigfp = curlfopen(cinfo, sigurl, 0, 0, 0, 0);
1031 printf(" unsigned, skipped\n");
1035 *sigpool = read_sigs();
1036 if (!checksig(*sigpool, fp, sigfp))
1038 printf(" checksig failed, skipped\n");
1046 #define CHKSUM_IDENT "1.1"
1049 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
1052 void *h = solv_chksum_create(chktype);
1055 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1056 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
1057 solv_chksum_add(h, buf, l);
1059 solv_chksum_free(h, out);
1063 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *cookie, unsigned char *out)
1065 void *h = solv_chksum_create(chktype);
1066 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1068 solv_chksum_add(h, cookie, 32);
1069 solv_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
1070 solv_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
1071 solv_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
1072 solv_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
1073 solv_chksum_free(h, out);
1085 pool_setarch(pool, un.machine);
1091 calccachepath(Repo *repo, const char *repoext, int forcesystemloc)
1095 if (!forcesystemloc && userhome && getuid())
1096 p = pool_tmpjoin(repo->pool, userhome, "/.solvcache/", 0);
1098 p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", 0);
1100 p = pool_tmpappend(repo->pool, p, repo->name, 0);
1103 p = pool_tmpappend(repo->pool, p, "_", repoext);
1104 p = pool_tmpappend(repo->pool, p, ".solvx", 0);
1107 p = pool_tmpappend(repo->pool, p, ".solv", 0);
1118 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1121 unsigned char mycookie[32];
1122 unsigned char myextcookie[32];
1123 struct repoinfo *cinfo;
1127 forcesystemloc = mark & 2 ? 0 : 1;
1128 if (mark < 2 && userhome && getuid())
1130 /* first try home location */
1131 int res = usecachedrepo(repo, repoext, cookie, mark | 2);
1136 cinfo = repo->appdata;
1137 if (!(fp = fopen(calccachepath(repo, repoext, forcesystemloc), "r")))
1139 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1144 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1149 if (cinfo && !repoext)
1151 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1162 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1163 if (strcmp(repoext, "DL") != 0)
1164 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1167 if (repo_add_solv(repo, fp, flags))
1172 if (cinfo && !repoext)
1174 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1175 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1178 futimens(fileno(fp), 0); /* try to set modification time */
1184 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1188 char *tmpl, *cachedir;
1189 struct repoinfo *cinfo;
1192 cinfo = repo->appdata;
1193 if (cinfo && cinfo->incomplete)
1195 cachedir = userhome && getuid() ? pool_tmpjoin(repo->pool, userhome, "/.solvcache", 0) : SOLVCACHE_PATH;
1196 if (access(cachedir, W_OK | X_OK) != 0 && mkdir(cachedir, 0755) == 0)
1197 printf("[created %s]\n", cachedir);
1198 /* use dupjoin instead of tmpjoin because tmpl must survive repo_write */
1199 tmpl = solv_dupjoin(cachedir, "/", ".newsolv-XXXXXX");
1207 if (!(fp = fdopen(fd, "w")))
1216 for (i = repo->start; i < repo->end; i++)
1217 if (repo->pool->solvables[i].repo != repo)
1223 repo_write(repo, fp);
1225 repodata_write(info, fp);
1228 int oldnrepodata = repo->nrepodata;
1229 repo->nrepodata = oldnrepodata > 2 ? 2 : oldnrepodata; /* XXX: do this right */
1230 repo_write(repo, fp);
1231 repo->nrepodata = oldnrepodata;
1235 if (!repoext && cinfo)
1237 if (!cinfo->extcookie[0])
1239 /* create the ext cookie and append it */
1240 /* we just need some unique ID */
1242 if (!fstat(fileno(fp), &stb))
1243 memset(&stb, 0, sizeof(stb));
1244 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cookie, cinfo->extcookie);
1245 if (cinfo->extcookie[0] == 0)
1246 cinfo->extcookie[0] = 1;
1248 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1256 /* append our cookie describing the metadata state */
1257 if (fwrite(cookie, 32, 1, fp) != 1)
1272 /* switch to just saved repo to activate paging and save memory */
1273 FILE *fp = fopen(tmpl, "r");
1279 repo_empty(repo, 1);
1280 if (repo_add_solv(repo, fp, SOLV_ADD_NO_STUBS))
1282 /* oops, no way to recover from here */
1283 fprintf(stderr, "internal error\n");
1289 int flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1290 /* make sure repodata contains complete repo */
1291 /* (this is how repodata_write saves it) */
1292 repodata_extend_block(info, repo->start, repo->end - repo->start);
1293 info->state = REPODATA_LOADING;
1294 if (strcmp(repoext, "DL") != 0)
1295 flags |= REPO_LOCALPOOL;
1296 repo_add_solv(repo, fp, flags);
1297 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1302 if (!rename(tmpl, calccachepath(repo, repoext, 0)))
1309 /* repomd helpers */
1311 static inline const char *
1312 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1314 Pool *pool = repo->pool;
1316 const char *filename;
1321 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1322 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1323 if (dataiterator_step(&di))
1325 dataiterator_setpos_parent(&di);
1326 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1327 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1329 dataiterator_free(&di);
1330 if (filename && !*chksumtypep)
1332 printf("no %s file checksum!\n", what);
1339 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1341 Id chksumtype, handle;
1342 const unsigned char *chksum;
1343 const char *filename;
1345 filename = repomd_find(repo, what, &chksum, &chksumtype);
1348 if (!strcmp(what, "prestodelta"))
1350 handle = repodata_new_handle(data);
1351 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1352 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1353 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1354 if (!strcmp(what, "deltainfo"))
1356 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1357 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1359 if (!strcmp(what, "filelists"))
1361 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1362 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1364 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1369 repomd_load_ext(Repo *repo, Repodata *data)
1371 const char *filename, *repomdtype;
1374 struct repoinfo *cinfo;
1375 const unsigned char *filechksum;
1379 cinfo = repo->appdata;
1380 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1383 if (!strcmp(repomdtype, "filelists"))
1385 else if (!strcmp(repomdtype, "deltainfo"))
1389 printf("[%s:%s", repo->name, ext);
1390 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1392 printf(" cached]\n"); fflush(stdout);
1395 printf(" fetching]\n"); fflush(stdout);
1396 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1398 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1399 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1401 if (!strcmp(ext, "FL"))
1402 r = repo_add_rpmmd(repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES|REPO_LOCALPOOL);
1403 else if (!strcmp(ext, "DL"))
1404 r = repo_add_deltainfoxml(repo, fp, REPO_USE_LOADING);
1408 printf("%s\n", pool_errstr(repo->pool));
1411 writecachedrepo(repo, data, ext, cinfo->extcookie);
1418 #ifdef ENABLE_SUSEREPO
1419 /* susetags helpers */
1421 static inline const char *
1422 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1424 Pool *pool = repo->pool;
1426 const char *filename;
1431 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
1432 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1433 if (dataiterator_step(&di))
1435 dataiterator_setpos_parent(&di);
1436 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
1439 dataiterator_free(&di);
1440 if (filename && !*chksumtypep)
1442 printf("no %s file checksum!\n", what);
1448 static Id susetags_langtags[] = {
1449 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
1450 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
1451 SOLVABLE_EULA, REPOKEY_TYPE_STR,
1452 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
1453 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
1454 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
1459 susetags_add_ext(Repo *repo, Repodata *data)
1461 Pool *pool = repo->pool;
1464 Id handle, filechksumtype;
1465 const unsigned char *filechksum;
1468 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
1469 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1470 while (dataiterator_step(&di))
1472 if (strncmp(di.kv.str, "packages.", 9) != 0)
1474 if (!strcmp(di.kv.str + 9, "gz"))
1476 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
1478 ext[0] = di.kv.str[9];
1479 ext[1] = di.kv.str[10];
1481 if (!strcmp(ext, "en"))
1483 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
1485 handle = repodata_new_handle(data);
1486 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
1488 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
1489 if (!strcmp(ext, "DU"))
1491 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
1492 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
1494 else if (!strcmp(ext, "FL"))
1496 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1497 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1501 for (i = 0; susetags_langtags[i]; i += 2)
1503 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
1504 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
1507 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1509 dataiterator_free(&di);
1513 susetags_load_ext(Repo *repo, Repodata *data)
1515 const char *filename, *descrdir;
1519 struct repoinfo *cinfo;
1520 const unsigned char *filechksum;
1524 cinfo = repo->appdata;
1525 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1529 ext[0] = filename[9];
1530 ext[1] = filename[10];
1532 printf("[%s:%s", repo->name, ext);
1533 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1535 printf(" cached]\n"); fflush(stdout);
1538 printf(" fetching]\n"); fflush(stdout);
1539 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1540 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1542 descrdir = "suse/setup/descr";
1544 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1545 if ((fp = curlfopen(cinfo, pool_tmpjoin(repo->pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1547 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1548 if (strcmp(ext, "DL") != 0)
1549 flags |= REPO_LOCALPOOL;
1550 if (repo_add_susetags(repo, fp, defvendor, ext, flags))
1553 printf("%s\n", pool_errstr(repo->pool));
1557 writecachedrepo(repo, data, ext, cinfo->extcookie);
1567 load_stub(Pool *pool, Repodata *data, void *dp)
1569 struct repoinfo *cinfo = data->repo->appdata;
1570 switch (cinfo->type)
1572 #ifdef ENABLE_SUSEREPO
1574 return susetags_load_ext(data->repo, data);
1578 return repomd_load_ext(data->repo, data);
1585 static unsigned char installedcookie[32];
1587 #ifdef ENABLE_DEBIAN
1590 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1594 unsigned char *chksum;
1599 static char *basearch;
1611 basearch = strdup(un.machine);
1612 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
1615 binarydir = solv_dupjoin("binary-", basearch, "/");
1616 lbinarydir = strlen(binarydir);
1617 compl = strlen(comp);
1621 chksum = solv_malloc(32);
1623 while(fgets(buf, sizeof(buf), fp))
1628 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1630 if (!strncasecmp(buf, "MD5Sum:", 7))
1632 curchksumtype = REPOKEY_TYPE_MD5;
1635 if (!strncasecmp(buf, "SHA1:", 5))
1637 curchksumtype = REPOKEY_TYPE_SHA1;
1640 if (!strncasecmp(buf, "SHA256:", 7))
1642 curchksumtype = REPOKEY_TYPE_SHA256;
1654 while (*bp && *bp != ' ' && *bp != '\t')
1659 while (*bp == ' ' || *bp == '\t')
1661 while (*bp && *bp != ' ' && *bp != '\t')
1665 while (*bp == ' ' || *bp == '\t')
1668 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1671 if (strncmp(bp, binarydir, lbinarydir))
1674 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1676 unsigned char curchksum[32];
1678 if (filename && !strcmp(bp, "Packages"))
1680 curl = solv_chksum_len(curchksumtype);
1681 if (!curl || (chksumtype && solv_chksum_len(chksumtype) > curl))
1683 if (solv_hex2bin((const char **)&ch, curchksum, sizeof(curchksum)) != curl)
1685 solv_free(filename);
1686 filename = strdup(fn);
1687 chksumtype = curchksumtype;
1688 memcpy(chksum, curchksum, curl);
1694 fn = solv_dupjoin("/", filename, 0);
1695 solv_free(filename);
1696 filename = solv_dupjoin("dists/", cinfo->name, fn);
1700 chksum = solv_free(chksum);
1702 *chksumtypep = chksumtype;
1708 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1711 struct repoinfo *cinfo;
1714 const char *filename;
1715 const unsigned char *filechksum;
1717 #ifdef ENABLE_SUSEREPO
1718 const char *descrdir;
1723 #if defined(ENABLE_SUSEREPO) || defined(ENABLE_RPMMD)
1727 #if defined(ENABLE_DEBIAN)
1732 repo = repo_create(pool, "@System");
1733 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1734 printf("rpm database:");
1735 if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/rpm/Packages"), &stb))
1736 memset(&stb, 0, sizeof(stb));
1738 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1739 printf("dpgk database:");
1740 if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/dpkg/status"), &stb))
1741 memset(&stb, 0, sizeof(stb));
1744 printf("no installed database:");
1745 memset(&stb, 0, sizeof(stb));
1747 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, 0, installedcookie);
1748 if (usecachedrepo(repo, 0, installedcookie, 0))
1749 printf(" cached\n");
1752 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1755 printf(" reading\n");
1757 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1758 # if defined(ENABLE_SUSEREPO) && defined(PRODUCTS_PATH)
1759 if (repo_add_products(repo, PRODUCTS_PATH, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
1761 fprintf(stderr, "product reading failed: %s\n", pool_errstr(pool));
1765 # if defined(ENABLE_APPDATA)
1766 if (repo_add_appdata_dir(repo, APPDATA_PATH, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
1768 fprintf(stderr, "appdata reading failed: %s\n", pool_errstr(pool));
1772 ofp = fopen(calccachepath(repo, 0, 0), "r");
1773 if (repo_add_rpmdb_reffp(repo, ofp, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
1775 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
1781 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1782 if (repo_add_debdb(repo, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
1784 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
1788 repo_internalize(repo);
1789 writecachedrepo(repo, 0, 0, installedcookie);
1791 pool_set_installed(pool, repo);
1793 for (i = 0; i < nrepoinfos; i++)
1795 cinfo = repoinfos + i;
1796 if (!cinfo->enabled)
1799 repo = repo_create(pool, cinfo->alias);
1801 repo->appdata = cinfo;
1802 repo->priority = 99 - cinfo->priority;
1804 dorefresh = cinfo->autorefresh;
1805 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0, 0), &stb) == 0)
1807 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1810 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1812 printf("repo '%s':", cinfo->alias);
1813 printf(" cached\n");
1816 switch (cinfo->type)
1820 printf("rpmmd repo '%s':", cinfo->alias);
1822 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1824 printf(" no repomd.xml file, skipped\n");
1829 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1830 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1832 printf(" cached\n");
1836 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "repodata/repomd.xml.asc", &sigpool))
1841 if (repo_add_repomdxml(repo, fp, 0))
1843 printf("repomd.xml: %s\n", pool_errstr(pool));
1845 break; /* hopeless */
1848 printf(" fetching\n");
1849 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1850 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1852 if (repo_add_rpmmd(repo, fp, 0, 0))
1854 printf("primary: %s\n", pool_errstr(pool));
1855 cinfo->incomplete = 1;
1859 if (cinfo->incomplete)
1860 break; /* hopeless */
1862 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1863 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1865 if (repo_add_updateinfoxml(repo, fp, 0))
1867 printf("updateinfo: %s\n", pool_errstr(pool));
1868 cinfo->incomplete = 1;
1873 #ifdef ENABLE_APPDATA
1874 filename = repomd_find(repo, "appdata", &filechksum, &filechksumtype);
1875 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1877 if (repo_add_appdata(repo, fp, 0))
1879 printf("appdata: %s\n", pool_errstr(pool));
1880 cinfo->incomplete = 1;
1885 data = repo_add_repodata(repo, 0);
1886 if (!repomd_add_ext(repo, data, "deltainfo"))
1887 repomd_add_ext(repo, data, "prestodelta");
1888 repomd_add_ext(repo, data, "filelists");
1889 repodata_internalize(data);
1890 if (!cinfo->incomplete)
1891 writecachedrepo(repo, 0, 0, cinfo->cookie);
1892 repodata_create_stubs(repo_last_repodata(repo));
1896 #ifdef ENABLE_SUSEREPO
1898 printf("susetags repo '%s':", cinfo->alias);
1902 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1904 printf(" no content file, skipped\n");
1909 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1910 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1912 printf(" cached\n");
1916 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "content.asc", &sigpool))
1921 if (repo_add_content(repo, fp, 0))
1923 printf("content: %s\n", pool_errstr(pool));
1925 break; /* hopeless */
1928 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1929 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1931 descrdir = "suse/setup/descr";
1932 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1934 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1937 printf(" no packages file entry, skipped\n");
1940 printf(" fetching\n");
1941 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) == 0)
1942 break; /* hopeless */
1943 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES))
1945 printf("packages: %s\n", pool_errstr(pool));
1947 cinfo->incomplete = 1;
1948 break; /* hopeless */
1951 /* add default language */
1952 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1954 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1957 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1959 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES))
1961 printf("packages.en: %s\n", pool_errstr(pool));
1962 cinfo->incomplete = 1;
1967 filename = susetags_find(repo, "patterns", &filechksum, &filechksumtype);
1970 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1973 while (fgets(pbuf, sizeof(pbuf), fp))
1975 int l = strlen(pbuf);
1977 if (l && pbuf[l - 1] == '\n')
1979 if (!*pbuf || *pbuf == '.' || strchr(pbuf, '/') != 0)
1981 filename = susetags_find(repo, pbuf, &filechksum, &filechksumtype);
1982 if (filename && (fp2 = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1984 if (repo_add_susetags(repo, fp2, defvendor, 0, REPO_NO_INTERNALIZE))
1986 printf("%s: %s\n", pbuf, pool_errstr(pool));
1987 cinfo->incomplete = 1;
1995 #ifdef ENABLE_APPDATA
1996 filename = susetags_find(repo, "appdata.xml.gz", &filechksum, &filechksumtype);
1998 filename = susetags_find(repo, "appdata.xml", &filechksum, &filechksumtype);
1999 if (filename && (fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
2001 if (repo_add_appdata(repo, fp, 0))
2003 printf("appdata: %s\n", pool_errstr(pool));
2004 cinfo->incomplete = 1;
2009 repo_internalize(repo);
2010 data = repo_add_repodata(repo, 0);
2011 susetags_add_ext(repo, data);
2012 repodata_internalize(data);
2013 if (!cinfo->incomplete)
2014 writecachedrepo(repo, 0, 0, cinfo->cookie);
2015 repodata_create_stubs(repo_last_repodata(repo));
2019 #if defined(ENABLE_DEBIAN)
2021 printf("debian repo '%s':", cinfo->alias);
2023 filename = solv_dupjoin("dists/", cinfo->name, "/Release");
2024 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
2026 printf(" no Release file, skipped\n");
2029 free((char *)filename);
2032 solv_free((char *)filename);
2033 if (cinfo->repo_gpgcheck)
2035 filename = solv_dupjoin("dists/", cinfo->name, "/Release.gpg");
2036 if (!downloadchecksig(cinfo, fpr, filename, &sigpool))
2039 solv_free((char *)filename);
2042 solv_free((char *)filename);
2044 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
2045 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
2047 printf(" cached\n");
2051 printf(" fetching\n");
2052 for (j = 0; j < cinfo->ncomponents; j++)
2054 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
2056 printf("[component %s not found]\n", cinfo->components[j]);
2059 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
2061 if (repo_add_debpackages(repo, fp, 0))
2063 printf("component %s: %s\n", cinfo->components[j], pool_errstr(pool));
2064 cinfo->incomplete = 1;
2068 solv_free((char *)filechksum);
2069 solv_free((char *)filename);
2072 if (!cinfo->incomplete)
2073 writecachedrepo(repo, 0, 0, cinfo->cookie);
2078 printf("unsupported repo '%s': skipped\n", cinfo->alias);
2089 yesno(const char *str)
2091 char inbuf[128], *ip;
2098 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2103 while (*ip == ' ' || *ip == '\t')
2110 if (*ip == 'y' || *ip == 'n')
2111 return *ip == 'y' ? 1 : 0;
2115 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2125 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2127 struct fcstate *fcstate = cbdata;
2133 s = pool_id2solvable(pool, p);
2134 if (pool->installed && s->repo == pool->installed)
2136 if (!s->repo->rpmdbid)
2138 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2141 return rpm_byrpmdbid(fcstate->rpmstate, rpmdbid);
2143 for (i = 0; i < fcstate->newpkgscnt; i++)
2144 if (fcstate->checkq->elements[i] == p)
2146 if (i == fcstate->newpkgscnt)
2148 fp = fcstate->newpkgsfps[i];
2152 return rpm_byfp(fcstate->rpmstate, fp, pool_solvable2str(pool, s));
2157 runrpm(const char *arg, const char *name, int dupfd3, const char *rootdir)
2162 if ((pid = fork()) == (pid_t)-1)
2171 if (dupfd3 != -1 && dupfd3 != 3)
2177 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2178 if (strcmp(arg, "-e") == 0)
2179 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2181 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2185 while (waitpid(pid, &status, 0) != pid)
2189 printf("rpm failed\n");
2196 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2199 rundpkg(const char *arg, const char *name, int dupfd3, const char *rootdir)
2204 if ((pid = fork()) == (pid_t)-1)
2213 if (dupfd3 != -1 && dupfd3 != 3)
2219 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2220 if (strcmp(arg, "--install") == 0)
2221 execlp("dpkg", "dpkg", "--install", "--root", rootdir, "--force", "all", name, (char *)0);
2223 execlp("dpkg", "dpkg", "--remove", "--root", rootdir, "--force", "all", name, (char *)0);
2227 while (waitpid(pid, &status, 0) != pid)
2231 printf("dpkg failed\n");
2240 nscallback(Pool *pool, void *data, Id name, Id evr)
2243 if (name == NAMESPACE_LANGUAGE)
2245 if (!strcmp(pool_id2str(pool, evr), "ja"))
2247 if (!strcmp(pool_id2str(pool, evr), "de"))
2249 if (!strcmp(pool_id2str(pool, evr), "en"))
2251 if (!strcmp(pool_id2str(pool, evr), "en_US"))
2259 #ifdef SOFTLOCKS_PATH
2261 addsoftlocks(Pool *pool, Queue *job)
2265 char *bp, *ep, buf[4096];
2267 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2269 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2271 while (*bp == ' ' || *bp == '\t')
2273 if (!*bp || *bp == '#')
2275 for (ep = bp; *ep; ep++)
2276 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2279 type = SOLVER_SOLVABLE_NAME;
2280 if (!strncmp(bp, "provides:", 9) && bp[9])
2282 type = SOLVER_SOLVABLE_PROVIDES;
2285 id = pool_str2id(pool, bp, 1);
2286 if (pool->installed)
2288 FOR_JOB_SELECT(p, pp, type, id)
2289 if (pool->solvables[p].repo == pool->installed)
2292 continue; /* ignore, as it is already installed */
2294 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2301 #if defined(ENABLE_RPMDB)
2304 rewrite_repos(Pool *pool, Queue *addedfileprovides, Queue *addedfileprovides_inst)
2309 Queue fileprovidesq;
2311 struct repoinfo *cinfo;
2313 map_init(&providedids, pool->ss.nstrings);
2314 queue_init(&fileprovidesq);
2315 for (i = 0; i < addedfileprovides->count; i++)
2316 MAPSET(&providedids, addedfileprovides->elements[i]);
2319 /* make sure all repodatas but the first are extensions */
2320 if (repo->nrepodata < 2)
2322 cinfo = repo->appdata;
2323 if (cinfo && cinfo->incomplete)
2325 data = repo_id2repodata(repo, 1);
2326 if (data->loadcallback)
2328 for (j = 2; j < repo->nrepodata; j++)
2330 Repodata *edata = repo_id2repodata(repo, j);
2331 if (!edata->loadcallback)
2334 if (j < repo->nrepodata)
2335 continue; /* found a non-externsion repodata, can't rewrite */
2336 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2338 if (repo == pool->installed && addedfileprovides_inst)
2340 for (j = 0; j < addedfileprovides->count; j++)
2341 MAPCLR(&providedids, addedfileprovides->elements[j]);
2342 for (j = 0; j < addedfileprovides_inst->count; j++)
2343 MAPSET(&providedids, addedfileprovides_inst->elements[j]);
2346 for (j = 0; j < fileprovidesq.count; j++)
2347 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2349 if (repo == pool->installed && addedfileprovides_inst)
2351 for (j = 0; j < addedfileprovides_inst->count; j++)
2352 MAPCLR(&providedids, addedfileprovides_inst->elements[j]);
2353 for (j = 0; j < addedfileprovides->count; j++)
2354 MAPSET(&providedids, addedfileprovides->elements[j]);
2355 if (n == addedfileprovides_inst->count)
2356 continue; /* nothing new added */
2358 else if (n == addedfileprovides->count)
2359 continue; /* nothing new added */
2361 repodata_set_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, repo == pool->installed && addedfileprovides_inst ? addedfileprovides_inst : addedfileprovides);
2362 repodata_internalize(data);
2363 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2365 queue_free(&fileprovidesq);
2366 map_free(&providedids);
2370 addfileprovides(Pool *pool)
2372 Queue addedfileprovides;
2373 Queue addedfileprovides_inst;
2375 queue_init(&addedfileprovides);
2376 queue_init(&addedfileprovides_inst);
2377 pool_addfileprovides_queue(pool, &addedfileprovides, &addedfileprovides_inst);
2378 if (addedfileprovides.count || addedfileprovides_inst.count)
2379 rewrite_repos(pool, &addedfileprovides, &addedfileprovides_inst);
2380 queue_free(&addedfileprovides);
2381 queue_free(&addedfileprovides_inst);
2386 #if defined(SUSE) || defined(FEDORA)
2388 add_patchjobs(Pool *pool, Queue *job)
2392 Map installedmap, multiversionmap;
2395 map_init(&multiversionmap, 0);
2396 map_init(&installedmap, pool->nsolvables);
2397 solver_calculate_multiversionmap(pool, job, &multiversionmap);
2398 if (pool->installed)
2399 FOR_REPO_SOLVABLES(pool->installed, p, s)
2400 MAPSET(&installedmap, p);
2402 /* install all patches */
2403 for (p = 1; p < pool->nsolvables; p++)
2409 s = pool->solvables + p;
2410 if (strncmp(pool_id2str(pool, s->name), "patch:", 6) != 0)
2412 FOR_PROVIDES(p2, pp, s->name)
2414 Solvable *s2 = pool->solvables + p2;
2415 if (s2->name != s->name)
2417 r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2418 if (r < 0 || (r == 0 && p > p2))
2423 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2424 if (type && !strcmp(type, "optional"))
2426 r = solvable_trivial_installable_map(s, &installedmap, 0, &multiversionmap);
2429 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2436 queue_push2(job, SOLVER_SOLVABLE, p);
2438 map_free(&installedmap);
2439 map_free(&multiversionmap);
2445 showdiskusagechanges(Transaction *trans)
2450 /* XXX: use mountpoints here */
2452 duc[1].path = "/usr/share/man";
2453 duc[2].path = "/sbin";
2454 duc[3].path = "/etc";
2455 transaction_calc_duchanges(trans, duc, 4);
2456 for (i = 0; i < 4; i++)
2457 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
2461 #if defined(ENABLE_RPMDB)
2463 trydeltadownload(Solvable *s, struct repoinfo *cinfo, const char *loc)
2465 Pool *pool = s->repo->pool;
2468 const unsigned char *chksum;
2471 char *matchname = strdup(pool_id2str(pool, s->name));
2473 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
2474 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
2475 while (dataiterator_step(&di))
2479 dataiterator_setpos_parent(&di);
2480 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
2481 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
2483 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
2484 FOR_PROVIDES(op, pp, s->name)
2486 Solvable *os = pool->solvables + op;
2487 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
2490 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
2492 /* base is installed, run sequence check */
2495 const char *archstr;
2500 archstr = pool_id2str(pool, s->arch);
2501 if (strlen(archstr) > 10 || strchr(archstr, '\'') != 0)
2504 seq = pool_tmpjoin(pool, pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME), "-", pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR));
2505 seq = pool_tmpappend(pool, seq, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM));
2506 if (strchr(seq, '\'') != 0)
2509 sprintf(cmd, "/usr/bin/applydeltarpm -a '%s' -c -s '", archstr);
2511 sprintf(cmd, "/usr/bin/applydeltarpm -c -s '");
2513 if (system(pool_tmpjoin(pool, cmd, seq, "'")) != 0)
2514 continue; /* didn't match */
2515 /* looks good, download delta */
2517 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
2519 continue; /* no way! */
2520 dloc = pool_lookup_deltalocation(pool, SOLVID_POS, 0);
2523 #ifdef ENABLE_SUSEREPO
2524 if (cinfo->type == TYPE_SUSETAGS)
2526 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
2527 dloc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", dloc);
2530 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
2532 /* got it, now reconstruct */
2533 newfd = opentmpfile();
2535 sprintf(cmd, "applydeltarpm -a '%s' /dev/fd/%d /dev/fd/%d", archstr, fileno(fp), newfd);
2537 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
2539 fcntl(fileno(fp), F_SETFD, 0);
2546 lseek(newfd, 0, SEEK_SET);
2548 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
2549 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
2555 retfp = fdopen(newfd, "r");
2560 dataiterator_free(&di);
2561 solv_free(matchname);
2568 #define MODE_INSTALL 1
2569 #define MODE_ERASE 2
2570 #define MODE_UPDATE 3
2571 #define MODE_DISTUPGRADE 4
2572 #define MODE_VERIFY 5
2573 #define MODE_PATCH 6
2575 #define MODE_REPOLIST 8
2576 #define MODE_SEARCH 9
2581 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2582 fprintf(stderr, "\n");
2583 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2584 fprintf(stderr, " versions from the repositories\n");
2585 fprintf(stderr, " erase: erase installed packages\n");
2586 fprintf(stderr, " info: display package information\n");
2587 fprintf(stderr, " install: install packages\n");
2588 fprintf(stderr, " list: list packages\n");
2589 fprintf(stderr, " repos: list enabled repositories\n");
2590 fprintf(stderr, " search: search name/summary/description\n");
2591 fprintf(stderr, " update: update installed packages\n");
2592 fprintf(stderr, " verify: check dependencies of installed packages\n");
2593 #if defined(SUSE) || defined(FEDORA)
2594 fprintf(stderr, " patch: install newest patches\n");
2596 fprintf(stderr, "\n");
2601 main(int argc, char **argv)
2604 Repo *commandlinerepo = 0;
2605 Id *commandlinepkgs = 0;
2607 struct repoinfo *repoinfos;
2609 int mainmode = 0, mode = 0;
2618 int archfilter_src = 0;
2627 userhome = getenv("HOME");
2628 if (userhome && userhome[0] != '/')
2630 while (argc && !strcmp(argv[0], "-d"))
2638 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2640 mainmode = MODE_INSTALL;
2641 mode = SOLVER_INSTALL;
2643 #if defined(SUSE) || defined(FEDORA)
2644 else if (!strcmp(argv[0], "patch"))
2646 mainmode = MODE_PATCH;
2647 mode = SOLVER_INSTALL;
2650 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2652 mainmode = MODE_ERASE;
2653 mode = SOLVER_ERASE;
2655 else if (!strcmp(argv[0], "list") || !strcmp(argv[0], "ls"))
2657 mainmode = MODE_LIST;
2660 else if (!strcmp(argv[0], "info"))
2662 mainmode = MODE_INFO;
2665 else if (!strcmp(argv[0], "search") || !strcmp(argv[0], "se"))
2667 mainmode = MODE_SEARCH;
2670 else if (!strcmp(argv[0], "verify"))
2672 mainmode = MODE_VERIFY;
2673 mode = SOLVER_VERIFY;
2675 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2677 mainmode = MODE_UPDATE;
2678 mode = SOLVER_UPDATE;
2680 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2682 mainmode = MODE_DISTUPGRADE;
2683 mode = SOLVER_DISTUPGRADE;
2685 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2687 mainmode = MODE_REPOLIST;
2695 if (argc > 2 && !strcmp(argv[1], "--root"))
2701 else if (argc > 1 && !strcmp(argv[1], "--clean"))
2707 else if (argc > 1 && !strcmp(argv[1], "--best"))
2713 if (argc > 2 && !strcmp(argv[1], "--keyname"))
2723 pool = pool_create();
2724 pool_set_rootdir(pool, rootdir);
2728 const char *langs[] = {"de_DE", "de", "en"};
2729 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2733 pool_setloadcallback(pool, load_stub, 0);
2735 pool->nscallback = nscallback;
2738 pool_setdebuglevel(pool, debuglevel);
2740 pool_set_flag(pool, POOL_FLAG_ADDFILEPROVIDESFILTERED, 1);
2741 repoinfos = read_repoinfos(pool, &nrepoinfos);
2743 if (mainmode == MODE_REPOLIST)
2746 for (i = 0; i < nrepoinfos; i++)
2748 struct repoinfo *cinfo = repoinfos + i;
2749 if (!cinfo->enabled)
2751 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2756 read_repos(pool, repoinfos, nrepoinfos);
2759 queue_init(&repofilter);
2760 queue_init(&kindfilter);
2761 queue_init(&archfilter);
2764 if (!strcmp(argv[1], "-i"))
2766 queue_push2(&repofilter, SOLVER_SOLVABLE_REPO | SOLVER_SETREPO, pool->installed->repoid);
2770 else if (argc > 2 && (!strcmp(argv[1], "-r") || !strcmp(argv[1], "--repo")))
2772 const char *rname = argv[2], *rp;
2774 for (rp = rname; *rp; rp++)
2775 if (*rp <= '0' || *rp >= '9')
2779 /* repo specified by number */
2780 int rnum = atoi(rname);
2781 for (i = 0; i < nrepoinfos; i++)
2783 struct repoinfo *cinfo = repoinfos + i;
2784 if (!cinfo->enabled)
2787 repoid = cinfo->repo->repoid;
2792 /* repo specified by alias */
2796 if (!strcasecmp(rname, repo->name))
2797 repoid = repo->repoid;
2802 fprintf(stderr, "%s: no such repo\n", rname);
2805 /* SETVENDOR is actually wrong but useful */
2806 queue_push2(&repofilter, SOLVER_SOLVABLE_REPO | SOLVER_SETREPO | SOLVER_SETVENDOR, repoid);
2810 else if (argc > 2 && !strcmp(argv[1], "--arch"))
2812 if (!strcmp(argv[2], "src") || !strcmp(argv[2], "nosrc"))
2814 queue_push2(&archfilter, SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, 0, pool_str2id(pool, argv[2], 1), REL_ARCH, 1));
2818 else if (argc > 2 && (!strcmp(argv[1], "-t") || !strcmp(argv[1], "--type")))
2820 const char *kind = argv[2];
2821 if (!strcmp(kind, "srcpackage"))
2823 /* hey! should use --arch! */
2824 queue_push2(&archfilter, SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, 0, ARCH_SRC, REL_ARCH, 1));
2830 if (!strcmp(kind, "package"))
2832 if (!strcmp(kind, "all"))
2833 queue_push2(&kindfilter, SOLVER_SOLVABLE_ALL, 0);
2835 queue_push2(&kindfilter, SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, 0, pool_str2id(pool, kind, 1), REL_KIND, 1));
2843 if (mainmode == MODE_SEARCH)
2849 pool_createwhatprovides(pool);
2851 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2852 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2853 dataiterator_set_search(&di, 0, 0);
2854 while (dataiterator_step(&di))
2855 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2856 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2857 dataiterator_set_search(&di, 0, 0);
2858 while (dataiterator_step(&di))
2859 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2860 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2861 dataiterator_set_search(&di, 0, 0);
2862 while (dataiterator_step(&di))
2863 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2864 dataiterator_free(&di);
2865 if (repofilter.count)
2866 selection_filter(pool, &sel, &repofilter);
2869 selection_solvables(pool, &sel, &q);
2871 for (i = 0; i < q.count; i++)
2873 Solvable *s = pool_id2solvable(pool, q.elements[i]);
2874 printf(" - %s [%s]: %s\n", pool_solvable2str(pool, s), s->repo->name, solvable_lookup_str(s, SOLVABLE_SUMMARY));
2880 /* process command line packages */
2881 if (mainmode == MODE_LIST || mainmode == MODE_INFO || mainmode == MODE_INSTALL)
2883 for (i = 1; i < argc; i++)
2886 l = strlen(argv[i]);
2887 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2888 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2891 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2892 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2895 if (access(argv[i], R_OK))
2900 if (!commandlinepkgs)
2901 commandlinepkgs = solv_calloc(argc, sizeof(Id));
2902 if (!commandlinerepo)
2903 commandlinerepo = repo_create(pool, "@commandline");
2905 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2906 p = repo_add_rpm(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2908 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2909 p = repo_add_deb(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2913 fprintf(stderr, "could not add '%s'\n", argv[i]);
2916 commandlinepkgs[i] = p;
2918 if (commandlinerepo)
2919 repo_internalize(commandlinerepo);
2922 // FOR_REPOS(i, repo)
2923 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2925 #if defined(ENABLE_RPMDB)
2926 if (pool->disttype == DISTTYPE_RPM)
2927 addfileprovides(pool);
2929 pool_createwhatprovides(pool);
2932 keyname = solv_dupjoin("solvable:", keyname, 0);
2934 for (i = 1; i < argc; i++)
2937 int j, flags, rflags;
2939 if (commandlinepkgs && commandlinepkgs[i])
2941 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2945 flags = SELECTION_NAME|SELECTION_PROVIDES|SELECTION_GLOB;
2946 flags |= SELECTION_CANON|SELECTION_DOTARCH|SELECTION_REL;
2947 if (kindfilter.count)
2948 flags |= SELECTION_SKIP_KIND;
2949 if (mode == MODE_LIST || archfilter_src)
2950 flags |= SELECTION_WITH_SOURCE;
2951 if (argv[i][0] == '/')
2952 flags |= SELECTION_FILELIST | (mode == MODE_ERASE ? SELECTION_INSTALLED_ONLY : 0);
2954 rflags = selection_make(pool, &job2, argv[i], flags);
2956 rflags = selection_make_matchdeps(pool, &job2, argv[i], flags, pool_str2id(pool, keyname, 1), 0);
2957 if (repofilter.count)
2958 selection_filter(pool, &job2, &repofilter);
2959 if (archfilter.count)
2960 selection_filter(pool, &job2, &archfilter);
2961 if (kindfilter.count)
2962 selection_filter(pool, &job2, &kindfilter);
2965 flags |= SELECTION_NOCASE;
2967 rflags = selection_make(pool, &job2, argv[i], flags);
2969 rflags = selection_make_matchdeps(pool, &job2, argv[i], flags, pool_str2id(pool, keyname, 1), 0);
2970 if (repofilter.count)
2971 selection_filter(pool, &job2, &repofilter);
2972 if (archfilter.count)
2973 selection_filter(pool, &job2, &archfilter);
2974 if (kindfilter.count)
2975 selection_filter(pool, &job2, &kindfilter);
2977 printf("[ignoring case for '%s']\n", argv[i]);
2981 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2984 if (rflags & SELECTION_FILELIST)
2985 printf("[using file list match for '%s']\n", argv[i]);
2986 if (rflags & SELECTION_PROVIDES)
2987 printf("[using capability match for '%s']\n", argv[i]);
2988 for (j = 0; j < job2.count; j++)
2989 queue_push(&job, job2.elements[j]);
2992 keyname = solv_free(keyname);
2994 if (!job.count && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE || mainmode == MODE_VERIFY || repofilter.count || archfilter.count || kindfilter.count))
2996 queue_push2(&job, SOLVER_SOLVABLE_ALL, 0);
2997 if (repofilter.count)
2998 selection_filter(pool, &job, &repofilter);
2999 if (archfilter.count)
3000 selection_filter(pool, &job, &archfilter);
3001 if (kindfilter.count)
3002 selection_filter(pool, &job, &kindfilter);
3004 queue_free(&repofilter);
3005 queue_free(&archfilter);
3006 queue_free(&kindfilter);
3008 if (!job.count && mainmode != MODE_PATCH)
3010 printf("no package matched\n");
3014 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
3016 /* list mode, no solver needed */
3019 for (i = 0; i < job.count; i += 2)
3023 pool_job2solvables(pool, &q, job.elements[i], job.elements[i + 1]);
3024 for (j = 0; j < q.count; j++)
3026 Solvable *s = pool_id2solvable(pool, q.elements[j]);
3027 if (mainmode == MODE_INFO)
3030 printf("Name: %s\n", pool_solvable2str(pool, s));
3031 printf("Repo: %s\n", s->repo->name);
3032 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
3033 str = solvable_lookup_str(s, SOLVABLE_URL);
3035 printf("Url: %s\n", str);
3036 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
3038 printf("License: %s\n", str);
3040 str = solvable_lookup_sourcepkg(s);
3042 printf("Source: %s\n", str);
3044 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
3050 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
3052 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
3054 printf(" - %s [%s]\n", pool_solvable2str(pool, s), s->repo->name);
3056 printf(" %s\n", sum);
3063 free_repoinfos(repoinfos, nrepoinfos);
3064 solv_free(commandlinepkgs);
3066 yum_substitute(pool, 0);
3071 #if defined(SUSE) || defined(FEDORA)
3072 if (mainmode == MODE_PATCH)
3073 add_patchjobs(pool, &job);
3077 for (i = 0; i < job.count; i += 2)
3079 job.elements[i] |= mode;
3080 if (mode == SOLVER_UPDATE && pool_isemptyupdatejob(pool, job.elements[i], job.elements[i + 1]))
3081 job.elements[i] ^= SOLVER_UPDATE ^ SOLVER_INSTALL;
3083 job.elements[i] |= SOLVER_CLEANDEPS;
3085 job.elements[i] |= SOLVER_FORCEBEST;
3088 // multiversion test
3089 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae", 1));
3090 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-base", 1));
3091 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-extra", 1));
3093 queue_push2(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, NAMESPACE_LANGUAGE, 0, REL_NAMESPACE, 1));
3094 queue_push2(&job, SOLVER_ERASE|SOLVER_CLEANDEPS|SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, NAMESPACE_LANGUAGE, 0, REL_NAMESPACE, 1));
3097 #ifdef SOFTLOCKS_PATH
3098 addsoftlocks(pool, &job);
3101 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3104 solv = solver_create(pool);
3105 solver_set_flag(solv, SOLVER_FLAG_SPLITPROVIDES, 1);
3107 solver_set_flag(solv, SOLVER_FLAG_ALLOW_VENDORCHANGE, 1);
3109 if (mainmode == MODE_ERASE)
3110 solver_set_flag(solv, SOLVER_FLAG_ALLOW_UNINSTALL, 1); /* don't nag */
3111 solver_set_flag(solv, SOLVER_FLAG_BEST_OBEY_POLICY, 1);
3115 Id problem, solution;
3118 if (!solver_solve(solv, &job))
3120 pcnt = solver_problem_count(solv);
3121 printf("Found %d problems:\n", pcnt);
3122 for (problem = 1; problem <= pcnt; problem++)
3125 printf("Problem %d/%d:\n", problem, pcnt);
3126 solver_printprobleminfo(solv, problem);
3128 scnt = solver_solution_count(solv, problem);
3129 for (solution = 1; solution <= scnt; solution++)
3131 printf("Solution %d:\n", solution);
3132 solver_printsolution(solv, problem, solution);
3137 char inbuf[128], *ip;
3138 printf("Please choose a solution: ");
3141 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
3146 while (*ip == ' ' || *ip == '\t')
3148 if (*ip >= '0' && *ip <= '9')
3151 if (take >= 1 && take <= scnt)
3167 solver_take_solution(solv, problem, take, &job);
3171 trans = solver_create_transaction(solv);
3172 if (!trans->steps.count)
3174 printf("Nothing to do.\n");
3175 transaction_free(trans);
3179 free_repoinfos(repoinfos, nrepoinfos);
3180 solv_free(commandlinepkgs);
3182 yum_substitute(pool, 0);
3187 /* display transaction to the user and ask for confirmation */
3189 printf("Transaction summary:\n\n");
3190 transaction_print(trans);
3192 showdiskusagechanges(trans);
3194 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
3197 if (!yesno("OK to continue (y/n)? "))
3200 transaction_free(trans);
3204 free_repoinfos(repoinfos, nrepoinfos);
3205 solv_free(commandlinepkgs);
3207 yum_substitute(pool, 0);
3212 /* download all new packages */
3213 queue_init(&checkq);
3214 newpkgs = transaction_installedresult(trans, &checkq);
3218 int downloadsize = 0;
3219 for (i = 0; i < newpkgs; i++)
3223 p = checkq.elements[i];
3224 s = pool_id2solvable(pool, p);
3225 downloadsize += solvable_lookup_sizek(s, SOLVABLE_DOWNLOADSIZE, 0);
3227 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
3228 newpkgsfps = solv_calloc(newpkgs, sizeof(*newpkgsfps));
3229 for (i = 0; i < newpkgs; i++)
3231 unsigned int medianr;
3234 struct repoinfo *cinfo;
3235 const unsigned char *chksum;
3238 p = checkq.elements[i];
3239 s = pool_id2solvable(pool, p);
3240 if (s->repo == commandlinerepo)
3242 loc = solvable_lookup_location(s, &medianr);
3245 if (!(newpkgsfps[i] = fopen(loc, "r")))
3253 cinfo = s->repo->appdata;
3256 printf("%s: no repository information\n", s->repo->name);
3259 loc = solvable_lookup_location(s, &medianr);
3262 #if defined(ENABLE_RPMDB)
3263 if (pool->installed && pool->installed->nsolvables)
3265 if ((newpkgsfps[i] = trydeltadownload(s, cinfo, loc)) != 0)
3269 continue; /* delta worked! */
3273 #ifdef ENABLE_SUSEREPO
3274 if (cinfo->type == TYPE_SUSETAGS)
3276 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3277 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3281 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3282 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3284 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3293 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3294 /* check for file conflicts */
3298 struct fcstate fcstate;
3300 printf("Searching for file conflicts\n");
3301 queue_init(&conflicts);
3302 fcstate.rpmstate = rpm_state_create(pool, rootdir);
3303 fcstate.newpkgscnt = newpkgs;
3304 fcstate.checkq = &checkq;
3305 fcstate.newpkgsfps = newpkgsfps;
3306 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, FINDFILECONFLICTS_USE_SOLVABLEFILELIST | FINDFILECONFLICTS_CHECK_DIRALIASING | FINDFILECONFLICTS_USE_ROOTDIR, &fileconflict_cb, &fcstate);
3307 fcstate.rpmstate = rpm_state_free(fcstate.rpmstate);
3308 if (conflicts.count)
3311 for (i = 0; i < conflicts.count; i += 6)
3312 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 + 4]));
3314 if (yesno("Re-run solver (y/n/q)? "))
3316 for (i = 0; i < newpkgs; i++)
3318 fclose(newpkgsfps[i]);
3319 newpkgsfps = solv_free(newpkgsfps);
3322 pool_add_fileconflicts_deps(pool, &conflicts);
3326 queue_free(&conflicts);
3330 /* and finally commit the transaction */
3331 printf("Committing transaction:\n\n");
3332 transaction_order(trans, 0);
3333 for (i = 0; i < trans->steps.count; i++)
3335 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3336 const char *evr, *evrp, *nvra;
3343 p = trans->steps.elements[i];
3344 s = pool_id2solvable(pool, p);
3345 type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3348 case SOLVER_TRANSACTION_ERASE:
3349 printf("erase %s\n", pool_solvid2str(pool, p));
3350 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3351 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3353 /* strip epoch from evr */
3354 evr = evrp = pool_id2str(pool, s->evr);
3355 while (*evrp >= '0' && *evrp <= '9')
3357 if (evrp > evr && evrp[0] == ':' && evrp[1])
3359 nvra = pool_tmpjoin(pool, pool_id2str(pool, s->name), "-", evr);
3360 nvra = pool_tmpappend(pool, nvra, ".", pool_id2str(pool, s->arch));
3361 runrpm("-e", nvra, -1, rootdir); /* too bad that --querybynumber doesn't work */
3363 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3364 rundpkg("--remove", pool_id2str(pool, s->name), 0, rootdir);
3367 case SOLVER_TRANSACTION_INSTALL:
3368 case SOLVER_TRANSACTION_MULTIINSTALL:
3369 printf("install %s\n", pool_solvid2str(pool, p));
3370 for (j = 0; j < newpkgs; j++)
3371 if (checkq.elements[j] == p)
3373 fp = j < newpkgs ? newpkgsfps[j] : 0;
3377 lseek(fileno(fp), 0, SEEK_SET);
3378 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3379 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp), rootdir);
3381 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3382 rundpkg("--install", "/dev/fd/3", fileno(fp), rootdir);
3392 for (i = 0; i < newpkgs; i++)
3394 fclose(newpkgsfps[i]);
3395 solv_free(newpkgsfps);
3396 queue_free(&checkq);
3397 transaction_free(trans);
3401 free_repoinfos(repoinfos, nrepoinfos);
3402 solv_free(commandlinepkgs);
3404 yum_substitute(pool, 0);