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"
88 #include "repo_autopattern.h"
90 #include "solv_xfopen.h"
93 # define REPOINFO_PATH "/etc/yum.repos.d"
96 # define REPOINFO_PATH "/etc/zypp/repos.d"
97 # define PRODUCTS_PATH "/etc/products.d"
98 # define SOFTLOCKS_PATH "/var/lib/zypp/SoftLocks"
100 #ifdef ENABLE_APPDATA
101 # define APPDATA_PATH "/usr/share/appdata"
104 #define SOLVCACHE_PATH "/var/cache/solv"
106 #define METADATA_EXPIRE (60 * 15)
128 unsigned char cookie[32];
129 unsigned char extcookie[32];
135 yum_substitute(Pool *pool, char *line)
138 static char *releaseevr;
139 static char *basearch;
143 solv_free(releaseevr);
150 while ((p2 = strchr(p, '$')) != 0)
152 if (!strncmp(p2, "$releasever", 11))
160 rpmstate = rpm_state_create(pool, pool_get_rootdir(pool));
161 rpm_installedrpmdbids(rpmstate, "Providename", "redhat-release", &q);
166 handle = rpm_byrpmdbid(rpmstate, q.elements[0]);
167 releaseevr = handle ? rpm_query(handle, SOLVABLE_EVR) : 0;
168 if (releaseevr && (p = strchr(releaseevr, '-')) != 0)
171 rpm_state_free(rpmstate);
175 fprintf(stderr, "no installed package provides 'redhat-release', cannot determine $releasever\n");
180 p = pool_tmpjoin(pool, line, releaseevr, p2 + 11);
181 p2 = p + (p2 - line);
183 p = p2 + strlen(releaseevr);
186 if (!strncmp(p2, "$basearch", 9))
196 basearch = strdup(un.machine);
197 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
201 p = pool_tmpjoin(pool, line, basearch, p2 + 9);
202 p2 = p + (p2 - line);
204 p = p2 + strlen(basearch);
213 #define TYPE_UNKNOWN 0
214 #define TYPE_SUSETAGS 1
216 #define TYPE_PLAINDIR 3
217 #define TYPE_DEBIAN 4
221 read_repoinfos_sort(const void *ap, const void *bp)
223 const struct repoinfo *a = ap;
224 const struct repoinfo *b = bp;
225 return strcmp(a->alias, b->alias);
229 #if defined(SUSE) || defined(FEDORA)
232 read_repoinfos(Pool *pool, int *nrepoinfosp)
234 const char *reposdir = REPOINFO_PATH;
236 char buf2[4096], *kp, *vp, *kpe;
241 struct repoinfo *repoinfos = 0, *cinfo;
244 rdlen = strlen(reposdir);
245 dir = opendir(reposdir);
251 while ((ent = readdir(dir)) != 0)
253 if (ent->d_name[0] == '.')
255 l = strlen(ent->d_name);
256 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
258 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
259 if ((fp = fopen(buf, "r")) == 0)
265 while(fgets(buf2, sizeof(buf2), fp))
270 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
273 while (*kp == ' ' || *kp == '\t')
275 if (!*kp || *kp == '#')
279 kp = yum_substitute(pool, kp);
283 vp = strrchr(kp, ']');
287 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
288 cinfo = repoinfos + nrepoinfos++;
289 memset(cinfo, 0, sizeof(*cinfo));
290 cinfo->alias = strdup(kp + 1);
291 cinfo->type = TYPE_RPMMD;
292 cinfo->autorefresh = 1;
293 cinfo->priority = 99;
295 cinfo->repo_gpgcheck = 1;
297 cinfo->metadata_expire = METADATA_EXPIRE;
302 vp = strchr(kp, '=');
305 for (kpe = vp - 1; kpe >= kp; kpe--)
306 if (*kpe != ' ' && *kpe != '\t')
311 while (*vp == ' ' || *vp == '\t')
314 if (!strcmp(kp, "name"))
315 cinfo->name = strdup(vp);
316 else if (!strcmp(kp, "enabled"))
317 cinfo->enabled = *vp == '0' ? 0 : 1;
318 else if (!strcmp(kp, "autorefresh"))
319 cinfo->autorefresh = *vp == '0' ? 0 : 1;
320 else if (!strcmp(kp, "gpgcheck"))
321 cinfo->pkgs_gpgcheck = *vp == '0' ? 0 : 1;
322 else if (!strcmp(kp, "repo_gpgcheck"))
323 cinfo->repo_gpgcheck = *vp == '0' ? 0 : 1;
324 else if (!strcmp(kp, "baseurl"))
325 cinfo->baseurl = strdup(vp);
326 else if (!strcmp(kp, "mirrorlist"))
328 if (strstr(vp, "metalink"))
329 cinfo->metalink = strdup(vp);
331 cinfo->mirrorlist = strdup(vp);
333 else if (!strcmp(kp, "path"))
335 if (vp && strcmp(vp, "/") != 0)
336 cinfo->path = strdup(vp);
338 else if (!strcmp(kp, "type"))
340 if (!strcmp(vp, "yast2"))
341 cinfo->type = TYPE_SUSETAGS;
342 else if (!strcmp(vp, "rpm-md"))
343 cinfo->type = TYPE_RPMMD;
344 else if (!strcmp(vp, "plaindir"))
345 cinfo->type = TYPE_PLAINDIR;
347 cinfo->type = TYPE_UNKNOWN;
349 else if (!strcmp(kp, "priority"))
350 cinfo->priority = atoi(vp);
351 else if (!strcmp(kp, "keeppackages"))
352 cinfo->keeppackages = *vp == '0' ? 0 : 1;
358 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
359 *nrepoinfosp = nrepoinfos;
368 read_repoinfos(Pool *pool, int *nrepoinfosp)
374 char *kp, *url, *distro;
375 struct repoinfo *repoinfos = 0, *cinfo;
380 fp = fopen("/etc/apt/sources.list", "r");
387 dir = opendir("/etc/apt/sources.list.d");
391 if ((ent = readdir(dir)) == 0)
396 if (ent->d_name[0] == '.')
398 l = strlen(ent->d_name);
399 if (l < 5 || strcmp(ent->d_name + l - 5, ".list") != 0)
401 snprintf(buf, sizeof(buf), "%s/%s", "/etc/apt/sources.list.d", ent->d_name);
402 if (!(fp = fopen(buf, "r")))
405 while(fgets(buf2, sizeof(buf2), fp))
410 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
413 while (*kp == ' ' || *kp == '\t')
415 if (!*kp || *kp == '#')
417 if (strncmp(kp, "deb", 3) != 0)
420 if (*kp != ' ' && *kp != '\t')
422 while (*kp == ' ' || *kp == '\t')
427 while (*kp && *kp != ' ' && *kp != '\t')
431 while (*kp == ' ' || *kp == '\t')
436 while (*kp && *kp != ' ' && *kp != '\t')
440 while (*kp == ' ' || *kp == '\t')
444 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
445 cinfo = repoinfos + nrepoinfos++;
446 memset(cinfo, 0, sizeof(*cinfo));
447 cinfo->baseurl = strdup(url);
448 cinfo->alias = solv_dupjoin(url, "/", distro);
449 cinfo->name = strdup(distro);
450 cinfo->type = TYPE_DEBIAN;
452 cinfo->autorefresh = 1;
453 cinfo->repo_gpgcheck = 1;
454 cinfo->metadata_expire = METADATA_EXPIRE;
458 while (*kp == ' ' || *kp == '\t')
463 while (*kp && *kp != ' ' && *kp != '\t')
467 cinfo->components = solv_extend(cinfo->components, cinfo->ncomponents, 1, sizeof(*cinfo->components), 15);
468 cinfo->components[cinfo->ncomponents++] = strdup(compo);
474 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
475 *nrepoinfosp = nrepoinfos;
483 read_repoinfos(Pool *pool, int *nrepoinfosp)
492 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
495 for (i = 0; i < nrepoinfos; i++)
497 struct repoinfo *cinfo = repoinfos + i;
498 solv_free(cinfo->name);
499 solv_free(cinfo->alias);
500 solv_free(cinfo->path);
501 solv_free(cinfo->metalink);
502 solv_free(cinfo->mirrorlist);
503 solv_free(cinfo->baseurl);
504 for (j = 0; j < cinfo->ncomponents; j++)
505 solv_free(cinfo->components[j]);
506 solv_free(cinfo->components);
508 solv_free(repoinfos);
517 strcpy(tmpl, "/var/tmp/solvXXXXXX");
529 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
532 const unsigned char *sum;
536 h = solv_chksum_create(chksumtype);
539 printf("%s: unknown checksum type\n", file);
542 while ((l = read(fd, buf, sizeof(buf))) > 0)
543 solv_chksum_add(h, buf, l);
544 lseek(fd, 0, SEEK_SET);
546 sum = solv_chksum_get(h, &l);
547 if (memcmp(sum, chksum, l))
549 printf("%s: checksum mismatch\n", file);
550 solv_chksum_free(h, 0);
553 solv_chksum_free(h, 0);
558 findfastest(char **urls, int nurls)
565 struct addrinfo hints, *result;;
567 fds = solv_calloc(nurls, sizeof(*fds));
568 socks = solv_calloc(nurls, sizeof(*socks));
569 for (i = 0; i < nurls; i++)
572 p = strchr(urls[i], '/');
585 if ((p2 = strchr(p, '@')) != 0)
588 if (!strncmp("https:", urls[i], 6))
590 else if (!strncmp("ftp:", urls[i], 4))
592 if ((p2 = strrchr(p, ':')) != 0)
601 sprintf(portstr, "%d", port);
602 memset(&hints, 0, sizeof(struct addrinfo));
603 hints.ai_family = AF_UNSPEC;
604 hints.ai_socktype = SOCK_STREAM;
605 hints.ai_flags = AI_NUMERICSERV;
607 if (!getaddrinfo(p, portstr, &hints, &result))
609 socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
612 fcntl(socks[i], F_SETFL, O_NONBLOCK);
613 if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1)
615 if (errno != EINPROGRESS)
622 freeaddrinfo(result);
629 for (i = j = 0; i < nurls; i++)
633 fds[j].fd = socks[i];
634 fds[j].events = POLLOUT;
642 if (poll(fds, j, 10000) <= 0)
644 i = -1; /* something is wrong */
647 for (i = 0; i < j; i++)
648 if ((fds[i].revents & POLLOUT) != 0)
651 socklen_t soel = sizeof(int);
652 if (getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, &soe, &soel) == -1 || soe != 0)
654 /* connect failed, kill socket */
655 for (j = 0; j < nurls; j++)
656 if (socks[j] == fds[i].fd)
669 i = -1; /* something is wrong, no bit was set */
672 /* now i contains the fastest fd index */
675 for (j = 0; j < nurls; j++)
676 if (socks[j] == fds[i].fd)
680 char *url0 = urls[0];
685 for (i = j = 0; i < nurls; i++)
693 findmetalinkurl(FILE *fp, unsigned char *chksump, Id *chksumtypep)
695 char buf[4096], *bp, *ep;
702 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
704 while (*bp == ' ' || *bp == '\t')
706 if (chksumtypep && !*chksumtypep && !strncmp(bp, "<hash type=\"sha256\">", 20))
709 if (solv_hex2bin((const char **)&bp, chksump, 32) == 32)
710 *chksumtypep = REPOKEY_TYPE_SHA256;
713 if (strncmp(bp, "<url", 4))
715 bp = strchr(bp, '>');
719 ep = strstr(bp, "repodata/repomd.xml</url>");
723 if (strncmp(bp, "http", 4))
725 urls = solv_extend(urls, nurls, 1, sizeof(*urls), 15);
726 urls[nurls++] = strdup(bp);
731 findfastest(urls, nurls > 5 ? 5 : nurls);
734 for (i = 0; i < nurls; i++)
737 ep = strchr(bp, '/');
738 if ((ep = strchr(ep + 2, '/')) != 0)
741 printf("[using mirror %s]\n", bp);
750 findmirrorlisturl(FILE *fp)
752 char buf[4096], *bp, *ep;
757 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
759 while (*bp == ' ' || *bp == '\t')
761 if (!*bp || *bp == '#')
764 while (l > 0 && (bp[l - 1] == ' ' || bp[l - 1] == '\t' || bp[l - 1] == '\n'))
766 urls = solv_extend(urls, nurls, 1, sizeof(*urls), 15);
767 urls[nurls++] = strdup(bp);
772 findfastest(urls, nurls > 5 ? 5 : nurls);
775 for (i = 0; i < nurls; i++)
778 ep = strchr(bp, '/');
779 if ((ep = strchr(ep + 2, '/')) != 0)
782 printf("[using mirror %s]\n", bp);
791 iscompressed(const char *name)
793 return solv_xfopen_iscompressed(name) != 0;
797 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int markincomplete)
804 const char *baseurl = cinfo->baseurl;
808 if (!cinfo->metalink && !cinfo->mirrorlist)
810 if (file != cinfo->metalink && file != cinfo->mirrorlist)
812 unsigned char mlchksum[32];
814 fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
819 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
821 cinfo->baseurl = findmirrorlisturl(fp);
826 if (strchr(cinfo->baseurl, '$'))
828 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
829 free(cinfo->baseurl);
830 cinfo->baseurl = strdup(b);
833 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
835 chksumtype = mlchksumtype;
838 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, markincomplete);
840 snprintf(url, sizeof(url), "%s", file);
845 if (l && baseurl[l - 1] == '/')
846 snprintf(url, sizeof(url), "%s%s", baseurl, file);
848 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
851 // printf("url: %s\n", url);
852 if ((pid = fork()) == (pid_t)-1)
864 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
869 while (waitpid(pid, &status, 0) != pid)
871 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
877 lseek(fd, 0, SEEK_SET);
880 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
882 cinfo->incomplete = 1;
886 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
889 cinfo->incomplete = 1;
893 fcntl(fd, F_SETFD, FD_CLOEXEC);
896 if (solv_xfopen_iscompressed(file) < 0)
898 printf("%s: unsupported compression\n", file);
900 cinfo->incomplete = 1;
904 fp = solv_xfopen_fd(file, fd, "r");
907 fp = fdopen(fd, "r");
916 cleanupgpg(char *gpgdir)
919 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
921 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
923 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
925 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
927 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
933 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
942 off_t posfp, possigfp;
945 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
948 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
949 if (!(kfp = fopen(keysfile, "w")) )
955 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
959 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
960 if (!pubkey || !*pubkey)
962 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
964 if (fputc('\n', kfp) == EOF) /* Just in case... */
968 if (fclose(kfp) || !nkeys)
973 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
976 fprintf(stderr, "key import error\n");
981 posfp = lseek(fileno(fp), 0, SEEK_CUR);
982 lseek(fileno(fp), 0, SEEK_SET);
983 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
984 lseek(fileno(sigfp), 0, SEEK_SET);
985 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));
986 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
987 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
989 lseek(fileno(sigfp), possigfp, SEEK_SET);
990 lseek(fileno(fp), posfp, SEEK_SET);
991 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
992 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
994 return r == 0 ? 1 : 0;
1000 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
1005 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));
1006 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
1007 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
1009 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
1010 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
1011 return r == 0 ? 1 : 0;
1019 Pool *sigpool = pool_create();
1020 #if defined(ENABLE_PUBKEY) && defined(ENABLE_RPMDB)
1021 Repo *repo = repo_create(sigpool, "pubkeys");
1022 repo_add_rpmdb_pubkeys(repo, 0);
1028 downloadchecksig(struct repoinfo *cinfo, FILE *fp, const char *sigurl, Pool **sigpool)
1031 sigfp = curlfopen(cinfo, sigurl, 0, 0, 0, 0);
1034 printf(" unsigned, skipped\n");
1038 *sigpool = read_sigs();
1039 if (!checksig(*sigpool, fp, sigfp))
1041 printf(" checksig failed, skipped\n");
1049 #define CHKSUM_IDENT "1.1"
1052 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
1055 Chksum *h = solv_chksum_create(chktype);
1058 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1059 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
1060 solv_chksum_add(h, buf, l);
1062 solv_chksum_free(h, out);
1066 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *cookie, unsigned char *out)
1068 Chksum *h = solv_chksum_create(chktype);
1069 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1071 solv_chksum_add(h, cookie, 32);
1072 solv_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
1073 solv_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
1074 solv_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
1075 solv_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
1076 solv_chksum_free(h, out);
1088 pool_setarch(pool, un.machine);
1094 calccachepath(Repo *repo, const char *repoext, int forcesystemloc)
1098 if (!forcesystemloc && userhome && getuid())
1099 p = pool_tmpjoin(repo->pool, userhome, "/.solvcache/", 0);
1101 p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", 0);
1103 p = pool_tmpappend(repo->pool, p, repo->name, 0);
1106 p = pool_tmpappend(repo->pool, p, "_", repoext);
1107 p = pool_tmpappend(repo->pool, p, ".solvx", 0);
1110 p = pool_tmpappend(repo->pool, p, ".solv", 0);
1121 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1124 unsigned char mycookie[32];
1125 unsigned char myextcookie[32];
1126 struct repoinfo *cinfo;
1130 forcesystemloc = mark & 2 ? 0 : 1;
1131 if (mark < 2 && userhome && getuid())
1133 /* first try home location */
1134 int res = usecachedrepo(repo, repoext, cookie, mark | 2);
1139 cinfo = repo->appdata;
1140 if (!(fp = fopen(calccachepath(repo, repoext, forcesystemloc), "r")))
1142 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1147 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1152 if (cinfo && !repoext)
1154 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1165 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1166 if (strcmp(repoext, "DL") != 0)
1167 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1170 if (repo_add_solv(repo, fp, flags))
1175 if (cinfo && !repoext)
1177 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1178 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1181 futimens(fileno(fp), 0); /* try to set modification time */
1187 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1191 char *tmpl, *cachedir;
1192 struct repoinfo *cinfo;
1195 cinfo = repo->appdata;
1196 if (cinfo && cinfo->incomplete)
1198 cachedir = userhome && getuid() ? pool_tmpjoin(repo->pool, userhome, "/.solvcache", 0) : SOLVCACHE_PATH;
1199 if (access(cachedir, W_OK | X_OK) != 0 && mkdir(cachedir, 0755) == 0)
1200 printf("[created %s]\n", cachedir);
1201 /* use dupjoin instead of tmpjoin because tmpl must survive repo_write */
1202 tmpl = solv_dupjoin(cachedir, "/", ".newsolv-XXXXXX");
1210 if (!(fp = fdopen(fd, "w")))
1219 for (i = repo->start; i < repo->end; i++)
1220 if (repo->pool->solvables[i].repo != repo)
1226 repo_write(repo, fp);
1228 repodata_write(info, fp);
1231 int oldnrepodata = repo->nrepodata;
1232 repo->nrepodata = oldnrepodata > 2 ? 2 : oldnrepodata; /* XXX: do this right */
1233 repo_write(repo, fp);
1234 repo->nrepodata = oldnrepodata;
1238 if (!repoext && cinfo)
1240 if (!cinfo->extcookie[0])
1242 /* create the ext cookie and append it */
1243 /* we just need some unique ID */
1245 if (!fstat(fileno(fp), &stb))
1246 memset(&stb, 0, sizeof(stb));
1247 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cookie, cinfo->extcookie);
1248 if (cinfo->extcookie[0] == 0)
1249 cinfo->extcookie[0] = 1;
1251 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1259 /* append our cookie describing the metadata state */
1260 if (fwrite(cookie, 32, 1, fp) != 1)
1275 /* switch to just saved repo to activate paging and save memory */
1276 FILE *fp = fopen(tmpl, "r");
1282 repo_empty(repo, 1);
1283 if (repo_add_solv(repo, fp, SOLV_ADD_NO_STUBS))
1285 /* oops, no way to recover from here */
1286 fprintf(stderr, "internal error\n");
1292 int flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1293 /* make sure repodata contains complete repo */
1294 /* (this is how repodata_write saves it) */
1295 repodata_extend_block(info, repo->start, repo->end - repo->start);
1296 info->state = REPODATA_LOADING;
1297 if (strcmp(repoext, "DL") != 0)
1298 flags |= REPO_LOCALPOOL;
1299 repo_add_solv(repo, fp, flags);
1300 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1305 if (!rename(tmpl, calccachepath(repo, repoext, 0)))
1312 /* repomd helpers */
1314 static inline const char *
1315 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1317 Pool *pool = repo->pool;
1319 const char *filename;
1324 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1325 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1326 if (dataiterator_step(&di))
1328 dataiterator_setpos_parent(&di);
1329 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1330 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1332 dataiterator_free(&di);
1333 if (filename && !*chksumtypep)
1335 printf("no %s file checksum!\n", what);
1342 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1344 Id chksumtype, handle;
1345 const unsigned char *chksum;
1346 const char *filename;
1348 filename = repomd_find(repo, what, &chksum, &chksumtype);
1351 if (!strcmp(what, "prestodelta"))
1353 handle = repodata_new_handle(data);
1354 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1355 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1356 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1357 if (!strcmp(what, "deltainfo"))
1359 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1360 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1362 if (!strcmp(what, "filelists"))
1364 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1365 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1367 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1372 repomd_load_ext(Repo *repo, Repodata *data)
1374 const char *filename, *repomdtype;
1377 struct repoinfo *cinfo;
1378 const unsigned char *filechksum;
1382 cinfo = repo->appdata;
1383 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1386 if (!strcmp(repomdtype, "filelists"))
1388 else if (!strcmp(repomdtype, "deltainfo"))
1392 printf("[%s:%s", repo->name, ext);
1393 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1395 printf(" cached]\n"); fflush(stdout);
1398 printf(" fetching]\n"); fflush(stdout);
1399 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1401 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1402 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1404 if (!strcmp(ext, "FL"))
1405 r = repo_add_rpmmd(repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES|REPO_LOCALPOOL);
1406 else if (!strcmp(ext, "DL"))
1407 r = repo_add_deltainfoxml(repo, fp, REPO_USE_LOADING);
1411 printf("%s\n", pool_errstr(repo->pool));
1414 writecachedrepo(repo, data, ext, cinfo->extcookie);
1421 #ifdef ENABLE_SUSEREPO
1422 /* susetags helpers */
1424 static inline const char *
1425 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1427 Pool *pool = repo->pool;
1429 const char *filename;
1434 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
1435 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1436 if (dataiterator_step(&di))
1438 dataiterator_setpos_parent(&di);
1439 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
1442 dataiterator_free(&di);
1443 if (filename && !*chksumtypep)
1445 printf("no %s file checksum!\n", what);
1451 static Id susetags_langtags[] = {
1452 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
1453 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
1454 SOLVABLE_EULA, REPOKEY_TYPE_STR,
1455 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
1456 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
1457 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
1462 susetags_add_ext(Repo *repo, Repodata *data)
1464 Pool *pool = repo->pool;
1467 Id handle, filechksumtype;
1468 const unsigned char *filechksum;
1471 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
1472 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1473 while (dataiterator_step(&di))
1475 if (strncmp(di.kv.str, "packages.", 9) != 0)
1477 if (!strcmp(di.kv.str + 9, "gz"))
1479 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
1481 ext[0] = di.kv.str[9];
1482 ext[1] = di.kv.str[10];
1484 if (!strcmp(ext, "en"))
1486 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
1488 handle = repodata_new_handle(data);
1489 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
1491 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
1492 if (!strcmp(ext, "DU"))
1494 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
1495 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
1497 else if (!strcmp(ext, "FL"))
1499 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1500 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1504 for (i = 0; susetags_langtags[i]; i += 2)
1506 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
1507 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
1510 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1512 dataiterator_free(&di);
1516 susetags_load_ext(Repo *repo, Repodata *data)
1518 const char *filename, *descrdir;
1522 struct repoinfo *cinfo;
1523 const unsigned char *filechksum;
1527 cinfo = repo->appdata;
1528 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1532 ext[0] = filename[9];
1533 ext[1] = filename[10];
1535 printf("[%s:%s", repo->name, ext);
1536 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1538 printf(" cached]\n"); fflush(stdout);
1541 printf(" fetching]\n"); fflush(stdout);
1542 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1543 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1545 descrdir = "suse/setup/descr";
1547 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1548 if ((fp = curlfopen(cinfo, pool_tmpjoin(repo->pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1550 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1551 if (strcmp(ext, "DL") != 0)
1552 flags |= REPO_LOCALPOOL;
1553 if (repo_add_susetags(repo, fp, defvendor, ext, flags))
1556 printf("%s\n", pool_errstr(repo->pool));
1560 writecachedrepo(repo, data, ext, cinfo->extcookie);
1570 load_stub(Pool *pool, Repodata *data, void *dp)
1572 struct repoinfo *cinfo = data->repo->appdata;
1573 switch (cinfo->type)
1575 #ifdef ENABLE_SUSEREPO
1577 return susetags_load_ext(data->repo, data);
1581 return repomd_load_ext(data->repo, data);
1588 static unsigned char installedcookie[32];
1590 #ifdef ENABLE_DEBIAN
1593 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1597 unsigned char *chksum;
1602 static char *basearch;
1614 basearch = strdup(un.machine);
1615 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
1618 binarydir = solv_dupjoin("binary-", basearch, "/");
1619 lbinarydir = strlen(binarydir);
1620 compl = strlen(comp);
1624 chksum = solv_malloc(32);
1626 while(fgets(buf, sizeof(buf), fp))
1631 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1633 if (!strncasecmp(buf, "MD5Sum:", 7))
1635 curchksumtype = REPOKEY_TYPE_MD5;
1638 if (!strncasecmp(buf, "SHA1:", 5))
1640 curchksumtype = REPOKEY_TYPE_SHA1;
1643 if (!strncasecmp(buf, "SHA256:", 7))
1645 curchksumtype = REPOKEY_TYPE_SHA256;
1657 while (*bp && *bp != ' ' && *bp != '\t')
1662 while (*bp == ' ' || *bp == '\t')
1664 while (*bp && *bp != ' ' && *bp != '\t')
1668 while (*bp == ' ' || *bp == '\t')
1671 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1674 if (strncmp(bp, binarydir, lbinarydir))
1677 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1679 unsigned char curchksum[32];
1681 if (filename && !strcmp(bp, "Packages"))
1683 curl = solv_chksum_len(curchksumtype);
1684 if (!curl || (chksumtype && solv_chksum_len(chksumtype) > curl))
1686 if (solv_hex2bin((const char **)&ch, curchksum, sizeof(curchksum)) != curl)
1688 solv_free(filename);
1689 filename = strdup(fn);
1690 chksumtype = curchksumtype;
1691 memcpy(chksum, curchksum, curl);
1697 fn = solv_dupjoin("/", filename, 0);
1698 solv_free(filename);
1699 filename = solv_dupjoin("dists/", cinfo->name, fn);
1703 chksum = solv_free(chksum);
1705 *chksumtypep = chksumtype;
1711 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1714 struct repoinfo *cinfo;
1717 const char *filename;
1718 const unsigned char *filechksum;
1720 #ifdef ENABLE_SUSEREPO
1721 const char *descrdir;
1726 #if defined(ENABLE_SUSEREPO) || defined(ENABLE_RPMMD)
1730 #if defined(ENABLE_DEBIAN)
1735 repo = repo_create(pool, "@System");
1736 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1737 printf("rpm database:");
1738 if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/rpm/Packages"), &stb))
1739 memset(&stb, 0, sizeof(stb));
1741 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1742 printf("dpgk database:");
1743 if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/dpkg/status"), &stb))
1744 memset(&stb, 0, sizeof(stb));
1747 printf("no installed database:");
1748 memset(&stb, 0, sizeof(stb));
1750 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, 0, installedcookie);
1751 if (usecachedrepo(repo, 0, installedcookie, 0))
1752 printf(" cached\n");
1755 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1758 printf(" reading\n");
1760 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1761 # if defined(ENABLE_SUSEREPO) && defined(PRODUCTS_PATH)
1762 if (repo_add_products(repo, PRODUCTS_PATH, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
1764 fprintf(stderr, "product reading failed: %s\n", pool_errstr(pool));
1768 # if defined(ENABLE_APPDATA)
1769 if (repo_add_appdata_dir(repo, APPDATA_PATH, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
1771 fprintf(stderr, "appdata reading failed: %s\n", pool_errstr(pool));
1775 ofp = fopen(calccachepath(repo, 0, 0), "r");
1776 if (repo_add_rpmdb_reffp(repo, ofp, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
1778 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
1784 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1785 if (repo_add_debdb(repo, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
1787 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
1791 repo_internalize(repo);
1792 writecachedrepo(repo, 0, 0, installedcookie);
1794 pool_set_installed(pool, repo);
1796 for (i = 0; i < nrepoinfos; i++)
1798 cinfo = repoinfos + i;
1799 if (!cinfo->enabled)
1802 repo = repo_create(pool, cinfo->alias);
1804 repo->appdata = cinfo;
1805 repo->priority = 99 - cinfo->priority;
1807 dorefresh = cinfo->autorefresh;
1808 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0, 0), &stb) == 0)
1810 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1813 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1815 printf("repo '%s':", cinfo->alias);
1816 printf(" cached\n");
1819 switch (cinfo->type)
1823 printf("rpmmd repo '%s':", cinfo->alias);
1825 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1827 printf(" no repomd.xml file, skipped\n");
1832 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1833 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1835 printf(" cached\n");
1839 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "repodata/repomd.xml.asc", &sigpool))
1844 if (repo_add_repomdxml(repo, fp, 0))
1846 printf("repomd.xml: %s\n", pool_errstr(pool));
1848 break; /* hopeless */
1851 printf(" fetching\n");
1852 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1853 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1855 if (repo_add_rpmmd(repo, fp, 0, 0))
1857 printf("primary: %s\n", pool_errstr(pool));
1858 cinfo->incomplete = 1;
1862 if (cinfo->incomplete)
1863 break; /* hopeless */
1865 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1866 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1868 if (repo_add_updateinfoxml(repo, fp, 0))
1870 printf("updateinfo: %s\n", pool_errstr(pool));
1871 cinfo->incomplete = 1;
1876 #ifdef ENABLE_APPDATA
1877 filename = repomd_find(repo, "appdata", &filechksum, &filechksumtype);
1878 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1880 if (repo_add_appdata(repo, fp, 0))
1882 printf("appdata: %s\n", pool_errstr(pool));
1883 cinfo->incomplete = 1;
1888 data = repo_add_repodata(repo, 0);
1889 if (!repomd_add_ext(repo, data, "deltainfo"))
1890 repomd_add_ext(repo, data, "prestodelta");
1891 repomd_add_ext(repo, data, "filelists");
1892 repodata_internalize(data);
1893 if (!cinfo->incomplete)
1894 writecachedrepo(repo, 0, 0, cinfo->cookie);
1895 repodata_create_stubs(repo_last_repodata(repo));
1899 #ifdef ENABLE_SUSEREPO
1901 printf("susetags repo '%s':", cinfo->alias);
1905 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1907 printf(" no content file, skipped\n");
1912 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1913 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1915 printf(" cached\n");
1919 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "content.asc", &sigpool))
1924 if (repo_add_content(repo, fp, 0))
1926 printf("content: %s\n", pool_errstr(pool));
1928 break; /* hopeless */
1931 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1932 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1934 descrdir = "suse/setup/descr";
1935 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1937 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1940 printf(" no packages file entry, skipped\n");
1943 printf(" fetching\n");
1944 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) == 0)
1945 break; /* hopeless */
1946 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES))
1948 printf("packages: %s\n", pool_errstr(pool));
1950 cinfo->incomplete = 1;
1951 break; /* hopeless */
1954 /* add default language */
1955 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1957 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1960 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1962 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES))
1964 printf("packages.en: %s\n", pool_errstr(pool));
1965 cinfo->incomplete = 1;
1970 filename = susetags_find(repo, "patterns", &filechksum, &filechksumtype);
1973 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1976 while (fgets(pbuf, sizeof(pbuf), fp))
1978 int l = strlen(pbuf);
1980 if (l && pbuf[l - 1] == '\n')
1982 if (!*pbuf || *pbuf == '.' || strchr(pbuf, '/') != 0)
1984 filename = susetags_find(repo, pbuf, &filechksum, &filechksumtype);
1985 if (filename && (fp2 = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1987 if (repo_add_susetags(repo, fp2, defvendor, 0, REPO_NO_INTERNALIZE))
1989 printf("%s: %s\n", pbuf, pool_errstr(pool));
1990 cinfo->incomplete = 1;
1998 #ifdef ENABLE_APPDATA
1999 filename = susetags_find(repo, "appdata.xml.gz", &filechksum, &filechksumtype);
2001 filename = susetags_find(repo, "appdata.xml", &filechksum, &filechksumtype);
2002 if (filename && (fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
2004 if (repo_add_appdata(repo, fp, 0))
2006 printf("appdata: %s\n", pool_errstr(pool));
2007 cinfo->incomplete = 1;
2012 repo_internalize(repo);
2013 data = repo_add_repodata(repo, 0);
2014 susetags_add_ext(repo, data);
2015 repodata_internalize(data);
2016 if (!cinfo->incomplete)
2017 writecachedrepo(repo, 0, 0, cinfo->cookie);
2018 repodata_create_stubs(repo_last_repodata(repo));
2022 #if defined(ENABLE_DEBIAN)
2024 printf("debian repo '%s':", cinfo->alias);
2026 filename = solv_dupjoin("dists/", cinfo->name, "/Release");
2027 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
2029 printf(" no Release file, skipped\n");
2032 free((char *)filename);
2035 solv_free((char *)filename);
2036 if (cinfo->repo_gpgcheck)
2038 filename = solv_dupjoin("dists/", cinfo->name, "/Release.gpg");
2039 if (!downloadchecksig(cinfo, fpr, filename, &sigpool))
2042 solv_free((char *)filename);
2045 solv_free((char *)filename);
2047 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
2048 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
2050 printf(" cached\n");
2054 printf(" fetching\n");
2055 for (j = 0; j < cinfo->ncomponents; j++)
2057 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
2059 printf("[component %s not found]\n", cinfo->components[j]);
2062 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
2064 if (repo_add_debpackages(repo, fp, 0))
2066 printf("component %s: %s\n", cinfo->components[j], pool_errstr(pool));
2067 cinfo->incomplete = 1;
2071 solv_free((char *)filechksum);
2072 solv_free((char *)filename);
2075 if (!cinfo->incomplete)
2076 writecachedrepo(repo, 0, 0, cinfo->cookie);
2081 printf("unsupported repo '%s': skipped\n", cinfo->alias);
2092 yesno(const char *str)
2094 char inbuf[128], *ip;
2101 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2106 while (*ip == ' ' || *ip == '\t')
2113 if (*ip == 'y' || *ip == 'n')
2114 return *ip == 'y' ? 1 : 0;
2118 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2128 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2130 struct fcstate *fcstate = cbdata;
2136 s = pool_id2solvable(pool, p);
2137 if (pool->installed && s->repo == pool->installed)
2139 if (!s->repo->rpmdbid)
2141 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2144 return rpm_byrpmdbid(fcstate->rpmstate, rpmdbid);
2146 for (i = 0; i < fcstate->newpkgscnt; i++)
2147 if (fcstate->checkq->elements[i] == p)
2149 if (i == fcstate->newpkgscnt)
2151 fp = fcstate->newpkgsfps[i];
2155 return rpm_byfp(fcstate->rpmstate, fp, pool_solvable2str(pool, s));
2160 runrpm(const char *arg, const char *name, int dupfd3, const char *rootdir)
2165 if ((pid = fork()) == (pid_t)-1)
2174 if (dupfd3 != -1 && dupfd3 != 3)
2180 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2181 if (strcmp(arg, "-e") == 0)
2182 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2184 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2188 while (waitpid(pid, &status, 0) != pid)
2192 printf("rpm failed\n");
2199 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2202 rundpkg(const char *arg, const char *name, int dupfd3, const char *rootdir)
2207 if ((pid = fork()) == (pid_t)-1)
2216 if (dupfd3 != -1 && dupfd3 != 3)
2222 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2223 if (strcmp(arg, "--install") == 0)
2224 execlp("dpkg", "dpkg", "--install", "--root", rootdir, "--force", "all", name, (char *)0);
2226 execlp("dpkg", "dpkg", "--remove", "--root", rootdir, "--force", "all", name, (char *)0);
2230 while (waitpid(pid, &status, 0) != pid)
2234 printf("dpkg failed\n");
2243 nscallback(Pool *pool, void *data, Id name, Id evr)
2246 if (name == NAMESPACE_LANGUAGE)
2248 if (!strcmp(pool_id2str(pool, evr), "ja"))
2250 if (!strcmp(pool_id2str(pool, evr), "de"))
2252 if (!strcmp(pool_id2str(pool, evr), "en"))
2254 if (!strcmp(pool_id2str(pool, evr), "en_US"))
2262 #ifdef SOFTLOCKS_PATH
2264 addsoftlocks(Pool *pool, Queue *job)
2268 char *bp, *ep, buf[4096];
2270 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2272 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2274 while (*bp == ' ' || *bp == '\t')
2276 if (!*bp || *bp == '#')
2278 for (ep = bp; *ep; ep++)
2279 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2282 type = SOLVER_SOLVABLE_NAME;
2283 if (!strncmp(bp, "provides:", 9) && bp[9])
2285 type = SOLVER_SOLVABLE_PROVIDES;
2288 id = pool_str2id(pool, bp, 1);
2289 if (pool->installed)
2291 FOR_JOB_SELECT(p, pp, type, id)
2292 if (pool->solvables[p].repo == pool->installed)
2295 continue; /* ignore, as it is already installed */
2297 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2304 #if defined(ENABLE_RPMDB)
2307 rewrite_repos(Pool *pool, Queue *addedfileprovides, Queue *addedfileprovides_inst)
2312 Queue fileprovidesq;
2314 struct repoinfo *cinfo;
2316 map_init(&providedids, pool->ss.nstrings);
2317 queue_init(&fileprovidesq);
2318 for (i = 0; i < addedfileprovides->count; i++)
2319 MAPSET(&providedids, addedfileprovides->elements[i]);
2322 /* make sure all repodatas but the first are extensions */
2323 if (repo->nrepodata < 2)
2325 cinfo = repo->appdata;
2326 if (repo != pool->installed && !cinfo)
2328 if (cinfo && cinfo->incomplete)
2330 data = repo_id2repodata(repo, 1);
2331 if (data->loadcallback)
2333 for (j = 2; j < repo->nrepodata; j++)
2335 Repodata *edata = repo_id2repodata(repo, j);
2336 if (!edata->loadcallback)
2339 if (j < repo->nrepodata)
2340 continue; /* found a non-externsion repodata, can't rewrite */
2341 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2343 if (repo == pool->installed && addedfileprovides_inst)
2345 for (j = 0; j < addedfileprovides->count; j++)
2346 MAPCLR(&providedids, addedfileprovides->elements[j]);
2347 for (j = 0; j < addedfileprovides_inst->count; j++)
2348 MAPSET(&providedids, addedfileprovides_inst->elements[j]);
2351 for (j = 0; j < fileprovidesq.count; j++)
2352 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2354 if (repo == pool->installed && addedfileprovides_inst)
2356 for (j = 0; j < addedfileprovides_inst->count; j++)
2357 MAPCLR(&providedids, addedfileprovides_inst->elements[j]);
2358 for (j = 0; j < addedfileprovides->count; j++)
2359 MAPSET(&providedids, addedfileprovides->elements[j]);
2360 if (n == addedfileprovides_inst->count)
2361 continue; /* nothing new added */
2363 else if (n == addedfileprovides->count)
2364 continue; /* nothing new added */
2366 repodata_set_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, repo == pool->installed && addedfileprovides_inst ? addedfileprovides_inst : addedfileprovides);
2367 repodata_internalize(data);
2368 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2370 queue_free(&fileprovidesq);
2371 map_free(&providedids);
2375 addfileprovides(Pool *pool)
2377 Queue addedfileprovides;
2378 Queue addedfileprovides_inst;
2380 queue_init(&addedfileprovides);
2381 queue_init(&addedfileprovides_inst);
2382 pool_addfileprovides_queue(pool, &addedfileprovides, &addedfileprovides_inst);
2383 if (addedfileprovides.count || addedfileprovides_inst.count)
2384 rewrite_repos(pool, &addedfileprovides, &addedfileprovides_inst);
2385 queue_free(&addedfileprovides);
2386 queue_free(&addedfileprovides_inst);
2393 add_autopackages(Pool *pool)
2398 repo_add_autopattern(repo, 0);
2402 #if defined(SUSE) || defined(FEDORA)
2404 add_patchjobs(Pool *pool, Queue *job)
2408 Map installedmap, multiversionmap;
2411 map_init(&multiversionmap, 0);
2412 map_init(&installedmap, pool->nsolvables);
2413 solver_calculate_multiversionmap(pool, job, &multiversionmap);
2414 if (pool->installed)
2415 FOR_REPO_SOLVABLES(pool->installed, p, s)
2416 MAPSET(&installedmap, p);
2418 /* install all patches */
2419 for (p = 1; p < pool->nsolvables; p++)
2425 s = pool->solvables + p;
2426 if (strncmp(pool_id2str(pool, s->name), "patch:", 6) != 0)
2428 FOR_PROVIDES(p2, pp, s->name)
2430 Solvable *s2 = pool->solvables + p2;
2431 if (s2->name != s->name)
2433 r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2434 if (r < 0 || (r == 0 && p > p2))
2439 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2440 if (type && !strcmp(type, "optional"))
2442 r = solvable_trivial_installable_map(s, &installedmap, 0, &multiversionmap);
2445 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2452 queue_push2(job, SOLVER_SOLVABLE, p);
2454 map_free(&installedmap);
2455 map_free(&multiversionmap);
2461 showdiskusagechanges(Transaction *trans)
2466 /* XXX: use mountpoints here */
2468 duc[1].path = "/usr/share/man";
2469 duc[2].path = "/sbin";
2470 duc[3].path = "/etc";
2471 transaction_calc_duchanges(trans, duc, 4);
2472 for (i = 0; i < 4; i++)
2473 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
2477 #if defined(ENABLE_RPMDB)
2479 trydeltadownload(Solvable *s, struct repoinfo *cinfo, const char *loc)
2481 Pool *pool = s->repo->pool;
2484 const unsigned char *chksum;
2487 char *matchname = strdup(pool_id2str(pool, s->name));
2489 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
2490 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
2491 while (dataiterator_step(&di))
2495 dataiterator_setpos_parent(&di);
2496 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
2497 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
2499 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
2500 FOR_PROVIDES(op, pp, s->name)
2502 Solvable *os = pool->solvables + op;
2503 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
2506 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
2508 /* base is installed, run sequence check */
2511 const char *archstr;
2516 archstr = pool_id2str(pool, s->arch);
2517 if (strlen(archstr) > 10 || strchr(archstr, '\'') != 0)
2520 seq = pool_tmpjoin(pool, pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME), "-", pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR));
2521 seq = pool_tmpappend(pool, seq, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM));
2522 if (strchr(seq, '\'') != 0)
2525 sprintf(cmd, "/usr/bin/applydeltarpm -a '%s' -c -s '", archstr);
2527 sprintf(cmd, "/usr/bin/applydeltarpm -c -s '");
2529 if (system(pool_tmpjoin(pool, cmd, seq, "'")) != 0)
2530 continue; /* didn't match */
2531 /* looks good, download delta */
2533 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
2535 continue; /* no way! */
2536 dloc = pool_lookup_deltalocation(pool, SOLVID_POS, 0);
2539 #ifdef ENABLE_SUSEREPO
2540 if (cinfo->type == TYPE_SUSETAGS)
2542 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
2543 dloc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", dloc);
2546 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
2548 /* got it, now reconstruct */
2549 newfd = opentmpfile();
2551 sprintf(cmd, "applydeltarpm -a '%s' /dev/fd/%d /dev/fd/%d", archstr, fileno(fp), newfd);
2553 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
2555 fcntl(fileno(fp), F_SETFD, 0);
2562 lseek(newfd, 0, SEEK_SET);
2564 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
2565 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
2571 retfp = fdopen(newfd, "r");
2576 dataiterator_free(&di);
2577 solv_free(matchname);
2584 #define MODE_INSTALL 1
2585 #define MODE_ERASE 2
2586 #define MODE_UPDATE 3
2587 #define MODE_DISTUPGRADE 4
2588 #define MODE_VERIFY 5
2589 #define MODE_PATCH 6
2591 #define MODE_REPOLIST 8
2592 #define MODE_SEARCH 9
2597 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2598 fprintf(stderr, "\n");
2599 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2600 fprintf(stderr, " versions from the repositories\n");
2601 fprintf(stderr, " erase: erase installed packages\n");
2602 fprintf(stderr, " info: display package information\n");
2603 fprintf(stderr, " install: install packages\n");
2604 fprintf(stderr, " list: list packages\n");
2605 fprintf(stderr, " repos: list enabled repositories\n");
2606 fprintf(stderr, " search: search name/summary/description\n");
2607 fprintf(stderr, " update: update installed packages\n");
2608 fprintf(stderr, " verify: check dependencies of installed packages\n");
2609 #if defined(SUSE) || defined(FEDORA)
2610 fprintf(stderr, " patch: install newest patches\n");
2612 fprintf(stderr, "\n");
2617 main(int argc, char **argv)
2620 Repo *commandlinerepo = 0;
2621 Id *commandlinepkgs = 0;
2623 struct repoinfo *repoinfos;
2625 int mainmode = 0, mode = 0;
2634 int archfilter_src = 0;
2643 userhome = getenv("HOME");
2644 if (userhome && userhome[0] != '/')
2646 while (argc && !strcmp(argv[0], "-d"))
2654 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2656 mainmode = MODE_INSTALL;
2657 mode = SOLVER_INSTALL;
2659 #if defined(SUSE) || defined(FEDORA)
2660 else if (!strcmp(argv[0], "patch"))
2662 mainmode = MODE_PATCH;
2663 mode = SOLVER_INSTALL;
2666 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2668 mainmode = MODE_ERASE;
2669 mode = SOLVER_ERASE;
2671 else if (!strcmp(argv[0], "list") || !strcmp(argv[0], "ls"))
2673 mainmode = MODE_LIST;
2676 else if (!strcmp(argv[0], "info"))
2678 mainmode = MODE_INFO;
2681 else if (!strcmp(argv[0], "search") || !strcmp(argv[0], "se"))
2683 mainmode = MODE_SEARCH;
2686 else if (!strcmp(argv[0], "verify"))
2688 mainmode = MODE_VERIFY;
2689 mode = SOLVER_VERIFY;
2691 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2693 mainmode = MODE_UPDATE;
2694 mode = SOLVER_UPDATE;
2696 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2698 mainmode = MODE_DISTUPGRADE;
2699 mode = SOLVER_DISTUPGRADE;
2701 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2703 mainmode = MODE_REPOLIST;
2711 if (argc > 2 && !strcmp(argv[1], "--root"))
2717 else if (argc > 1 && !strcmp(argv[1], "--clean"))
2723 else if (argc > 1 && !strcmp(argv[1], "--best"))
2729 if (argc > 2 && !strcmp(argv[1], "--keyname"))
2739 pool = pool_create();
2740 pool_set_rootdir(pool, rootdir);
2744 const char *langs[] = {"de_DE", "de", "en"};
2745 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2749 pool_setloadcallback(pool, load_stub, 0);
2751 pool->nscallback = nscallback;
2754 pool_setdebuglevel(pool, debuglevel);
2756 pool_set_flag(pool, POOL_FLAG_ADDFILEPROVIDESFILTERED, 1);
2757 repoinfos = read_repoinfos(pool, &nrepoinfos);
2759 if (mainmode == MODE_REPOLIST)
2762 for (i = 0; i < nrepoinfos; i++)
2764 struct repoinfo *cinfo = repoinfos + i;
2765 if (!cinfo->enabled)
2767 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2772 read_repos(pool, repoinfos, nrepoinfos);
2775 queue_init(&repofilter);
2776 queue_init(&kindfilter);
2777 queue_init(&archfilter);
2780 if (!strcmp(argv[1], "-i"))
2782 queue_push2(&repofilter, SOLVER_SOLVABLE_REPO | SOLVER_SETREPO, pool->installed->repoid);
2786 else if (argc > 2 && (!strcmp(argv[1], "-r") || !strcmp(argv[1], "--repo")))
2788 const char *rname = argv[2], *rp;
2790 for (rp = rname; *rp; rp++)
2791 if (*rp <= '0' || *rp >= '9')
2795 /* repo specified by number */
2796 int rnum = atoi(rname);
2797 for (i = 0; i < nrepoinfos; i++)
2799 struct repoinfo *cinfo = repoinfos + i;
2800 if (!cinfo->enabled)
2803 repoid = cinfo->repo->repoid;
2808 /* repo specified by alias */
2812 if (!strcasecmp(rname, repo->name))
2813 repoid = repo->repoid;
2818 fprintf(stderr, "%s: no such repo\n", rname);
2821 /* SETVENDOR is actually wrong but useful */
2822 queue_push2(&repofilter, SOLVER_SOLVABLE_REPO | SOLVER_SETREPO | SOLVER_SETVENDOR, repoid);
2826 else if (argc > 2 && !strcmp(argv[1], "--arch"))
2828 if (!strcmp(argv[2], "src") || !strcmp(argv[2], "nosrc"))
2830 queue_push2(&archfilter, SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, 0, pool_str2id(pool, argv[2], 1), REL_ARCH, 1));
2834 else if (argc > 2 && (!strcmp(argv[1], "-t") || !strcmp(argv[1], "--type")))
2836 const char *kind = argv[2];
2837 if (!strcmp(kind, "srcpackage"))
2839 /* hey! should use --arch! */
2840 queue_push2(&archfilter, SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, 0, ARCH_SRC, REL_ARCH, 1));
2846 if (!strcmp(kind, "package"))
2848 if (!strcmp(kind, "all"))
2849 queue_push2(&kindfilter, SOLVER_SOLVABLE_ALL, 0);
2851 queue_push2(&kindfilter, SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, 0, pool_str2id(pool, kind, 1), REL_KIND, 1));
2859 if (mainmode == MODE_SEARCH)
2865 pool_createwhatprovides(pool);
2867 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2868 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2869 dataiterator_set_search(&di, 0, 0);
2870 while (dataiterator_step(&di))
2871 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2872 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2873 dataiterator_set_search(&di, 0, 0);
2874 while (dataiterator_step(&di))
2875 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2876 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2877 dataiterator_set_search(&di, 0, 0);
2878 while (dataiterator_step(&di))
2879 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2880 dataiterator_free(&di);
2881 if (repofilter.count)
2882 selection_filter(pool, &sel, &repofilter);
2885 selection_solvables(pool, &sel, &q);
2887 for (i = 0; i < q.count; i++)
2889 Solvable *s = pool_id2solvable(pool, q.elements[i]);
2890 printf(" - %s [%s]: %s\n", pool_solvable2str(pool, s), s->repo->name, solvable_lookup_str(s, SOLVABLE_SUMMARY));
2896 /* process command line packages */
2897 if (mainmode == MODE_LIST || mainmode == MODE_INFO || mainmode == MODE_INSTALL)
2899 for (i = 1; i < argc; i++)
2902 l = strlen(argv[i]);
2903 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2904 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2907 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2908 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2911 if (access(argv[i], R_OK))
2916 if (!commandlinepkgs)
2917 commandlinepkgs = solv_calloc(argc, sizeof(Id));
2918 if (!commandlinerepo)
2919 commandlinerepo = repo_create(pool, "@commandline");
2921 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2922 p = repo_add_rpm(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2924 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2925 p = repo_add_deb(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2929 fprintf(stderr, "could not add '%s'\n", argv[i]);
2932 commandlinepkgs[i] = p;
2934 if (commandlinerepo)
2935 repo_internalize(commandlinerepo);
2938 // FOR_REPOS(i, repo)
2939 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2941 #if defined(ENABLE_RPMDB)
2942 if (pool->disttype == DISTTYPE_RPM)
2943 addfileprovides(pool);
2946 add_autopackages(pool);
2948 pool_createwhatprovides(pool);
2951 keyname = solv_dupjoin("solvable:", keyname, 0);
2953 for (i = 1; i < argc; i++)
2956 int j, flags, rflags;
2958 if (commandlinepkgs && commandlinepkgs[i])
2960 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2964 flags = SELECTION_NAME|SELECTION_PROVIDES|SELECTION_GLOB;
2965 flags |= SELECTION_CANON|SELECTION_DOTARCH|SELECTION_REL;
2966 if (kindfilter.count)
2967 flags |= SELECTION_SKIP_KIND;
2968 if (mode == MODE_LIST || archfilter_src)
2969 flags |= SELECTION_WITH_SOURCE;
2970 if (argv[i][0] == '/')
2971 flags |= SELECTION_FILELIST | (mode == MODE_ERASE ? SELECTION_INSTALLED_ONLY : 0);
2973 rflags = selection_make(pool, &job2, argv[i], flags);
2975 rflags = selection_make_matchdeps(pool, &job2, argv[i], flags, pool_str2id(pool, keyname, 1), 0);
2976 if (repofilter.count)
2977 selection_filter(pool, &job2, &repofilter);
2978 if (archfilter.count)
2979 selection_filter(pool, &job2, &archfilter);
2980 if (kindfilter.count)
2981 selection_filter(pool, &job2, &kindfilter);
2984 flags |= SELECTION_NOCASE;
2986 rflags = selection_make(pool, &job2, argv[i], flags);
2988 rflags = selection_make_matchdeps(pool, &job2, argv[i], flags, pool_str2id(pool, keyname, 1), 0);
2989 if (repofilter.count)
2990 selection_filter(pool, &job2, &repofilter);
2991 if (archfilter.count)
2992 selection_filter(pool, &job2, &archfilter);
2993 if (kindfilter.count)
2994 selection_filter(pool, &job2, &kindfilter);
2996 printf("[ignoring case for '%s']\n", argv[i]);
3000 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
3003 if (rflags & SELECTION_FILELIST)
3004 printf("[using file list match for '%s']\n", argv[i]);
3005 if (rflags & SELECTION_PROVIDES)
3006 printf("[using capability match for '%s']\n", argv[i]);
3007 for (j = 0; j < job2.count; j++)
3008 queue_push(&job, job2.elements[j]);
3011 keyname = solv_free(keyname);
3013 if (!job.count && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE || mainmode == MODE_VERIFY || repofilter.count || archfilter.count || kindfilter.count))
3015 queue_push2(&job, SOLVER_SOLVABLE_ALL, 0);
3016 if (repofilter.count)
3017 selection_filter(pool, &job, &repofilter);
3018 if (archfilter.count)
3019 selection_filter(pool, &job, &archfilter);
3020 if (kindfilter.count)
3021 selection_filter(pool, &job, &kindfilter);
3023 queue_free(&repofilter);
3024 queue_free(&archfilter);
3025 queue_free(&kindfilter);
3027 if (!job.count && mainmode != MODE_PATCH)
3029 printf("no package matched\n");
3033 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
3035 /* list mode, no solver needed */
3038 for (i = 0; i < job.count; i += 2)
3042 pool_job2solvables(pool, &q, job.elements[i], job.elements[i + 1]);
3043 for (j = 0; j < q.count; j++)
3045 Solvable *s = pool_id2solvable(pool, q.elements[j]);
3046 if (mainmode == MODE_INFO)
3049 printf("Name: %s\n", pool_solvable2str(pool, s));
3050 printf("Repo: %s\n", s->repo->name);
3051 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
3052 str = solvable_lookup_str(s, SOLVABLE_URL);
3054 printf("Url: %s\n", str);
3055 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
3057 printf("License: %s\n", str);
3059 str = solvable_lookup_sourcepkg(s);
3061 printf("Source: %s\n", str);
3063 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
3069 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
3071 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
3073 printf(" - %s [%s]\n", pool_solvable2str(pool, s), s->repo->name);
3075 printf(" %s\n", sum);
3082 free_repoinfos(repoinfos, nrepoinfos);
3083 solv_free(commandlinepkgs);
3085 yum_substitute(pool, 0);
3090 #if defined(SUSE) || defined(FEDORA)
3091 if (mainmode == MODE_PATCH)
3092 add_patchjobs(pool, &job);
3096 for (i = 0; i < job.count; i += 2)
3098 job.elements[i] |= mode;
3099 if (mode == SOLVER_UPDATE && pool_isemptyupdatejob(pool, job.elements[i], job.elements[i + 1]))
3100 job.elements[i] ^= SOLVER_UPDATE ^ SOLVER_INSTALL;
3102 job.elements[i] |= SOLVER_CLEANDEPS;
3104 job.elements[i] |= SOLVER_FORCEBEST;
3107 // multiversion test
3108 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae", 1));
3109 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-base", 1));
3110 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-extra", 1));
3112 queue_push2(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, NAMESPACE_LANGUAGE, 0, REL_NAMESPACE, 1));
3113 queue_push2(&job, SOLVER_ERASE|SOLVER_CLEANDEPS|SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, NAMESPACE_LANGUAGE, 0, REL_NAMESPACE, 1));
3116 #ifdef SOFTLOCKS_PATH
3117 addsoftlocks(pool, &job);
3120 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3123 solv = solver_create(pool);
3124 solver_set_flag(solv, SOLVER_FLAG_SPLITPROVIDES, 1);
3126 solver_set_flag(solv, SOLVER_FLAG_ALLOW_VENDORCHANGE, 1);
3128 if (mainmode == MODE_ERASE)
3129 solver_set_flag(solv, SOLVER_FLAG_ALLOW_UNINSTALL, 1); /* don't nag */
3130 solver_set_flag(solv, SOLVER_FLAG_BEST_OBEY_POLICY, 1);
3134 Id problem, solution;
3137 if (!solver_solve(solv, &job))
3139 pcnt = solver_problem_count(solv);
3140 printf("Found %d problems:\n", pcnt);
3141 for (problem = 1; problem <= pcnt; problem++)
3144 printf("Problem %d/%d:\n", problem, pcnt);
3145 solver_printprobleminfo(solv, problem);
3147 scnt = solver_solution_count(solv, problem);
3148 for (solution = 1; solution <= scnt; solution++)
3150 printf("Solution %d:\n", solution);
3151 solver_printsolution(solv, problem, solution);
3156 char inbuf[128], *ip;
3157 printf("Please choose a solution: ");
3160 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
3165 while (*ip == ' ' || *ip == '\t')
3167 if (*ip >= '0' && *ip <= '9')
3170 if (take >= 1 && take <= scnt)
3186 solver_take_solution(solv, problem, take, &job);
3190 trans = solver_create_transaction(solv);
3191 if (!trans->steps.count)
3193 printf("Nothing to do.\n");
3194 transaction_free(trans);
3198 free_repoinfos(repoinfos, nrepoinfos);
3199 solv_free(commandlinepkgs);
3201 yum_substitute(pool, 0);
3206 /* display transaction to the user and ask for confirmation */
3208 printf("Transaction summary:\n\n");
3209 transaction_print(trans);
3211 showdiskusagechanges(trans);
3213 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
3216 if (!yesno("OK to continue (y/n)? "))
3219 transaction_free(trans);
3223 free_repoinfos(repoinfos, nrepoinfos);
3224 solv_free(commandlinepkgs);
3226 yum_substitute(pool, 0);
3231 /* download all new packages */
3232 queue_init(&checkq);
3233 newpkgs = transaction_installedresult(trans, &checkq);
3237 int downloadsize = 0;
3238 for (i = 0; i < newpkgs; i++)
3242 p = checkq.elements[i];
3243 s = pool_id2solvable(pool, p);
3244 downloadsize += solvable_lookup_sizek(s, SOLVABLE_DOWNLOADSIZE, 0);
3246 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
3247 newpkgsfps = solv_calloc(newpkgs, sizeof(*newpkgsfps));
3248 for (i = 0; i < newpkgs; i++)
3250 unsigned int medianr;
3253 struct repoinfo *cinfo;
3254 const unsigned char *chksum;
3257 p = checkq.elements[i];
3258 s = pool_id2solvable(pool, p);
3259 if (s->repo == commandlinerepo)
3261 loc = solvable_lookup_location(s, &medianr);
3264 if (!(newpkgsfps[i] = fopen(loc, "r")))
3272 cinfo = s->repo->appdata;
3275 printf("%s: no repository information\n", s->repo->name);
3278 loc = solvable_lookup_location(s, &medianr);
3281 #if defined(ENABLE_RPMDB)
3282 if (pool->installed && pool->installed->nsolvables)
3284 if ((newpkgsfps[i] = trydeltadownload(s, cinfo, loc)) != 0)
3288 continue; /* delta worked! */
3292 #ifdef ENABLE_SUSEREPO
3293 if (cinfo->type == TYPE_SUSETAGS)
3295 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3296 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3300 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3301 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3303 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3312 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3313 /* check for file conflicts */
3317 struct fcstate fcstate;
3319 printf("Searching for file conflicts\n");
3320 queue_init(&conflicts);
3321 fcstate.rpmstate = rpm_state_create(pool, rootdir);
3322 fcstate.newpkgscnt = newpkgs;
3323 fcstate.checkq = &checkq;
3324 fcstate.newpkgsfps = newpkgsfps;
3325 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, FINDFILECONFLICTS_USE_SOLVABLEFILELIST | FINDFILECONFLICTS_CHECK_DIRALIASING | FINDFILECONFLICTS_USE_ROOTDIR, &fileconflict_cb, &fcstate);
3326 fcstate.rpmstate = rpm_state_free(fcstate.rpmstate);
3327 if (conflicts.count)
3330 for (i = 0; i < conflicts.count; i += 6)
3331 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]));
3333 if (yesno("Re-run solver (y/n/q)? "))
3335 for (i = 0; i < newpkgs; i++)
3337 fclose(newpkgsfps[i]);
3338 newpkgsfps = solv_free(newpkgsfps);
3341 pool_add_fileconflicts_deps(pool, &conflicts);
3345 queue_free(&conflicts);
3349 /* and finally commit the transaction */
3350 printf("Committing transaction:\n\n");
3351 transaction_order(trans, 0);
3352 for (i = 0; i < trans->steps.count; i++)
3354 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3355 const char *evr, *evrp, *nvra;
3362 p = trans->steps.elements[i];
3363 s = pool_id2solvable(pool, p);
3364 type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3367 case SOLVER_TRANSACTION_ERASE:
3368 printf("erase %s\n", pool_solvid2str(pool, p));
3369 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3370 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3372 /* strip epoch from evr */
3373 evr = evrp = pool_id2str(pool, s->evr);
3374 while (*evrp >= '0' && *evrp <= '9')
3376 if (evrp > evr && evrp[0] == ':' && evrp[1])
3378 nvra = pool_tmpjoin(pool, pool_id2str(pool, s->name), "-", evr);
3379 nvra = pool_tmpappend(pool, nvra, ".", pool_id2str(pool, s->arch));
3380 runrpm("-e", nvra, -1, rootdir); /* too bad that --querybynumber doesn't work */
3382 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3383 rundpkg("--remove", pool_id2str(pool, s->name), 0, rootdir);
3386 case SOLVER_TRANSACTION_INSTALL:
3387 case SOLVER_TRANSACTION_MULTIINSTALL:
3388 printf("install %s\n", pool_solvid2str(pool, p));
3389 for (j = 0; j < newpkgs; j++)
3390 if (checkq.elements[j] == p)
3392 fp = j < newpkgs ? newpkgsfps[j] : 0;
3396 lseek(fileno(fp), 0, SEEK_SET);
3397 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3398 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp), rootdir);
3400 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3401 rundpkg("--install", "/dev/fd/3", fileno(fp), rootdir);
3411 for (i = 0; i < newpkgs; i++)
3413 fclose(newpkgsfps[i]);
3414 solv_free(newpkgsfps);
3415 queue_free(&checkq);
3416 transaction_free(trans);
3420 free_repoinfos(repoinfos, nrepoinfos);
3421 solv_free(commandlinepkgs);
3423 yum_substitute(pool, 0);