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_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_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_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_USE_ROOTDIR))
1784 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
1788 writecachedrepo(repo, 0, 0, installedcookie);
1790 pool_set_installed(pool, repo);
1792 for (i = 0; i < nrepoinfos; i++)
1794 cinfo = repoinfos + i;
1795 if (!cinfo->enabled)
1798 repo = repo_create(pool, cinfo->alias);
1800 repo->appdata = cinfo;
1801 repo->priority = 99 - cinfo->priority;
1803 dorefresh = cinfo->autorefresh;
1804 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0, 0), &stb) == 0)
1806 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1809 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1811 printf("repo '%s':", cinfo->alias);
1812 printf(" cached\n");
1815 switch (cinfo->type)
1819 printf("rpmmd repo '%s':", cinfo->alias);
1821 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1823 printf(" no repomd.xml file, skipped\n");
1828 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1829 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1831 printf(" cached\n");
1835 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "repodata/repomd.xml.asc", &sigpool))
1840 if (repo_add_repomdxml(repo, fp, 0))
1842 printf("repomd.xml: %s\n", pool_errstr(pool));
1844 break; /* hopeless */
1847 printf(" fetching\n");
1848 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1849 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1851 if (repo_add_rpmmd(repo, fp, 0, 0))
1853 printf("primary: %s\n", pool_errstr(pool));
1854 cinfo->incomplete = 1;
1858 if (cinfo->incomplete)
1859 break; /* hopeless */
1861 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1862 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1864 if (repo_add_updateinfoxml(repo, fp, 0))
1866 printf("updateinfo: %s\n", pool_errstr(pool));
1867 cinfo->incomplete = 1;
1872 #ifdef ENABLE_APPDATA
1873 filename = repomd_find(repo, "appdata", &filechksum, &filechksumtype);
1874 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1876 if (repo_add_appdata(repo, fp, 0))
1878 printf("appdata: %s\n", pool_errstr(pool));
1879 cinfo->incomplete = 1;
1884 data = repo_add_repodata(repo, 0);
1885 if (!repomd_add_ext(repo, data, "deltainfo"))
1886 repomd_add_ext(repo, data, "prestodelta");
1887 repomd_add_ext(repo, data, "filelists");
1888 repodata_internalize(data);
1889 if (!cinfo->incomplete)
1890 writecachedrepo(repo, 0, 0, cinfo->cookie);
1891 repodata_create_stubs(repo_last_repodata(repo));
1895 #ifdef ENABLE_SUSEREPO
1897 printf("susetags repo '%s':", cinfo->alias);
1901 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1903 printf(" no content file, skipped\n");
1908 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1909 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1911 printf(" cached\n");
1915 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "content.asc", &sigpool))
1920 if (repo_add_content(repo, fp, 0))
1922 printf("content: %s\n", pool_errstr(pool));
1924 break; /* hopeless */
1927 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1928 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1930 descrdir = "suse/setup/descr";
1931 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1933 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1936 printf(" no packages file entry, skipped\n");
1939 printf(" fetching\n");
1940 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) == 0)
1941 break; /* hopeless */
1942 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES))
1944 printf("packages: %s\n", pool_errstr(pool));
1946 cinfo->incomplete = 1;
1947 break; /* hopeless */
1950 /* add default language */
1951 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1953 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1956 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1958 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES))
1960 printf("packages.en: %s\n", pool_errstr(pool));
1961 cinfo->incomplete = 1;
1966 filename = susetags_find(repo, "patterns", &filechksum, &filechksumtype);
1969 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1972 while (fgets(pbuf, sizeof(pbuf), fp))
1974 int l = strlen(pbuf);
1976 if (l && pbuf[l - 1] == '\n')
1978 if (!*pbuf || *pbuf == '.' || strchr(pbuf, '/') != 0)
1980 filename = susetags_find(repo, pbuf, &filechksum, &filechksumtype);
1981 if (filename && (fp2 = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1983 if (repo_add_susetags(repo, fp2, defvendor, 0, REPO_NO_INTERNALIZE))
1985 printf("%s: %s\n", pbuf, pool_errstr(pool));
1986 cinfo->incomplete = 1;
1994 #ifdef ENABLE_APPDATA
1995 filename = susetags_find(repo, "appdata.xml.gz", &filechksum, &filechksumtype);
1997 filename = susetags_find(repo, "appdata.xml", &filechksum, &filechksumtype);
1998 if (filename && (fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
2000 if (repo_add_appdata(repo, fp, 0))
2002 printf("appdata: %s\n", pool_errstr(pool));
2003 cinfo->incomplete = 1;
2008 repo_internalize(repo);
2009 data = repo_add_repodata(repo, 0);
2010 susetags_add_ext(repo, data);
2011 repodata_internalize(data);
2012 if (!cinfo->incomplete)
2013 writecachedrepo(repo, 0, 0, cinfo->cookie);
2014 repodata_create_stubs(repo_last_repodata(repo));
2018 #if defined(ENABLE_DEBIAN)
2020 printf("debian repo '%s':", cinfo->alias);
2022 filename = solv_dupjoin("dists/", cinfo->name, "/Release");
2023 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
2025 printf(" no Release file, skipped\n");
2028 free((char *)filename);
2031 solv_free((char *)filename);
2032 if (cinfo->repo_gpgcheck)
2034 filename = solv_dupjoin("dists/", cinfo->name, "/Release.gpg");
2035 if (!downloadchecksig(cinfo, fpr, filename, &sigpool))
2038 solv_free((char *)filename);
2041 solv_free((char *)filename);
2043 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
2044 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
2046 printf(" cached\n");
2050 printf(" fetching\n");
2051 for (j = 0; j < cinfo->ncomponents; j++)
2053 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
2055 printf("[component %s not found]\n", cinfo->components[j]);
2058 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
2060 if (repo_add_debpackages(repo, fp, 0))
2062 printf("component %s: %s\n", cinfo->components[j], pool_errstr(pool));
2063 cinfo->incomplete = 1;
2067 solv_free((char *)filechksum);
2068 solv_free((char *)filename);
2071 if (!cinfo->incomplete)
2072 writecachedrepo(repo, 0, 0, cinfo->cookie);
2077 printf("unsupported repo '%s': skipped\n", cinfo->alias);
2088 yesno(const char *str)
2090 char inbuf[128], *ip;
2097 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2102 while (*ip == ' ' || *ip == '\t')
2109 if (*ip == 'y' || *ip == 'n')
2110 return *ip == 'y' ? 1 : 0;
2114 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2124 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2126 struct fcstate *fcstate = cbdata;
2132 s = pool_id2solvable(pool, p);
2133 if (pool->installed && s->repo == pool->installed)
2135 if (!s->repo->rpmdbid)
2137 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2140 return rpm_byrpmdbid(fcstate->rpmstate, rpmdbid);
2142 for (i = 0; i < fcstate->newpkgscnt; i++)
2143 if (fcstate->checkq->elements[i] == p)
2145 if (i == fcstate->newpkgscnt)
2147 fp = fcstate->newpkgsfps[i];
2151 return rpm_byfp(fcstate->rpmstate, fp, pool_solvable2str(pool, s));
2156 runrpm(const char *arg, const char *name, int dupfd3, const char *rootdir)
2161 if ((pid = fork()) == (pid_t)-1)
2170 if (dupfd3 != -1 && dupfd3 != 3)
2176 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2177 if (strcmp(arg, "-e") == 0)
2178 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2180 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2184 while (waitpid(pid, &status, 0) != pid)
2188 printf("rpm failed\n");
2195 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2198 rundpkg(const char *arg, const char *name, int dupfd3, const char *rootdir)
2203 if ((pid = fork()) == (pid_t)-1)
2212 if (dupfd3 != -1 && dupfd3 != 3)
2218 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2219 if (strcmp(arg, "--install") == 0)
2220 execlp("dpkg", "dpkg", "--install", "--root", rootdir, "--force", "all", name, (char *)0);
2222 execlp("dpkg", "dpkg", "--remove", "--root", rootdir, "--force", "all", name, (char *)0);
2226 while (waitpid(pid, &status, 0) != pid)
2230 printf("dpkg failed\n");
2239 nscallback(Pool *pool, void *data, Id name, Id evr)
2242 if (name == NAMESPACE_LANGUAGE)
2244 if (!strcmp(pool_id2str(pool, evr), "ja"))
2246 if (!strcmp(pool_id2str(pool, evr), "de"))
2248 if (!strcmp(pool_id2str(pool, evr), "en"))
2250 if (!strcmp(pool_id2str(pool, evr), "en_US"))
2258 #ifdef SOFTLOCKS_PATH
2260 addsoftlocks(Pool *pool, Queue *job)
2264 char *bp, *ep, buf[4096];
2266 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2268 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2270 while (*bp == ' ' || *bp == '\t')
2272 if (!*bp || *bp == '#')
2274 for (ep = bp; *ep; ep++)
2275 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2278 type = SOLVER_SOLVABLE_NAME;
2279 if (!strncmp(bp, "provides:", 9) && bp[9])
2281 type = SOLVER_SOLVABLE_PROVIDES;
2284 id = pool_str2id(pool, bp, 1);
2285 if (pool->installed)
2287 FOR_JOB_SELECT(p, pp, type, id)
2288 if (pool->solvables[p].repo == pool->installed)
2291 continue; /* ignore, as it is already installed */
2293 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2300 #if defined(ENABLE_RPMDB)
2303 rewrite_repos(Pool *pool, Queue *addedfileprovides, Queue *addedfileprovides_inst)
2308 Queue fileprovidesq;
2310 struct repoinfo *cinfo;
2312 map_init(&providedids, pool->ss.nstrings);
2313 queue_init(&fileprovidesq);
2314 for (i = 0; i < addedfileprovides->count; i++)
2315 MAPSET(&providedids, addedfileprovides->elements[i]);
2318 /* make sure all repodatas but the first are extensions */
2319 if (repo->nrepodata < 2)
2321 cinfo = repo->appdata;
2322 if (cinfo && cinfo->incomplete)
2324 data = repo_id2repodata(repo, 1);
2325 if (data->loadcallback)
2327 for (j = 2; j < repo->nrepodata; j++)
2329 Repodata *edata = repo_id2repodata(repo, j);
2330 if (!edata->loadcallback)
2333 if (j < repo->nrepodata)
2334 continue; /* found a non-externsion repodata, can't rewrite */
2335 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2337 if (repo == pool->installed && addedfileprovides_inst)
2339 for (j = 0; j < addedfileprovides->count; j++)
2340 MAPCLR(&providedids, addedfileprovides->elements[j]);
2341 for (j = 0; j < addedfileprovides_inst->count; j++)
2342 MAPSET(&providedids, addedfileprovides_inst->elements[j]);
2345 for (j = 0; j < fileprovidesq.count; j++)
2346 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2348 if (repo == pool->installed && addedfileprovides_inst)
2350 for (j = 0; j < addedfileprovides_inst->count; j++)
2351 MAPCLR(&providedids, addedfileprovides_inst->elements[j]);
2352 for (j = 0; j < addedfileprovides->count; j++)
2353 MAPSET(&providedids, addedfileprovides->elements[j]);
2354 if (n == addedfileprovides_inst->count)
2355 continue; /* nothing new added */
2357 else if (n == addedfileprovides->count)
2358 continue; /* nothing new added */
2360 repodata_set_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, repo == pool->installed && addedfileprovides_inst ? addedfileprovides_inst : addedfileprovides);
2361 repodata_internalize(data);
2362 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2364 queue_free(&fileprovidesq);
2365 map_free(&providedids);
2369 addfileprovides(Pool *pool)
2371 Queue addedfileprovides;
2372 Queue addedfileprovides_inst;
2374 queue_init(&addedfileprovides);
2375 queue_init(&addedfileprovides_inst);
2376 pool_addfileprovides_queue(pool, &addedfileprovides, &addedfileprovides_inst);
2377 if (addedfileprovides.count || addedfileprovides_inst.count)
2378 rewrite_repos(pool, &addedfileprovides, &addedfileprovides_inst);
2379 queue_free(&addedfileprovides);
2380 queue_free(&addedfileprovides_inst);
2385 #if defined(SUSE) || defined(FEDORA)
2387 add_patchjobs(Pool *pool, Queue *job)
2391 Map installedmap, multiversionmap;
2394 map_init(&multiversionmap, 0);
2395 map_init(&installedmap, pool->nsolvables);
2396 solver_calculate_multiversionmap(pool, job, &multiversionmap);
2397 if (pool->installed)
2398 FOR_REPO_SOLVABLES(pool->installed, p, s)
2399 MAPSET(&installedmap, p);
2401 /* install all patches */
2402 for (p = 1; p < pool->nsolvables; p++)
2408 s = pool->solvables + p;
2409 if (strncmp(pool_id2str(pool, s->name), "patch:", 6) != 0)
2411 FOR_PROVIDES(p2, pp, s->name)
2413 Solvable *s2 = pool->solvables + p2;
2414 if (s2->name != s->name)
2416 r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2417 if (r < 0 || (r == 0 && p > p2))
2422 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2423 if (type && !strcmp(type, "optional"))
2425 r = solvable_trivial_installable_map(s, &installedmap, 0, &multiversionmap);
2428 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2435 queue_push2(job, SOLVER_SOLVABLE, p);
2437 map_free(&installedmap);
2438 map_free(&multiversionmap);
2444 showdiskusagechanges(Transaction *trans)
2449 /* XXX: use mountpoints here */
2451 duc[1].path = "/usr/share/man";
2452 duc[2].path = "/sbin";
2453 duc[3].path = "/etc";
2454 transaction_calc_duchanges(trans, duc, 4);
2455 for (i = 0; i < 4; i++)
2456 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
2460 #if defined(ENABLE_RPMDB)
2462 trydeltadownload(Solvable *s, struct repoinfo *cinfo, const char *loc)
2464 Pool *pool = s->repo->pool;
2467 const unsigned char *chksum;
2470 char *matchname = strdup(pool_id2str(pool, s->name));
2472 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
2473 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
2474 while (dataiterator_step(&di))
2478 dataiterator_setpos_parent(&di);
2479 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
2480 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
2482 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
2483 FOR_PROVIDES(op, pp, s->name)
2485 Solvable *os = pool->solvables + op;
2486 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
2489 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
2491 /* base is installed, run sequence check */
2494 const char *archstr;
2499 archstr = pool_id2str(pool, s->arch);
2500 if (strlen(archstr) > 10 || strchr(archstr, '\'') != 0)
2503 seq = pool_tmpjoin(pool, pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME), "-", pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR));
2504 seq = pool_tmpappend(pool, seq, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM));
2505 if (strchr(seq, '\'') != 0)
2508 sprintf(cmd, "/usr/bin/applydeltarpm -a '%s' -c -s '", archstr);
2510 sprintf(cmd, "/usr/bin/applydeltarpm -c -s '");
2512 if (system(pool_tmpjoin(pool, cmd, seq, "'")) != 0)
2513 continue; /* didn't match */
2514 /* looks good, download delta */
2516 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
2518 continue; /* no way! */
2519 dloc = pool_lookup_deltalocation(pool, SOLVID_POS, 0);
2522 #ifdef ENABLE_SUSEREPO
2523 if (cinfo->type == TYPE_SUSETAGS)
2525 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
2526 dloc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", dloc);
2529 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
2531 /* got it, now reconstruct */
2532 newfd = opentmpfile();
2534 sprintf(cmd, "applydeltarpm -a '%s' /dev/fd/%d /dev/fd/%d", archstr, fileno(fp), newfd);
2536 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
2538 fcntl(fileno(fp), F_SETFD, 0);
2545 lseek(newfd, 0, SEEK_SET);
2547 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
2548 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
2554 retfp = fdopen(newfd, "r");
2559 dataiterator_free(&di);
2560 solv_free(matchname);
2567 #define MODE_INSTALL 1
2568 #define MODE_ERASE 2
2569 #define MODE_UPDATE 3
2570 #define MODE_DISTUPGRADE 4
2571 #define MODE_VERIFY 5
2572 #define MODE_PATCH 6
2574 #define MODE_REPOLIST 8
2575 #define MODE_SEARCH 9
2580 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2581 fprintf(stderr, "\n");
2582 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2583 fprintf(stderr, " versions from the repositories\n");
2584 fprintf(stderr, " erase: erase installed packages\n");
2585 fprintf(stderr, " info: display package information\n");
2586 fprintf(stderr, " install: install packages\n");
2587 fprintf(stderr, " list: list packages\n");
2588 fprintf(stderr, " repos: list enabled repositories\n");
2589 fprintf(stderr, " search: search name/summary/description\n");
2590 fprintf(stderr, " update: update installed packages\n");
2591 fprintf(stderr, " verify: check dependencies of installed packages\n");
2592 #if defined(SUSE) || defined(FEDORA)
2593 fprintf(stderr, " patch: install newest patches\n");
2595 fprintf(stderr, "\n");
2600 main(int argc, char **argv)
2603 Repo *commandlinerepo = 0;
2604 Id *commandlinepkgs = 0;
2606 struct repoinfo *repoinfos;
2608 int mainmode = 0, mode = 0;
2617 int archfilter_src = 0;
2626 userhome = getenv("HOME");
2627 if (userhome && userhome[0] != '/')
2629 while (argc && !strcmp(argv[0], "-d"))
2637 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2639 mainmode = MODE_INSTALL;
2640 mode = SOLVER_INSTALL;
2642 #if defined(SUSE) || defined(FEDORA)
2643 else if (!strcmp(argv[0], "patch"))
2645 mainmode = MODE_PATCH;
2646 mode = SOLVER_INSTALL;
2649 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2651 mainmode = MODE_ERASE;
2652 mode = SOLVER_ERASE;
2654 else if (!strcmp(argv[0], "list") || !strcmp(argv[0], "ls"))
2656 mainmode = MODE_LIST;
2659 else if (!strcmp(argv[0], "info"))
2661 mainmode = MODE_INFO;
2664 else if (!strcmp(argv[0], "search") || !strcmp(argv[0], "se"))
2666 mainmode = MODE_SEARCH;
2669 else if (!strcmp(argv[0], "verify"))
2671 mainmode = MODE_VERIFY;
2672 mode = SOLVER_VERIFY;
2674 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2676 mainmode = MODE_UPDATE;
2677 mode = SOLVER_UPDATE;
2679 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2681 mainmode = MODE_DISTUPGRADE;
2682 mode = SOLVER_DISTUPGRADE;
2684 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2686 mainmode = MODE_REPOLIST;
2694 if (argc > 2 && !strcmp(argv[1], "--root"))
2700 else if (argc > 1 && !strcmp(argv[1], "--clean"))
2706 else if (argc > 1 && !strcmp(argv[1], "--best"))
2712 if (argc > 2 && !strcmp(argv[1], "--keyname"))
2722 pool = pool_create();
2723 pool_set_rootdir(pool, rootdir);
2727 const char *langs[] = {"de_DE", "de", "en"};
2728 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2732 pool_setloadcallback(pool, load_stub, 0);
2734 pool->nscallback = nscallback;
2737 pool_setdebuglevel(pool, debuglevel);
2739 pool_set_flag(pool, POOL_FLAG_ADDFILEPROVIDESFILTERED, 1);
2740 repoinfos = read_repoinfos(pool, &nrepoinfos);
2742 if (mainmode == MODE_REPOLIST)
2745 for (i = 0; i < nrepoinfos; i++)
2747 struct repoinfo *cinfo = repoinfos + i;
2748 if (!cinfo->enabled)
2750 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2755 read_repos(pool, repoinfos, nrepoinfos);
2758 queue_init(&repofilter);
2759 queue_init(&kindfilter);
2760 queue_init(&archfilter);
2763 if (!strcmp(argv[1], "-r") || !strcmp(argv[1], "--repo"))
2765 const char *rname = argv[2], *rp;
2767 for (rp = rname; *rp; rp++)
2768 if (*rp <= '0' || *rp >= '9')
2772 /* repo specified by number */
2773 int rnum = atoi(rname);
2774 for (i = 0; i < nrepoinfos; i++)
2776 struct repoinfo *cinfo = repoinfos + i;
2777 if (!cinfo->enabled)
2780 repoid = cinfo->repo->repoid;
2785 /* repo specified by alias */
2789 if (!strcasecmp(rname, repo->name))
2790 repoid = repo->repoid;
2795 fprintf(stderr, "%s: no such repo\n", rname);
2798 /* SETVENDOR is actually wrong but useful */
2799 queue_push2(&repofilter, SOLVER_SOLVABLE_REPO | SOLVER_SETREPO | SOLVER_SETVENDOR, repoid);
2803 else if (!strcmp(argv[1], "--arch"))
2805 if (!strcmp(argv[2], "src") || !strcmp(argv[2], "nosrc"))
2807 queue_push2(&archfilter, SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, 0, pool_str2id(pool, argv[2], 1), REL_ARCH, 1));
2811 else if (!strcmp(argv[1], "-t") || !strcmp(argv[1], "--type"))
2813 const char *kind = argv[2];
2814 if (!strcmp(kind, "srcpackage"))
2816 /* hey! should use --arch! */
2817 queue_push2(&archfilter, SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, 0, ARCH_SRC, REL_ARCH, 1));
2823 if (!strcmp(kind, "package"))
2825 if (!strcmp(kind, "all"))
2826 queue_push2(&kindfilter, SOLVER_SOLVABLE_ALL, 0);
2828 queue_push2(&kindfilter, SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, 0, pool_str2id(pool, kind, 1), REL_KIND, 1));
2836 if (mainmode == MODE_SEARCH)
2842 pool_createwhatprovides(pool);
2844 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2845 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2846 dataiterator_set_search(&di, 0, 0);
2847 while (dataiterator_step(&di))
2848 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2849 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2850 dataiterator_set_search(&di, 0, 0);
2851 while (dataiterator_step(&di))
2852 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2853 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2854 dataiterator_set_search(&di, 0, 0);
2855 while (dataiterator_step(&di))
2856 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2857 dataiterator_free(&di);
2858 if (repofilter.count)
2859 selection_filter(pool, &sel, &repofilter);
2862 selection_solvables(pool, &sel, &q);
2864 for (i = 0; i < q.count; i++)
2866 Solvable *s = pool_id2solvable(pool, q.elements[i]);
2867 printf(" - %s [%s]: %s\n", pool_solvable2str(pool, s), s->repo->name, solvable_lookup_str(s, SOLVABLE_SUMMARY));
2873 /* process command line packages */
2874 if (mainmode == MODE_LIST || mainmode == MODE_INFO || mainmode == MODE_INSTALL)
2876 for (i = 1; i < argc; i++)
2879 l = strlen(argv[i]);
2880 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2881 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2884 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2885 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2888 if (access(argv[i], R_OK))
2893 if (!commandlinepkgs)
2894 commandlinepkgs = solv_calloc(argc, sizeof(Id));
2895 if (!commandlinerepo)
2896 commandlinerepo = repo_create(pool, "@commandline");
2898 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2899 p = repo_add_rpm(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2901 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2902 p = repo_add_deb(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2906 fprintf(stderr, "could not add '%s'\n", argv[i]);
2909 commandlinepkgs[i] = p;
2911 if (commandlinerepo)
2912 repo_internalize(commandlinerepo);
2915 // FOR_REPOS(i, repo)
2916 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2918 #if defined(ENABLE_RPMDB)
2919 if (pool->disttype == DISTTYPE_RPM)
2920 addfileprovides(pool);
2922 pool_createwhatprovides(pool);
2925 keyname = solv_dupjoin("solvable:", keyname, 0);
2927 for (i = 1; i < argc; i++)
2930 int j, flags, rflags;
2932 if (commandlinepkgs && commandlinepkgs[i])
2934 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2938 flags = SELECTION_NAME|SELECTION_PROVIDES|SELECTION_GLOB;
2939 flags |= SELECTION_CANON|SELECTION_DOTARCH|SELECTION_REL;
2940 if (kindfilter.count)
2941 flags |= SELECTION_SKIP_KIND;
2942 if (mode == MODE_LIST || archfilter_src)
2943 flags |= SELECTION_WITH_SOURCE;
2944 if (argv[i][0] == '/')
2945 flags |= SELECTION_FILELIST | (mode == MODE_ERASE ? SELECTION_INSTALLED_ONLY : 0);
2947 rflags = selection_make(pool, &job2, argv[i], flags);
2949 rflags = selection_make_matchdeps(pool, &job2, argv[i], flags, pool_str2id(pool, keyname, 1), 0);
2950 if (repofilter.count)
2951 selection_filter(pool, &job2, &repofilter);
2952 if (archfilter.count)
2953 selection_filter(pool, &job2, &archfilter);
2954 if (kindfilter.count)
2955 selection_filter(pool, &job2, &kindfilter);
2958 flags |= SELECTION_NOCASE;
2960 rflags = selection_make(pool, &job2, argv[i], flags);
2962 rflags = selection_make_matchdeps(pool, &job2, argv[i], flags, pool_str2id(pool, keyname, 1), 0);
2963 if (repofilter.count)
2964 selection_filter(pool, &job2, &repofilter);
2965 if (archfilter.count)
2966 selection_filter(pool, &job2, &archfilter);
2967 if (kindfilter.count)
2968 selection_filter(pool, &job2, &kindfilter);
2970 printf("[ignoring case for '%s']\n", argv[i]);
2974 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2977 if (rflags & SELECTION_FILELIST)
2978 printf("[using file list match for '%s']\n", argv[i]);
2979 if (rflags & SELECTION_PROVIDES)
2980 printf("[using capability match for '%s']\n", argv[i]);
2981 for (j = 0; j < job2.count; j++)
2982 queue_push(&job, job2.elements[j]);
2985 keyname = solv_free(keyname);
2987 if (!job.count && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE || mainmode == MODE_VERIFY || repofilter.count || archfilter.count || kindfilter.count))
2989 queue_push2(&job, SOLVER_SOLVABLE_ALL, 0);
2990 if (repofilter.count)
2991 selection_filter(pool, &job, &repofilter);
2992 if (archfilter.count)
2993 selection_filter(pool, &job, &archfilter);
2994 if (kindfilter.count)
2995 selection_filter(pool, &job, &kindfilter);
2997 queue_free(&repofilter);
2998 queue_free(&archfilter);
2999 queue_free(&kindfilter);
3001 if (!job.count && mainmode != MODE_PATCH)
3003 printf("no package matched\n");
3007 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
3009 /* list mode, no solver needed */
3012 for (i = 0; i < job.count; i += 2)
3016 pool_job2solvables(pool, &q, job.elements[i], job.elements[i + 1]);
3017 for (j = 0; j < q.count; j++)
3019 Solvable *s = pool_id2solvable(pool, q.elements[j]);
3020 if (mainmode == MODE_INFO)
3023 printf("Name: %s\n", pool_solvable2str(pool, s));
3024 printf("Repo: %s\n", s->repo->name);
3025 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
3026 str = solvable_lookup_str(s, SOLVABLE_URL);
3028 printf("Url: %s\n", str);
3029 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
3031 printf("License: %s\n", str);
3033 str = solvable_lookup_sourcepkg(s);
3035 printf("Source: %s\n", str);
3037 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
3043 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
3045 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
3047 printf(" - %s [%s]\n", pool_solvable2str(pool, s), s->repo->name);
3049 printf(" %s\n", sum);
3056 free_repoinfos(repoinfos, nrepoinfos);
3057 solv_free(commandlinepkgs);
3059 yum_substitute(pool, 0);
3064 #if defined(SUSE) || defined(FEDORA)
3065 if (mainmode == MODE_PATCH)
3066 add_patchjobs(pool, &job);
3070 for (i = 0; i < job.count; i += 2)
3072 job.elements[i] |= mode;
3073 if (mode == SOLVER_UPDATE && pool_isemptyupdatejob(pool, job.elements[i], job.elements[i + 1]))
3074 job.elements[i] ^= SOLVER_UPDATE ^ SOLVER_INSTALL;
3076 job.elements[i] |= SOLVER_CLEANDEPS;
3078 job.elements[i] |= SOLVER_FORCEBEST;
3081 // multiversion test
3082 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae", 1));
3083 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-base", 1));
3084 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-extra", 1));
3086 queue_push2(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, NAMESPACE_LANGUAGE, 0, REL_NAMESPACE, 1));
3087 queue_push2(&job, SOLVER_ERASE|SOLVER_CLEANDEPS|SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, NAMESPACE_LANGUAGE, 0, REL_NAMESPACE, 1));
3090 #ifdef SOFTLOCKS_PATH
3091 addsoftlocks(pool, &job);
3094 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3097 solv = solver_create(pool);
3098 solver_set_flag(solv, SOLVER_FLAG_SPLITPROVIDES, 1);
3100 solver_set_flag(solv, SOLVER_FLAG_ALLOW_VENDORCHANGE, 1);
3102 if (mainmode == MODE_ERASE)
3103 solver_set_flag(solv, SOLVER_FLAG_ALLOW_UNINSTALL, 1); /* don't nag */
3104 solver_set_flag(solv, SOLVER_FLAG_BEST_OBEY_POLICY, 1);
3108 Id problem, solution;
3111 if (!solver_solve(solv, &job))
3113 pcnt = solver_problem_count(solv);
3114 printf("Found %d problems:\n", pcnt);
3115 for (problem = 1; problem <= pcnt; problem++)
3118 printf("Problem %d/%d:\n", problem, pcnt);
3119 solver_printprobleminfo(solv, problem);
3121 scnt = solver_solution_count(solv, problem);
3122 for (solution = 1; solution <= scnt; solution++)
3124 printf("Solution %d:\n", solution);
3125 solver_printsolution(solv, problem, solution);
3130 char inbuf[128], *ip;
3131 printf("Please choose a solution: ");
3134 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
3139 while (*ip == ' ' || *ip == '\t')
3141 if (*ip >= '0' && *ip <= '9')
3144 if (take >= 1 && take <= scnt)
3160 solver_take_solution(solv, problem, take, &job);
3164 trans = solver_create_transaction(solv);
3165 if (!trans->steps.count)
3167 printf("Nothing to do.\n");
3168 transaction_free(trans);
3172 free_repoinfos(repoinfos, nrepoinfos);
3173 solv_free(commandlinepkgs);
3175 yum_substitute(pool, 0);
3180 /* display transaction to the user and ask for confirmation */
3182 printf("Transaction summary:\n\n");
3183 transaction_print(trans);
3185 showdiskusagechanges(trans);
3187 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
3190 if (!yesno("OK to continue (y/n)? "))
3193 transaction_free(trans);
3197 free_repoinfos(repoinfos, nrepoinfos);
3198 solv_free(commandlinepkgs);
3200 yum_substitute(pool, 0);
3205 /* download all new packages */
3206 queue_init(&checkq);
3207 newpkgs = transaction_installedresult(trans, &checkq);
3211 int downloadsize = 0;
3212 for (i = 0; i < newpkgs; i++)
3216 p = checkq.elements[i];
3217 s = pool_id2solvable(pool, p);
3218 downloadsize += solvable_lookup_sizek(s, SOLVABLE_DOWNLOADSIZE, 0);
3220 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
3221 newpkgsfps = solv_calloc(newpkgs, sizeof(*newpkgsfps));
3222 for (i = 0; i < newpkgs; i++)
3224 unsigned int medianr;
3227 struct repoinfo *cinfo;
3228 const unsigned char *chksum;
3231 p = checkq.elements[i];
3232 s = pool_id2solvable(pool, p);
3233 if (s->repo == commandlinerepo)
3235 loc = solvable_lookup_location(s, &medianr);
3238 if (!(newpkgsfps[i] = fopen(loc, "r")))
3246 cinfo = s->repo->appdata;
3249 printf("%s: no repository information\n", s->repo->name);
3252 loc = solvable_lookup_location(s, &medianr);
3255 #if defined(ENABLE_RPMDB)
3256 if (pool->installed && pool->installed->nsolvables)
3258 if ((newpkgsfps[i] = trydeltadownload(s, cinfo, loc)) != 0)
3262 continue; /* delta worked! */
3266 #ifdef ENABLE_SUSEREPO
3267 if (cinfo->type == TYPE_SUSETAGS)
3269 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3270 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3274 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3275 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3277 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3286 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3287 /* check for file conflicts */
3291 struct fcstate fcstate;
3293 printf("Searching for file conflicts\n");
3294 queue_init(&conflicts);
3295 fcstate.rpmstate = rpm_state_create(pool, rootdir);
3296 fcstate.newpkgscnt = newpkgs;
3297 fcstate.checkq = &checkq;
3298 fcstate.newpkgsfps = newpkgsfps;
3299 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, FINDFILECONFLICTS_USE_SOLVABLEFILELIST | FINDFILECONFLICTS_CHECK_DIRALIASING | FINDFILECONFLICTS_USE_ROOTDIR, &fileconflict_cb, &fcstate);
3300 fcstate.rpmstate = rpm_state_free(fcstate.rpmstate);
3301 if (conflicts.count)
3304 for (i = 0; i < conflicts.count; i += 6)
3305 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]));
3307 if (yesno("Re-run solver (y/n/q)? "))
3309 for (i = 0; i < newpkgs; i++)
3311 fclose(newpkgsfps[i]);
3312 newpkgsfps = solv_free(newpkgsfps);
3315 pool_add_fileconflicts_deps(pool, &conflicts);
3319 queue_free(&conflicts);
3323 /* and finally commit the transaction */
3324 printf("Committing transaction:\n\n");
3325 transaction_order(trans, 0);
3326 for (i = 0; i < trans->steps.count; i++)
3328 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3329 const char *evr, *evrp, *nvra;
3336 p = trans->steps.elements[i];
3337 s = pool_id2solvable(pool, p);
3338 type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3341 case SOLVER_TRANSACTION_ERASE:
3342 printf("erase %s\n", pool_solvid2str(pool, p));
3343 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3344 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3346 /* strip epoch from evr */
3347 evr = evrp = pool_id2str(pool, s->evr);
3348 while (*evrp >= '0' && *evrp <= '9')
3350 if (evrp > evr && evrp[0] == ':' && evrp[1])
3352 nvra = pool_tmpjoin(pool, pool_id2str(pool, s->name), "-", evr);
3353 nvra = pool_tmpappend(pool, nvra, ".", pool_id2str(pool, s->arch));
3354 runrpm("-e", nvra, -1, rootdir); /* too bad that --querybynumber doesn't work */
3356 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3357 rundpkg("--remove", pool_id2str(pool, s->name), 0, rootdir);
3360 case SOLVER_TRANSACTION_INSTALL:
3361 case SOLVER_TRANSACTION_MULTIINSTALL:
3362 printf("install %s\n", pool_solvid2str(pool, p));
3363 for (j = 0; j < newpkgs; j++)
3364 if (checkq.elements[j] == p)
3366 fp = j < newpkgs ? newpkgsfps[j] : 0;
3370 lseek(fileno(fp), 0, SEEK_SET);
3371 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3372 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp), rootdir);
3374 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3375 rundpkg("--install", "/dev/fd/3", fileno(fp), rootdir);
3385 for (i = 0; i < newpkgs; i++)
3387 fclose(newpkgsfps[i]);
3388 solv_free(newpkgsfps);
3389 queue_free(&checkq);
3390 transaction_free(trans);
3394 free_repoinfos(repoinfos, nrepoinfos);
3395 solv_free(commandlinepkgs);
3397 yum_substitute(pool, 0);