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
220 read_repoinfos_sort(const void *ap, const void *bp)
222 const struct repoinfo *a = ap;
223 const struct repoinfo *b = bp;
224 return strcmp(a->alias, b->alias);
227 #if defined(SUSE) || defined(FEDORA)
230 read_repoinfos(Pool *pool, int *nrepoinfosp)
232 const char *reposdir = REPOINFO_PATH;
234 char buf2[4096], *kp, *vp, *kpe;
239 struct repoinfo *repoinfos = 0, *cinfo;
242 rdlen = strlen(reposdir);
243 dir = opendir(reposdir);
249 while ((ent = readdir(dir)) != 0)
251 if (ent->d_name[0] == '.')
253 l = strlen(ent->d_name);
254 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
256 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
257 if ((fp = fopen(buf, "r")) == 0)
263 while(fgets(buf2, sizeof(buf2), fp))
268 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
271 while (*kp == ' ' || *kp == '\t')
273 if (!*kp || *kp == '#')
277 kp = yum_substitute(pool, kp);
281 vp = strrchr(kp, ']');
285 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
286 cinfo = repoinfos + nrepoinfos++;
287 memset(cinfo, 0, sizeof(*cinfo));
288 cinfo->alias = strdup(kp + 1);
289 cinfo->type = TYPE_RPMMD;
290 cinfo->autorefresh = 1;
291 cinfo->priority = 99;
293 cinfo->repo_gpgcheck = 1;
295 cinfo->metadata_expire = METADATA_EXPIRE;
300 vp = strchr(kp, '=');
303 for (kpe = vp - 1; kpe >= kp; kpe--)
304 if (*kpe != ' ' && *kpe != '\t')
309 while (*vp == ' ' || *vp == '\t')
312 if (!strcmp(kp, "name"))
313 cinfo->name = strdup(vp);
314 else if (!strcmp(kp, "enabled"))
315 cinfo->enabled = *vp == '0' ? 0 : 1;
316 else if (!strcmp(kp, "autorefresh"))
317 cinfo->autorefresh = *vp == '0' ? 0 : 1;
318 else if (!strcmp(kp, "gpgcheck"))
319 cinfo->pkgs_gpgcheck = *vp == '0' ? 0 : 1;
320 else if (!strcmp(kp, "repo_gpgcheck"))
321 cinfo->repo_gpgcheck = *vp == '0' ? 0 : 1;
322 else if (!strcmp(kp, "baseurl"))
323 cinfo->baseurl = strdup(vp);
324 else if (!strcmp(kp, "mirrorlist"))
326 if (strstr(vp, "metalink"))
327 cinfo->metalink = strdup(vp);
329 cinfo->mirrorlist = strdup(vp);
331 else if (!strcmp(kp, "path"))
333 if (vp && strcmp(vp, "/") != 0)
334 cinfo->path = strdup(vp);
336 else if (!strcmp(kp, "type"))
338 if (!strcmp(vp, "yast2"))
339 cinfo->type = TYPE_SUSETAGS;
340 else if (!strcmp(vp, "rpm-md"))
341 cinfo->type = TYPE_RPMMD;
342 else if (!strcmp(vp, "plaindir"))
343 cinfo->type = TYPE_PLAINDIR;
345 cinfo->type = TYPE_UNKNOWN;
347 else if (!strcmp(kp, "priority"))
348 cinfo->priority = atoi(vp);
349 else if (!strcmp(kp, "keeppackages"))
350 cinfo->keeppackages = *vp == '0' ? 0 : 1;
356 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
357 *nrepoinfosp = nrepoinfos;
366 read_repoinfos(Pool *pool, int *nrepoinfosp)
372 char *kp, *url, *distro;
373 struct repoinfo *repoinfos = 0, *cinfo;
378 fp = fopen("/etc/apt/sources.list", "r");
385 dir = opendir("/etc/apt/sources.list.d");
389 if ((ent = readdir(dir)) == 0)
394 if (ent->d_name[0] == '.')
396 l = strlen(ent->d_name);
397 if (l < 5 || strcmp(ent->d_name + l - 5, ".list") != 0)
399 snprintf(buf, sizeof(buf), "%s/%s", "/etc/apt/sources.list.d", ent->d_name);
400 if (!(fp = fopen(buf, "r")))
403 while(fgets(buf2, sizeof(buf2), fp))
408 while (l && (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t'))
411 while (*kp == ' ' || *kp == '\t')
413 if (!*kp || *kp == '#')
415 if (strncmp(kp, "deb", 3) != 0)
418 if (*kp != ' ' && *kp != '\t')
420 while (*kp == ' ' || *kp == '\t')
425 while (*kp && *kp != ' ' && *kp != '\t')
429 while (*kp == ' ' || *kp == '\t')
434 while (*kp && *kp != ' ' && *kp != '\t')
438 while (*kp == ' ' || *kp == '\t')
442 repoinfos = solv_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
443 cinfo = repoinfos + nrepoinfos++;
444 memset(cinfo, 0, sizeof(*cinfo));
445 cinfo->baseurl = strdup(url);
446 cinfo->alias = solv_dupjoin(url, "/", distro);
447 cinfo->name = strdup(distro);
448 cinfo->type = TYPE_DEBIAN;
450 cinfo->autorefresh = 1;
451 cinfo->repo_gpgcheck = 1;
452 cinfo->metadata_expire = METADATA_EXPIRE;
456 while (*kp == ' ' || *kp == '\t')
461 while (*kp && *kp != ' ' && *kp != '\t')
465 cinfo->components = solv_extend(cinfo->components, cinfo->ncomponents, 1, sizeof(*cinfo->components), 15);
466 cinfo->components[cinfo->ncomponents++] = strdup(compo);
472 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
473 *nrepoinfosp = nrepoinfos;
481 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
484 for (i = 0; i < nrepoinfos; i++)
486 struct repoinfo *cinfo = repoinfos + i;
487 solv_free(cinfo->name);
488 solv_free(cinfo->alias);
489 solv_free(cinfo->path);
490 solv_free(cinfo->metalink);
491 solv_free(cinfo->mirrorlist);
492 solv_free(cinfo->baseurl);
493 for (j = 0; j < cinfo->ncomponents; j++)
494 solv_free(cinfo->components[j]);
495 solv_free(cinfo->components);
497 solv_free(repoinfos);
506 strcpy(tmpl, "/var/tmp/solvXXXXXX");
518 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
521 const unsigned char *sum;
525 h = solv_chksum_create(chksumtype);
528 printf("%s: unknown checksum type\n", file);
531 while ((l = read(fd, buf, sizeof(buf))) > 0)
532 solv_chksum_add(h, buf, l);
533 lseek(fd, 0, SEEK_SET);
535 sum = solv_chksum_get(h, &l);
536 if (memcmp(sum, chksum, l))
538 printf("%s: checksum mismatch\n", file);
539 solv_chksum_free(h, 0);
542 solv_chksum_free(h, 0);
547 findfastest(char **urls, int nurls)
554 struct addrinfo hints, *result;;
556 fds = solv_calloc(nurls, sizeof(*fds));
557 socks = solv_calloc(nurls, sizeof(*socks));
558 for (i = 0; i < nurls; i++)
561 p = strchr(urls[i], '/');
574 if ((p2 = strchr(p, '@')) != 0)
577 if (!strncmp("https:", urls[i], 6))
579 else if (!strncmp("ftp:", urls[i], 4))
581 if ((p2 = strrchr(p, ':')) != 0)
590 sprintf(portstr, "%d", port);
591 memset(&hints, 0, sizeof(struct addrinfo));
592 hints.ai_family = AF_UNSPEC;
593 hints.ai_socktype = SOCK_STREAM;
594 hints.ai_flags = AI_NUMERICSERV;
596 if (!getaddrinfo(p, portstr, &hints, &result))
598 socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
601 fcntl(socks[i], F_SETFL, O_NONBLOCK);
602 if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1)
604 if (errno != EINPROGRESS)
611 freeaddrinfo(result);
618 for (i = j = 0; i < nurls; i++)
622 fds[j].fd = socks[i];
623 fds[j].events = POLLOUT;
631 if (poll(fds, j, 10000) <= 0)
633 i = -1; /* something is wrong */
636 for (i = 0; i < j; i++)
637 if ((fds[i].revents & POLLOUT) != 0)
640 socklen_t soel = sizeof(int);
641 if (getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, &soe, &soel) == -1 || soe != 0)
643 /* connect failed, kill socket */
644 for (j = 0; j < nurls; j++)
645 if (socks[j] == fds[i].fd)
658 i = -1; /* something is wrong, no bit was set */
661 /* now i contains the fastest fd index */
664 for (j = 0; j < nurls; j++)
665 if (socks[j] == fds[i].fd)
669 char *url0 = urls[0];
674 for (i = j = 0; i < nurls; i++)
682 findmetalinkurl(FILE *fp, unsigned char *chksump, Id *chksumtypep)
684 char buf[4096], *bp, *ep;
691 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
693 while (*bp == ' ' || *bp == '\t')
695 if (chksumtypep && !*chksumtypep && !strncmp(bp, "<hash type=\"sha256\">", 20))
698 if (solv_hex2bin((const char **)&bp, chksump, 32) == 32)
699 *chksumtypep = REPOKEY_TYPE_SHA256;
702 if (strncmp(bp, "<url", 4))
704 bp = strchr(bp, '>');
708 ep = strstr(bp, "repodata/repomd.xml</url>");
712 if (strncmp(bp, "http", 4))
714 urls = solv_extend(urls, nurls, 1, sizeof(*urls), 15);
715 urls[nurls++] = strdup(bp);
720 findfastest(urls, nurls > 5 ? 5 : nurls);
723 for (i = 0; i < nurls; i++)
726 ep = strchr(bp, '/');
727 if ((ep = strchr(ep + 2, '/')) != 0)
730 printf("[using mirror %s]\n", bp);
739 findmirrorlisturl(FILE *fp)
741 char buf[4096], *bp, *ep;
746 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
748 while (*bp == ' ' || *bp == '\t')
750 if (!*bp || *bp == '#')
753 while (l > 0 && (bp[l - 1] == ' ' || bp[l - 1] == '\t' || bp[l - 1] == '\n'))
755 urls = solv_extend(urls, nurls, 1, sizeof(*urls), 15);
756 urls[nurls++] = strdup(bp);
761 findfastest(urls, nurls > 5 ? 5 : nurls);
764 for (i = 0; i < nurls; i++)
767 ep = strchr(bp, '/');
768 if ((ep = strchr(ep + 2, '/')) != 0)
771 printf("[using mirror %s]\n", bp);
780 iscompressed(const char *name)
782 return solv_xfopen_iscompressed(name) != 0;
786 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int markincomplete)
793 const char *baseurl = cinfo->baseurl;
797 if (!cinfo->metalink && !cinfo->mirrorlist)
799 if (file != cinfo->metalink && file != cinfo->mirrorlist)
801 unsigned char mlchksum[32];
803 fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
808 cinfo->baseurl = findmetalinkurl(fp, mlchksum, &mlchksumtype);
810 cinfo->baseurl = findmirrorlisturl(fp);
815 if (strchr(cinfo->baseurl, '$'))
817 char *b = yum_substitute(cinfo->repo->pool, cinfo->baseurl);
818 free(cinfo->baseurl);
819 cinfo->baseurl = strdup(b);
822 if (!chksumtype && mlchksumtype && !strcmp(file, "repodata/repomd.xml"))
824 chksumtype = mlchksumtype;
827 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, markincomplete);
829 snprintf(url, sizeof(url), "%s", file);
834 if (l && baseurl[l - 1] == '/')
835 snprintf(url, sizeof(url), "%s%s", baseurl, file);
837 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
840 // printf("url: %s\n", url);
841 if ((pid = fork()) == (pid_t)-1)
853 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
858 while (waitpid(pid, &status, 0) != pid)
860 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
866 lseek(fd, 0, SEEK_SET);
869 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
871 cinfo->incomplete = 1;
875 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
878 cinfo->incomplete = 1;
882 fcntl(fd, F_SETFD, FD_CLOEXEC);
885 if (solv_xfopen_iscompressed(file) < 0)
887 printf("%s: unsupported compression\n", file);
889 cinfo->incomplete = 1;
893 fp = solv_xfopen_fd(file, fd, "r");
896 fp = fdopen(fd, "r");
905 cleanupgpg(char *gpgdir)
908 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
910 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
912 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
914 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
916 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
922 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
931 off_t posfp, possigfp;
934 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
937 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
938 if (!(kfp = fopen(keysfile, "w")) )
944 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
948 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
949 if (!pubkey || !*pubkey)
951 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
953 if (fputc('\n', kfp) == EOF) /* Just in case... */
957 if (fclose(kfp) || !nkeys)
962 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
965 fprintf(stderr, "key import error\n");
970 posfp = lseek(fileno(fp), 0, SEEK_CUR);
971 lseek(fileno(fp), 0, SEEK_SET);
972 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
973 lseek(fileno(sigfp), 0, SEEK_SET);
974 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));
975 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
976 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
978 lseek(fileno(sigfp), possigfp, SEEK_SET);
979 lseek(fileno(fp), posfp, SEEK_SET);
980 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
981 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
983 return r == 0 ? 1 : 0;
989 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
994 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));
995 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
996 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
998 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
999 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
1000 return r == 0 ? 1 : 0;
1008 Pool *sigpool = pool_create();
1009 #if defined(ENABLE_PUBKEY) && defined(ENABLE_RPMDB)
1010 Repo *repo = repo_create(sigpool, "pubkeys");
1011 repo_add_rpmdb_pubkeys(repo, 0);
1017 downloadchecksig(struct repoinfo *cinfo, FILE *fp, const char *sigurl, Pool **sigpool)
1020 sigfp = curlfopen(cinfo, sigurl, 0, 0, 0, 0);
1023 printf(" unsigned, skipped\n");
1027 *sigpool = read_sigs();
1028 if (!checksig(*sigpool, fp, sigfp))
1030 printf(" checksig failed, skipped\n");
1038 #define CHKSUM_IDENT "1.1"
1041 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
1044 Chksum *h = solv_chksum_create(chktype);
1047 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1048 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
1049 solv_chksum_add(h, buf, l);
1051 solv_chksum_free(h, out);
1055 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *cookie, unsigned char *out)
1057 Chksum *h = solv_chksum_create(chktype);
1058 solv_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
1060 solv_chksum_add(h, cookie, 32);
1061 solv_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
1062 solv_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
1063 solv_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
1064 solv_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
1065 solv_chksum_free(h, out);
1077 pool_setarch(pool, un.machine);
1083 calccachepath(Repo *repo, const char *repoext, int forcesystemloc)
1087 if (!forcesystemloc && userhome && getuid())
1088 p = pool_tmpjoin(repo->pool, userhome, "/.solvcache/", 0);
1090 p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", 0);
1092 p = pool_tmpappend(repo->pool, p, repo->name, 0);
1095 p = pool_tmpappend(repo->pool, p, "_", repoext);
1096 p = pool_tmpappend(repo->pool, p, ".solvx", 0);
1099 p = pool_tmpappend(repo->pool, p, ".solv", 0);
1110 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
1113 unsigned char mycookie[32];
1114 unsigned char myextcookie[32];
1115 struct repoinfo *cinfo;
1119 forcesystemloc = mark & 2 ? 0 : 1;
1120 if (mark < 2 && userhome && getuid())
1122 /* first try home location */
1123 int res = usecachedrepo(repo, repoext, cookie, mark | 2);
1128 cinfo = repo->appdata;
1129 if (!(fp = fopen(calccachepath(repo, repoext, forcesystemloc), "r")))
1131 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
1136 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
1141 if (cinfo && !repoext)
1143 if (fseek(fp, -sizeof(mycookie) * 2, SEEK_END) || fread(myextcookie, sizeof(myextcookie), 1, fp) != 1)
1154 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1155 if (strcmp(repoext, "DL") != 0)
1156 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
1159 if (repo_add_solv(repo, fp, flags))
1164 if (cinfo && !repoext)
1166 memcpy(cinfo->cookie, mycookie, sizeof(mycookie));
1167 memcpy(cinfo->extcookie, myextcookie, sizeof(myextcookie));
1170 futimens(fileno(fp), 0); /* try to set modification time */
1176 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
1180 char *tmpl, *cachedir;
1181 struct repoinfo *cinfo;
1184 cinfo = repo->appdata;
1185 if (cinfo && cinfo->incomplete)
1187 cachedir = userhome && getuid() ? pool_tmpjoin(repo->pool, userhome, "/.solvcache", 0) : SOLVCACHE_PATH;
1188 if (access(cachedir, W_OK | X_OK) != 0 && mkdir(cachedir, 0755) == 0)
1189 printf("[created %s]\n", cachedir);
1190 /* use dupjoin instead of tmpjoin because tmpl must survive repo_write */
1191 tmpl = solv_dupjoin(cachedir, "/", ".newsolv-XXXXXX");
1199 if (!(fp = fdopen(fd, "w")))
1208 for (i = repo->start; i < repo->end; i++)
1209 if (repo->pool->solvables[i].repo != repo)
1215 repo_write(repo, fp);
1217 repodata_write(info, fp);
1220 int oldnrepodata = repo->nrepodata;
1221 repo->nrepodata = oldnrepodata > 2 ? 2 : oldnrepodata; /* XXX: do this right */
1222 repo_write(repo, fp);
1223 repo->nrepodata = oldnrepodata;
1227 if (!repoext && cinfo)
1229 if (!cinfo->extcookie[0])
1231 /* create the ext cookie and append it */
1232 /* we just need some unique ID */
1234 if (!fstat(fileno(fp), &stb))
1235 memset(&stb, 0, sizeof(stb));
1236 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cookie, cinfo->extcookie);
1237 if (cinfo->extcookie[0] == 0)
1238 cinfo->extcookie[0] = 1;
1240 if (fwrite(cinfo->extcookie, 32, 1, fp) != 1)
1248 /* append our cookie describing the metadata state */
1249 if (fwrite(cookie, 32, 1, fp) != 1)
1264 /* switch to just saved repo to activate paging and save memory */
1265 FILE *fp = fopen(tmpl, "r");
1271 repo_empty(repo, 1);
1272 if (repo_add_solv(repo, fp, SOLV_ADD_NO_STUBS))
1274 /* oops, no way to recover from here */
1275 fprintf(stderr, "internal error\n");
1281 int flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1282 /* make sure repodata contains complete repo */
1283 /* (this is how repodata_write saves it) */
1284 repodata_extend_block(info, repo->start, repo->end - repo->start);
1285 info->state = REPODATA_LOADING;
1286 if (strcmp(repoext, "DL") != 0)
1287 flags |= REPO_LOCALPOOL;
1288 repo_add_solv(repo, fp, flags);
1289 info->state = REPODATA_AVAILABLE; /* in case the load failed */
1294 if (!rename(tmpl, calccachepath(repo, repoext, 0)))
1301 /* repomd helpers */
1303 static inline const char *
1304 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1306 Pool *pool = repo->pool;
1308 const char *filename;
1313 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
1314 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
1315 if (dataiterator_step(&di))
1317 dataiterator_setpos_parent(&di);
1318 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
1319 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
1321 dataiterator_free(&di);
1322 if (filename && !*chksumtypep)
1324 printf("no %s file checksum!\n", what);
1331 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
1333 Id chksumtype, handle;
1334 const unsigned char *chksum;
1335 const char *filename;
1337 filename = repomd_find(repo, what, &chksum, &chksumtype);
1340 if (!strcmp(what, "prestodelta"))
1342 handle = repodata_new_handle(data);
1343 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
1344 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
1345 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
1346 if (!strcmp(what, "deltainfo"))
1348 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
1349 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
1351 if (!strcmp(what, "filelists"))
1353 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1354 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1356 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1361 repomd_load_ext(Repo *repo, Repodata *data)
1363 const char *filename, *repomdtype;
1366 struct repoinfo *cinfo;
1367 const unsigned char *filechksum;
1371 cinfo = repo->appdata;
1372 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1375 if (!strcmp(repomdtype, "filelists"))
1377 else if (!strcmp(repomdtype, "deltainfo"))
1381 printf("[%s:%s", repo->name, ext);
1382 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1384 printf(" cached]\n"); fflush(stdout);
1387 printf(" fetching]\n"); fflush(stdout);
1388 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1390 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, REPOSITORY_REPOMD_CHECKSUM, &filechksumtype);
1391 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1393 if (!strcmp(ext, "FL"))
1394 r = repo_add_rpmmd(repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES|REPO_LOCALPOOL);
1395 else if (!strcmp(ext, "DL"))
1396 r = repo_add_deltainfoxml(repo, fp, REPO_USE_LOADING);
1400 printf("%s\n", pool_errstr(repo->pool));
1403 writecachedrepo(repo, data, ext, cinfo->extcookie);
1410 #ifdef ENABLE_SUSEREPO
1411 /* susetags helpers */
1413 static inline const char *
1414 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
1416 Pool *pool = repo->pool;
1418 const char *filename;
1423 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
1424 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1425 if (dataiterator_step(&di))
1427 dataiterator_setpos_parent(&di);
1428 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
1431 dataiterator_free(&di);
1432 if (filename && !*chksumtypep)
1434 printf("no %s file checksum!\n", what);
1440 static Id susetags_langtags[] = {
1441 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
1442 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
1443 SOLVABLE_EULA, REPOKEY_TYPE_STR,
1444 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
1445 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
1446 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
1451 susetags_add_ext(Repo *repo, Repodata *data)
1453 Pool *pool = repo->pool;
1456 Id handle, filechksumtype;
1457 const unsigned char *filechksum;
1460 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
1461 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
1462 while (dataiterator_step(&di))
1464 if (strncmp(di.kv.str, "packages.", 9) != 0)
1466 if (!strcmp(di.kv.str + 9, "gz"))
1468 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
1470 ext[0] = di.kv.str[9];
1471 ext[1] = di.kv.str[10];
1473 if (!strcmp(ext, "en"))
1475 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
1477 handle = repodata_new_handle(data);
1478 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
1480 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
1481 if (!strcmp(ext, "DU"))
1483 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
1484 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
1486 else if (!strcmp(ext, "FL"))
1488 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
1489 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
1493 for (i = 0; susetags_langtags[i]; i += 2)
1495 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
1496 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
1499 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
1501 dataiterator_free(&di);
1505 susetags_load_ext(Repo *repo, Repodata *data)
1507 const char *filename, *descrdir;
1511 struct repoinfo *cinfo;
1512 const unsigned char *filechksum;
1516 cinfo = repo->appdata;
1517 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
1521 ext[0] = filename[9];
1522 ext[1] = filename[10];
1524 printf("[%s:%s", repo->name, ext);
1525 if (usecachedrepo(repo, ext, cinfo->extcookie, 0))
1527 printf(" cached]\n"); fflush(stdout);
1530 printf(" fetching]\n"); fflush(stdout);
1531 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1532 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1534 descrdir = "suse/setup/descr";
1536 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1537 if ((fp = curlfopen(cinfo, pool_tmpjoin(repo->pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1539 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
1540 if (strcmp(ext, "DL") != 0)
1541 flags |= REPO_LOCALPOOL;
1542 if (repo_add_susetags(repo, fp, defvendor, ext, flags))
1545 printf("%s\n", pool_errstr(repo->pool));
1549 writecachedrepo(repo, data, ext, cinfo->extcookie);
1559 load_stub(Pool *pool, Repodata *data, void *dp)
1561 struct repoinfo *cinfo = data->repo->appdata;
1562 switch (cinfo->type)
1564 #ifdef ENABLE_SUSEREPO
1566 return susetags_load_ext(data->repo, data);
1570 return repomd_load_ext(data->repo, data);
1577 static unsigned char installedcookie[32];
1579 #ifdef ENABLE_DEBIAN
1582 debian_find_component(struct repoinfo *cinfo, FILE *fp, char *comp, const unsigned char **chksump, Id *chksumtypep)
1586 unsigned char *chksum;
1591 static char *basearch;
1603 basearch = strdup(un.machine);
1604 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
1607 binarydir = solv_dupjoin("binary-", basearch, "/");
1608 lbinarydir = strlen(binarydir);
1609 compl = strlen(comp);
1613 chksum = solv_malloc(32);
1615 while(fgets(buf, sizeof(buf), fp))
1620 while (l && (buf[l - 1] == '\n' || buf[l - 1] == ' ' || buf[l - 1] == '\t'))
1622 if (!strncasecmp(buf, "MD5Sum:", 7))
1624 curchksumtype = REPOKEY_TYPE_MD5;
1627 if (!strncasecmp(buf, "SHA1:", 5))
1629 curchksumtype = REPOKEY_TYPE_SHA1;
1632 if (!strncasecmp(buf, "SHA256:", 7))
1634 curchksumtype = REPOKEY_TYPE_SHA256;
1646 while (*bp && *bp != ' ' && *bp != '\t')
1651 while (*bp == ' ' || *bp == '\t')
1653 while (*bp && *bp != ' ' && *bp != '\t')
1657 while (*bp == ' ' || *bp == '\t')
1660 if (strncmp(fn, comp, compl) != 0 || fn[compl] != '/')
1663 if (strncmp(bp, binarydir, lbinarydir))
1666 if (!strcmp(bp, "Packages") || !strcmp(bp, "Packages.gz"))
1668 unsigned char curchksum[32];
1670 if (filename && !strcmp(bp, "Packages"))
1672 curl = solv_chksum_len(curchksumtype);
1673 if (!curl || (chksumtype && solv_chksum_len(chksumtype) > curl))
1675 if (solv_hex2bin((const char **)&ch, curchksum, sizeof(curchksum)) != curl)
1677 solv_free(filename);
1678 filename = strdup(fn);
1679 chksumtype = curchksumtype;
1680 memcpy(chksum, curchksum, curl);
1686 fn = solv_dupjoin("/", filename, 0);
1687 solv_free(filename);
1688 filename = solv_dupjoin("dists/", cinfo->name, fn);
1692 chksum = solv_free(chksum);
1694 *chksumtypep = chksumtype;
1700 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1703 struct repoinfo *cinfo;
1706 const char *filename;
1707 const unsigned char *filechksum;
1709 #ifdef ENABLE_SUSEREPO
1710 const char *descrdir;
1715 #if defined(ENABLE_SUSEREPO) || defined(ENABLE_RPMMD)
1719 #if defined(ENABLE_DEBIAN)
1724 repo = repo_create(pool, "@System");
1725 memset(&stb, 0, sizeof(stb));
1726 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1727 printf("rpm database:");
1728 if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/rpm/Packages"), &stb))
1729 memset(&stb, 0, sizeof(stb));
1731 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1732 printf("dpgk database:");
1733 if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/dpkg/status"), &stb))
1734 memset(&stb, 0, sizeof(stb));
1736 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, 0, installedcookie);
1737 if (usecachedrepo(repo, 0, installedcookie, 0))
1738 printf(" cached\n");
1741 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1744 printf(" reading\n");
1746 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
1747 # if defined(ENABLE_SUSEREPO) && defined(PRODUCTS_PATH)
1748 if (repo_add_products(repo, PRODUCTS_PATH, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
1750 fprintf(stderr, "product reading failed: %s\n", pool_errstr(pool));
1754 # if defined(ENABLE_APPDATA)
1755 if (repo_add_appdata_dir(repo, APPDATA_PATH, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
1757 fprintf(stderr, "appdata reading failed: %s\n", pool_errstr(pool));
1761 ofp = fopen(calccachepath(repo, 0, 0), "r");
1762 if (repo_add_rpmdb_reffp(repo, ofp, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
1764 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
1770 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
1771 if (repo_add_debdb(repo, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
1773 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
1777 repo_internalize(repo);
1778 writecachedrepo(repo, 0, 0, installedcookie);
1780 pool_set_installed(pool, repo);
1782 for (i = 0; i < nrepoinfos; i++)
1784 cinfo = repoinfos + i;
1785 if (!cinfo->enabled)
1788 repo = repo_create(pool, cinfo->alias);
1790 repo->appdata = cinfo;
1791 repo->priority = 99 - cinfo->priority;
1793 dorefresh = cinfo->autorefresh;
1794 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0, 0), &stb) == 0)
1796 if (cinfo->metadata_expire == -1 || time(0) - stb.st_mtime < cinfo->metadata_expire)
1799 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1801 printf("repo '%s':", cinfo->alias);
1802 printf(" cached\n");
1805 switch (cinfo->type)
1809 printf("rpmmd repo '%s':", cinfo->alias);
1811 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1813 printf(" no repomd.xml file, skipped\n");
1818 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1819 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1821 printf(" cached\n");
1825 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "repodata/repomd.xml.asc", &sigpool))
1830 if (repo_add_repomdxml(repo, fp, 0))
1832 printf("repomd.xml: %s\n", pool_errstr(pool));
1834 break; /* hopeless */
1837 printf(" fetching\n");
1838 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1839 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1841 if (repo_add_rpmmd(repo, fp, 0, 0))
1843 printf("primary: %s\n", pool_errstr(pool));
1844 cinfo->incomplete = 1;
1848 if (cinfo->incomplete)
1849 break; /* hopeless */
1851 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1852 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1854 if (repo_add_updateinfoxml(repo, fp, 0))
1856 printf("updateinfo: %s\n", pool_errstr(pool));
1857 cinfo->incomplete = 1;
1862 #ifdef ENABLE_APPDATA
1863 filename = repomd_find(repo, "appdata", &filechksum, &filechksumtype);
1864 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1866 if (repo_add_appdata(repo, fp, 0))
1868 printf("appdata: %s\n", pool_errstr(pool));
1869 cinfo->incomplete = 1;
1874 data = repo_add_repodata(repo, 0);
1875 if (!repomd_add_ext(repo, data, "deltainfo"))
1876 repomd_add_ext(repo, data, "prestodelta");
1877 repomd_add_ext(repo, data, "filelists");
1878 repodata_internalize(data);
1879 if (!cinfo->incomplete)
1880 writecachedrepo(repo, 0, 0, cinfo->cookie);
1881 repodata_create_stubs(repo_last_repodata(repo));
1885 #ifdef ENABLE_SUSEREPO
1887 printf("susetags repo '%s':", cinfo->alias);
1891 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1893 printf(" no content file, skipped\n");
1898 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cinfo->cookie);
1899 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
1901 printf(" cached\n");
1905 if (cinfo->repo_gpgcheck && !downloadchecksig(cinfo, fp, "content.asc", &sigpool))
1910 if (repo_add_content(repo, fp, 0))
1912 printf("content: %s\n", pool_errstr(pool));
1914 break; /* hopeless */
1917 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1918 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1920 descrdir = "suse/setup/descr";
1921 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1923 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1926 printf(" no packages file entry, skipped\n");
1929 printf(" fetching\n");
1930 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) == 0)
1931 break; /* hopeless */
1932 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|SUSETAGS_RECORD_SHARES))
1934 printf("packages: %s\n", pool_errstr(pool));
1936 cinfo->incomplete = 1;
1937 break; /* hopeless */
1940 /* add default language */
1941 filename = susetags_find(repo, "packages.en.gz", &filechksum, &filechksumtype);
1943 filename = susetags_find(repo, "packages.en", &filechksum, &filechksumtype);
1946 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1948 if (repo_add_susetags(repo, fp, defvendor, 0, REPO_NO_INTERNALIZE|REPO_REUSE_REPODATA|REPO_EXTEND_SOLVABLES))
1950 printf("packages.en: %s\n", pool_errstr(pool));
1951 cinfo->incomplete = 1;
1956 filename = susetags_find(repo, "patterns", &filechksum, &filechksumtype);
1959 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1962 while (fgets(pbuf, sizeof(pbuf), fp))
1964 int l = strlen(pbuf);
1966 if (l && pbuf[l - 1] == '\n')
1968 if (!*pbuf || *pbuf == '.' || strchr(pbuf, '/') != 0)
1970 filename = susetags_find(repo, pbuf, &filechksum, &filechksumtype);
1971 if (filename && (fp2 = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1973 if (repo_add_susetags(repo, fp2, defvendor, 0, REPO_NO_INTERNALIZE))
1975 printf("%s: %s\n", pbuf, pool_errstr(pool));
1976 cinfo->incomplete = 1;
1984 #ifdef ENABLE_APPDATA
1985 filename = susetags_find(repo, "appdata.xml.gz", &filechksum, &filechksumtype);
1987 filename = susetags_find(repo, "appdata.xml", &filechksum, &filechksumtype);
1988 if (filename && (fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
1990 if (repo_add_appdata(repo, fp, 0))
1992 printf("appdata: %s\n", pool_errstr(pool));
1993 cinfo->incomplete = 1;
1998 repo_internalize(repo);
1999 data = repo_add_repodata(repo, 0);
2000 susetags_add_ext(repo, data);
2001 repodata_internalize(data);
2002 if (!cinfo->incomplete)
2003 writecachedrepo(repo, 0, 0, cinfo->cookie);
2004 repodata_create_stubs(repo_last_repodata(repo));
2008 #if defined(ENABLE_DEBIAN)
2010 printf("debian repo '%s':", cinfo->alias);
2012 filename = solv_dupjoin("dists/", cinfo->name, "/Release");
2013 if ((fpr = curlfopen(cinfo, filename, 0, 0, 0, 0)) == 0)
2015 printf(" no Release file, skipped\n");
2018 free((char *)filename);
2021 solv_free((char *)filename);
2022 if (cinfo->repo_gpgcheck)
2024 filename = solv_dupjoin("dists/", cinfo->name, "/Release.gpg");
2025 if (!downloadchecksig(cinfo, fpr, filename, &sigpool))
2028 solv_free((char *)filename);
2031 solv_free((char *)filename);
2033 calc_checksum_fp(fpr, REPOKEY_TYPE_SHA256, cinfo->cookie);
2034 if (usecachedrepo(repo, 0, cinfo->cookie, 1))
2036 printf(" cached\n");
2040 printf(" fetching\n");
2041 for (j = 0; j < cinfo->ncomponents; j++)
2043 if (!(filename = debian_find_component(cinfo, fpr, cinfo->components[j], &filechksum, &filechksumtype)))
2045 printf("[component %s not found]\n", cinfo->components[j]);
2048 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 1)) != 0)
2050 if (repo_add_debpackages(repo, fp, 0))
2052 printf("component %s: %s\n", cinfo->components[j], pool_errstr(pool));
2053 cinfo->incomplete = 1;
2057 solv_free((char *)filechksum);
2058 solv_free((char *)filename);
2061 if (!cinfo->incomplete)
2062 writecachedrepo(repo, 0, 0, cinfo->cookie);
2067 printf("unsupported repo '%s': skipped\n", cinfo->alias);
2078 yesno(const char *str)
2080 char inbuf[128], *ip;
2087 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
2092 while (*ip == ' ' || *ip == '\t')
2099 if (*ip == 'y' || *ip == 'n')
2100 return *ip == 'y' ? 1 : 0;
2104 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2114 fileconflict_cb(Pool *pool, Id p, void *cbdata)
2116 struct fcstate *fcstate = cbdata;
2122 s = pool_id2solvable(pool, p);
2123 if (pool->installed && s->repo == pool->installed)
2125 if (!s->repo->rpmdbid)
2127 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
2130 return rpm_byrpmdbid(fcstate->rpmstate, rpmdbid);
2132 for (i = 0; i < fcstate->newpkgscnt; i++)
2133 if (fcstate->checkq->elements[i] == p)
2135 if (i == fcstate->newpkgscnt)
2137 fp = fcstate->newpkgsfps[i];
2141 return rpm_byfp(fcstate->rpmstate, fp, pool_solvable2str(pool, s));
2146 runrpm(const char *arg, const char *name, int dupfd3, const char *rootdir)
2151 if ((pid = fork()) == (pid_t)-1)
2160 if (dupfd3 != -1 && dupfd3 != 3)
2166 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2167 if (strcmp(arg, "-e") == 0)
2168 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2170 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
2174 while (waitpid(pid, &status, 0) != pid)
2178 printf("rpm failed\n");
2185 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2188 rundpkg(const char *arg, const char *name, int dupfd3, const char *rootdir)
2193 if ((pid = fork()) == (pid_t)-1)
2202 if (dupfd3 != -1 && dupfd3 != 3)
2208 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
2209 if (strcmp(arg, "--install") == 0)
2210 execlp("dpkg", "dpkg", "--install", "--root", rootdir, "--force", "all", name, (char *)0);
2212 execlp("dpkg", "dpkg", "--remove", "--root", rootdir, "--force", "all", name, (char *)0);
2216 while (waitpid(pid, &status, 0) != pid)
2220 printf("dpkg failed\n");
2229 nscallback(Pool *pool, void *data, Id name, Id evr)
2232 if (name == NAMESPACE_LANGUAGE)
2234 if (!strcmp(pool_id2str(pool, evr), "ja"))
2236 if (!strcmp(pool_id2str(pool, evr), "de"))
2238 if (!strcmp(pool_id2str(pool, evr), "en"))
2240 if (!strcmp(pool_id2str(pool, evr), "en_US"))
2248 #ifdef SOFTLOCKS_PATH
2250 addsoftlocks(Pool *pool, Queue *job)
2254 char *bp, *ep, buf[4096];
2256 if ((fp = fopen(SOFTLOCKS_PATH, "r")) == 0)
2258 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
2260 while (*bp == ' ' || *bp == '\t')
2262 if (!*bp || *bp == '#')
2264 for (ep = bp; *ep; ep++)
2265 if (*ep == ' ' || *ep == '\t' || *ep == '\n')
2268 type = SOLVER_SOLVABLE_NAME;
2269 if (!strncmp(bp, "provides:", 9) && bp[9])
2271 type = SOLVER_SOLVABLE_PROVIDES;
2274 id = pool_str2id(pool, bp, 1);
2275 if (pool->installed)
2277 FOR_JOB_SELECT(p, pp, type, id)
2278 if (pool->solvables[p].repo == pool->installed)
2281 continue; /* ignore, as it is already installed */
2283 queue_push2(job, SOLVER_LOCK|SOLVER_WEAK|type, id);
2290 #if defined(ENABLE_RPMDB)
2293 rewrite_repos(Pool *pool, Queue *addedfileprovides, Queue *addedfileprovides_inst)
2298 Queue fileprovidesq;
2300 struct repoinfo *cinfo;
2302 map_init(&providedids, pool->ss.nstrings);
2303 queue_init(&fileprovidesq);
2304 for (i = 0; i < addedfileprovides->count; i++)
2305 MAPSET(&providedids, addedfileprovides->elements[i]);
2308 /* make sure all repodatas but the first are extensions */
2309 if (repo->nrepodata < 2)
2311 cinfo = repo->appdata;
2312 if (repo != pool->installed && !cinfo)
2314 if (cinfo && cinfo->incomplete)
2316 data = repo_id2repodata(repo, 1);
2317 if (data->loadcallback)
2319 for (j = 2; j < repo->nrepodata; j++)
2321 Repodata *edata = repo_id2repodata(repo, j);
2322 if (!edata->loadcallback)
2325 if (j < repo->nrepodata)
2326 continue; /* found a non-externsion repodata, can't rewrite */
2327 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
2329 if (repo == pool->installed && addedfileprovides_inst)
2331 for (j = 0; j < addedfileprovides->count; j++)
2332 MAPCLR(&providedids, addedfileprovides->elements[j]);
2333 for (j = 0; j < addedfileprovides_inst->count; j++)
2334 MAPSET(&providedids, addedfileprovides_inst->elements[j]);
2337 for (j = 0; j < fileprovidesq.count; j++)
2338 if (MAPTST(&providedids, fileprovidesq.elements[j]))
2340 if (repo == pool->installed && addedfileprovides_inst)
2342 for (j = 0; j < addedfileprovides_inst->count; j++)
2343 MAPCLR(&providedids, addedfileprovides_inst->elements[j]);
2344 for (j = 0; j < addedfileprovides->count; j++)
2345 MAPSET(&providedids, addedfileprovides->elements[j]);
2346 if (n == addedfileprovides_inst->count)
2347 continue; /* nothing new added */
2349 else if (n == addedfileprovides->count)
2350 continue; /* nothing new added */
2352 repodata_set_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, repo == pool->installed && addedfileprovides_inst ? addedfileprovides_inst : addedfileprovides);
2353 repodata_internalize(data);
2354 writecachedrepo(repo, data, 0, cinfo ? cinfo->cookie : installedcookie);
2356 queue_free(&fileprovidesq);
2357 map_free(&providedids);
2361 addfileprovides(Pool *pool)
2363 Queue addedfileprovides;
2364 Queue addedfileprovides_inst;
2366 queue_init(&addedfileprovides);
2367 queue_init(&addedfileprovides_inst);
2368 pool_addfileprovides_queue(pool, &addedfileprovides, &addedfileprovides_inst);
2369 if (addedfileprovides.count || addedfileprovides_inst.count)
2370 rewrite_repos(pool, &addedfileprovides, &addedfileprovides_inst);
2371 queue_free(&addedfileprovides);
2372 queue_free(&addedfileprovides_inst);
2379 add_autopackages(Pool *pool)
2384 repo_add_autopattern(repo, 0);
2388 #if defined(SUSE) || defined(FEDORA)
2390 add_patchjobs(Pool *pool, Queue *job)
2394 Map installedmap, multiversionmap;
2397 map_init(&multiversionmap, 0);
2398 map_init(&installedmap, pool->nsolvables);
2399 solver_calculate_multiversionmap(pool, job, &multiversionmap);
2400 if (pool->installed)
2401 FOR_REPO_SOLVABLES(pool->installed, p, s)
2402 MAPSET(&installedmap, p);
2404 /* install all patches */
2405 for (p = 1; p < pool->nsolvables; p++)
2411 s = pool->solvables + p;
2412 if (strncmp(pool_id2str(pool, s->name), "patch:", 6) != 0)
2414 FOR_PROVIDES(p2, pp, s->name)
2416 Solvable *s2 = pool->solvables + p2;
2417 if (s2->name != s->name)
2419 r = pool_evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
2420 if (r < 0 || (r == 0 && p > p2))
2425 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
2426 if (type && !strcmp(type, "optional"))
2428 r = solvable_trivial_installable_map(s, &installedmap, 0, &multiversionmap);
2431 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
2438 queue_push2(job, SOLVER_SOLVABLE, p);
2440 map_free(&installedmap);
2441 map_free(&multiversionmap);
2447 showdiskusagechanges(Transaction *trans)
2452 /* XXX: use mountpoints here */
2453 memset(duc, 0, sizeof(duc));
2455 duc[1].path = "/usr/share/man";
2456 duc[2].path = "/sbin";
2457 duc[3].path = "/etc";
2458 transaction_calc_duchanges(trans, duc, 4);
2459 for (i = 0; i < 4; i++)
2460 printf("duchanges %s: %d K %d inodes\n", duc[i].path, duc[i].kbytes, duc[i].files);
2464 #if defined(ENABLE_RPMDB)
2466 trydeltadownload(Solvable *s, struct repoinfo *cinfo, const char *loc)
2468 Pool *pool = s->repo->pool;
2471 const unsigned char *chksum;
2474 char *matchname = strdup(pool_id2str(pool, s->name));
2476 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, matchname, SEARCH_STRING);
2477 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
2478 while (dataiterator_step(&di))
2482 dataiterator_setpos_parent(&di);
2483 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
2484 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
2486 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
2487 FOR_PROVIDES(op, pp, s->name)
2489 Solvable *os = pool->solvables + op;
2490 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
2493 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
2495 /* base is installed, run sequence check */
2498 const char *archstr;
2503 archstr = pool_id2str(pool, s->arch);
2504 if (strlen(archstr) > 10 || strchr(archstr, '\'') != 0)
2507 seq = pool_tmpjoin(pool, pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME), "-", pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR));
2508 seq = pool_tmpappend(pool, seq, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM));
2509 if (strchr(seq, '\'') != 0)
2512 sprintf(cmd, "/usr/bin/applydeltarpm -a '%s' -c -s '", archstr);
2514 sprintf(cmd, "/usr/bin/applydeltarpm -c -s '");
2516 if (system(pool_tmpjoin(pool, cmd, seq, "'")) != 0)
2517 continue; /* didn't match */
2518 /* looks good, download delta */
2520 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
2522 continue; /* no way! */
2523 dloc = pool_lookup_deltalocation(pool, SOLVID_POS, 0);
2526 #ifdef ENABLE_SUSEREPO
2527 if (cinfo->type == TYPE_SUSETAGS)
2529 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
2530 dloc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", dloc);
2533 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
2535 /* got it, now reconstruct */
2536 newfd = opentmpfile();
2538 sprintf(cmd, "applydeltarpm -a '%s' /dev/fd/%d /dev/fd/%d", archstr, fileno(fp), newfd);
2540 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
2542 fcntl(fileno(fp), F_SETFD, 0);
2549 lseek(newfd, 0, SEEK_SET);
2551 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
2552 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
2558 retfp = fdopen(newfd, "r");
2563 dataiterator_free(&di);
2564 solv_free(matchname);
2571 #define MODE_INSTALL 1
2572 #define MODE_ERASE 2
2573 #define MODE_UPDATE 3
2574 #define MODE_DISTUPGRADE 4
2575 #define MODE_VERIFY 5
2576 #define MODE_PATCH 6
2578 #define MODE_REPOLIST 8
2579 #define MODE_SEARCH 9
2584 fprintf(stderr, "Usage: solv COMMAND <select>\n");
2585 fprintf(stderr, "\n");
2586 fprintf(stderr, " dist-upgrade: replace installed packages with\n");
2587 fprintf(stderr, " versions from the repositories\n");
2588 fprintf(stderr, " erase: erase installed packages\n");
2589 fprintf(stderr, " info: display package information\n");
2590 fprintf(stderr, " install: install packages\n");
2591 fprintf(stderr, " list: list packages\n");
2592 fprintf(stderr, " repos: list enabled repositories\n");
2593 fprintf(stderr, " search: search name/summary/description\n");
2594 fprintf(stderr, " update: update installed packages\n");
2595 fprintf(stderr, " verify: check dependencies of installed packages\n");
2596 #if defined(SUSE) || defined(FEDORA)
2597 fprintf(stderr, " patch: install newest patches\n");
2599 fprintf(stderr, "\n");
2604 main(int argc, char **argv)
2607 Repo *commandlinerepo = 0;
2608 Id *commandlinepkgs = 0;
2610 struct repoinfo *repoinfos;
2612 int mainmode = 0, mode = 0;
2621 int archfilter_src = 0;
2630 userhome = getenv("HOME");
2631 if (userhome && userhome[0] != '/')
2633 while (argc && !strcmp(argv[0], "-d"))
2641 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
2643 mainmode = MODE_INSTALL;
2644 mode = SOLVER_INSTALL;
2646 #if defined(SUSE) || defined(FEDORA)
2647 else if (!strcmp(argv[0], "patch"))
2649 mainmode = MODE_PATCH;
2650 mode = SOLVER_INSTALL;
2653 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
2655 mainmode = MODE_ERASE;
2656 mode = SOLVER_ERASE;
2658 else if (!strcmp(argv[0], "list") || !strcmp(argv[0], "ls"))
2660 mainmode = MODE_LIST;
2663 else if (!strcmp(argv[0], "info"))
2665 mainmode = MODE_INFO;
2668 else if (!strcmp(argv[0], "search") || !strcmp(argv[0], "se"))
2670 mainmode = MODE_SEARCH;
2673 else if (!strcmp(argv[0], "verify"))
2675 mainmode = MODE_VERIFY;
2676 mode = SOLVER_VERIFY;
2678 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
2680 mainmode = MODE_UPDATE;
2681 mode = SOLVER_UPDATE;
2683 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
2685 mainmode = MODE_DISTUPGRADE;
2686 mode = SOLVER_DISTUPGRADE;
2688 else if (!strcmp(argv[0], "repos") || !strcmp(argv[0], "repolist") || !strcmp(argv[0], "lr"))
2690 mainmode = MODE_REPOLIST;
2698 if (argc > 2 && !strcmp(argv[1], "--root"))
2704 else if (argc > 1 && !strcmp(argv[1], "--clean"))
2710 else if (argc > 1 && !strcmp(argv[1], "--best"))
2716 if (argc > 2 && !strcmp(argv[1], "--keyname"))
2726 pool = pool_create();
2727 pool_set_rootdir(pool, rootdir);
2731 const char *langs[] = {"de_DE", "de", "en"};
2732 pool_set_languages(pool, langs, sizeof(langs)/sizeof(*langs));
2736 pool_setloadcallback(pool, load_stub, 0);
2738 pool->nscallback = nscallback;
2741 pool_setdebuglevel(pool, debuglevel);
2743 pool_set_flag(pool, POOL_FLAG_ADDFILEPROVIDESFILTERED, 1);
2744 repoinfos = read_repoinfos(pool, &nrepoinfos);
2746 if (mainmode == MODE_REPOLIST)
2749 for (i = 0; i < nrepoinfos; i++)
2751 struct repoinfo *cinfo = repoinfos + i;
2752 if (!cinfo->enabled)
2754 printf("%d: %-20s %s (prio %d)\n", j++, cinfo->alias, cinfo->name, cinfo->priority);
2759 read_repos(pool, repoinfos, nrepoinfos);
2762 queue_init(&repofilter);
2763 queue_init(&kindfilter);
2764 queue_init(&archfilter);
2767 if (!strcmp(argv[1], "-i"))
2769 queue_push2(&repofilter, SOLVER_SOLVABLE_REPO | SOLVER_SETREPO, pool->installed->repoid);
2773 else if (argc > 2 && (!strcmp(argv[1], "-r") || !strcmp(argv[1], "--repo")))
2775 const char *rname = argv[2], *rp;
2777 for (rp = rname; *rp; rp++)
2778 if (*rp <= '0' || *rp >= '9')
2782 /* repo specified by number */
2783 int rnum = atoi(rname);
2784 for (i = 0; i < nrepoinfos; i++)
2786 struct repoinfo *cinfo = repoinfos + i;
2787 if (!cinfo->enabled)
2790 repoid = cinfo->repo->repoid;
2795 /* repo specified by alias */
2799 if (!strcasecmp(rname, repo->name))
2800 repoid = repo->repoid;
2805 fprintf(stderr, "%s: no such repo\n", rname);
2808 /* SETVENDOR is actually wrong but useful */
2809 queue_push2(&repofilter, SOLVER_SOLVABLE_REPO | SOLVER_SETREPO | SOLVER_SETVENDOR, repoid);
2813 else if (argc > 2 && !strcmp(argv[1], "--arch"))
2815 if (!strcmp(argv[2], "src") || !strcmp(argv[2], "nosrc"))
2817 queue_push2(&archfilter, SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, 0, pool_str2id(pool, argv[2], 1), REL_ARCH, 1));
2821 else if (argc > 2 && (!strcmp(argv[1], "-t") || !strcmp(argv[1], "--type")))
2823 const char *kind = argv[2];
2824 if (!strcmp(kind, "srcpackage"))
2826 /* hey! should use --arch! */
2827 queue_push2(&archfilter, SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, 0, ARCH_SRC, REL_ARCH, 1));
2833 if (!strcmp(kind, "package"))
2835 if (!strcmp(kind, "all"))
2836 queue_push2(&kindfilter, SOLVER_SOLVABLE_ALL, 0);
2838 queue_push2(&kindfilter, SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, 0, pool_str2id(pool, kind, 1), REL_KIND, 1));
2846 if (mainmode == MODE_SEARCH)
2852 pool_createwhatprovides(pool);
2854 dataiterator_init(&di, pool, 0, 0, 0, argv[1], SEARCH_SUBSTRING|SEARCH_NOCASE);
2855 dataiterator_set_keyname(&di, SOLVABLE_NAME);
2856 dataiterator_set_search(&di, 0, 0);
2857 while (dataiterator_step(&di))
2858 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2859 dataiterator_set_keyname(&di, SOLVABLE_SUMMARY);
2860 dataiterator_set_search(&di, 0, 0);
2861 while (dataiterator_step(&di))
2862 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2863 dataiterator_set_keyname(&di, SOLVABLE_DESCRIPTION);
2864 dataiterator_set_search(&di, 0, 0);
2865 while (dataiterator_step(&di))
2866 queue_push2(&sel, SOLVER_SOLVABLE, di.solvid);
2867 dataiterator_free(&di);
2868 if (repofilter.count)
2869 selection_filter(pool, &sel, &repofilter);
2872 selection_solvables(pool, &sel, &q);
2874 for (i = 0; i < q.count; i++)
2876 Solvable *s = pool_id2solvable(pool, q.elements[i]);
2877 printf(" - %s [%s]: %s\n", pool_solvable2str(pool, s), s->repo->name, solvable_lookup_str(s, SOLVABLE_SUMMARY));
2883 /* process command line packages */
2884 if (mainmode == MODE_LIST || mainmode == MODE_INFO || mainmode == MODE_INSTALL)
2886 for (i = 1; i < argc; i++)
2889 l = strlen(argv[i]);
2890 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2891 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
2894 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2895 if (l <= 4 || strcmp(argv[i] + l - 4, ".deb"))
2898 if (access(argv[i], R_OK))
2903 if (!commandlinepkgs)
2904 commandlinepkgs = solv_calloc(argc, sizeof(Id));
2905 if (!commandlinerepo)
2906 commandlinerepo = repo_create(pool, "@commandline");
2908 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
2909 p = repo_add_rpm(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2911 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
2912 p = repo_add_deb(commandlinerepo, (const char *)argv[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
2916 fprintf(stderr, "could not add '%s'\n", argv[i]);
2919 commandlinepkgs[i] = p;
2921 if (commandlinerepo)
2922 repo_internalize(commandlinerepo);
2925 // FOR_REPOS(i, repo)
2926 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
2928 #if defined(ENABLE_RPMDB)
2929 if (pool->disttype == DISTTYPE_RPM)
2930 addfileprovides(pool);
2933 add_autopackages(pool);
2935 pool_createwhatprovides(pool);
2938 keyname = solv_dupjoin("solvable:", keyname, 0);
2940 for (i = 1; i < argc; i++)
2943 int j, flags, rflags;
2945 if (commandlinepkgs && commandlinepkgs[i])
2947 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
2951 flags = SELECTION_NAME|SELECTION_PROVIDES|SELECTION_GLOB;
2952 flags |= SELECTION_CANON|SELECTION_DOTARCH|SELECTION_REL;
2953 if (kindfilter.count)
2954 flags |= SELECTION_SKIP_KIND;
2955 if (mode == MODE_LIST || archfilter_src)
2956 flags |= SELECTION_WITH_SOURCE;
2957 if (argv[i][0] == '/')
2958 flags |= SELECTION_FILELIST | (mode == MODE_ERASE ? SELECTION_INSTALLED_ONLY : 0);
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);
2971 flags |= SELECTION_NOCASE;
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);
2983 printf("[ignoring case for '%s']\n", argv[i]);
2987 fprintf(stderr, "nothing matches '%s'\n", argv[i]);
2990 if (rflags & SELECTION_FILELIST)
2991 printf("[using file list match for '%s']\n", argv[i]);
2992 if (rflags & SELECTION_PROVIDES)
2993 printf("[using capability match for '%s']\n", argv[i]);
2994 for (j = 0; j < job2.count; j++)
2995 queue_push(&job, job2.elements[j]);
2998 keyname = solv_free(keyname);
3000 if (!job.count && (mainmode == MODE_UPDATE || mainmode == MODE_DISTUPGRADE || mainmode == MODE_VERIFY || repofilter.count || archfilter.count || kindfilter.count))
3002 queue_push2(&job, SOLVER_SOLVABLE_ALL, 0);
3003 if (repofilter.count)
3004 selection_filter(pool, &job, &repofilter);
3005 if (archfilter.count)
3006 selection_filter(pool, &job, &archfilter);
3007 if (kindfilter.count)
3008 selection_filter(pool, &job, &kindfilter);
3010 queue_free(&repofilter);
3011 queue_free(&archfilter);
3012 queue_free(&kindfilter);
3014 if (!job.count && mainmode != MODE_PATCH)
3016 printf("no package matched\n");
3020 if (mainmode == MODE_LIST || mainmode == MODE_INFO)
3022 /* list mode, no solver needed */
3025 for (i = 0; i < job.count; i += 2)
3029 pool_job2solvables(pool, &q, job.elements[i], job.elements[i + 1]);
3030 for (j = 0; j < q.count; j++)
3032 Solvable *s = pool_id2solvable(pool, q.elements[j]);
3033 if (mainmode == MODE_INFO)
3036 printf("Name: %s\n", pool_solvable2str(pool, s));
3037 printf("Repo: %s\n", s->repo->name);
3038 printf("Summary: %s\n", solvable_lookup_str(s, SOLVABLE_SUMMARY));
3039 str = solvable_lookup_str(s, SOLVABLE_URL);
3041 printf("Url: %s\n", str);
3042 str = solvable_lookup_str(s, SOLVABLE_LICENSE);
3044 printf("License: %s\n", str);
3046 str = solvable_lookup_sourcepkg(s);
3048 printf("Source: %s\n", str);
3050 printf("Description:\n%s\n", solvable_lookup_str(s, SOLVABLE_DESCRIPTION));
3056 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de", 1);
3058 const char *sum = solvable_lookup_str_poollang(s, SOLVABLE_SUMMARY);
3060 printf(" - %s [%s]\n", pool_solvable2str(pool, s), s->repo->name);
3062 printf(" %s\n", sum);
3069 free_repoinfos(repoinfos, nrepoinfos);
3070 solv_free(commandlinepkgs);
3072 yum_substitute(pool, 0);
3077 #if defined(SUSE) || defined(FEDORA)
3078 if (mainmode == MODE_PATCH)
3079 add_patchjobs(pool, &job);
3083 for (i = 0; i < job.count; i += 2)
3085 job.elements[i] |= mode;
3086 if (mode == SOLVER_UPDATE && pool_isemptyupdatejob(pool, job.elements[i], job.elements[i + 1]))
3087 job.elements[i] ^= SOLVER_UPDATE ^ SOLVER_INSTALL;
3089 job.elements[i] |= SOLVER_CLEANDEPS;
3091 job.elements[i] |= SOLVER_FORCEBEST;
3094 // multiversion test
3095 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae", 1));
3096 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-base", 1));
3097 // queue_push2(&job, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_NAME, pool_str2id(pool, "kernel-pae-extra", 1));
3099 queue_push2(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, NAMESPACE_LANGUAGE, 0, REL_NAMESPACE, 1));
3100 queue_push2(&job, SOLVER_ERASE|SOLVER_CLEANDEPS|SOLVER_SOLVABLE_PROVIDES, pool_rel2id(pool, NAMESPACE_LANGUAGE, 0, REL_NAMESPACE, 1));
3103 #ifdef SOFTLOCKS_PATH
3104 addsoftlocks(pool, &job);
3107 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3110 solv = solver_create(pool);
3111 solver_set_flag(solv, SOLVER_FLAG_SPLITPROVIDES, 1);
3113 solver_set_flag(solv, SOLVER_FLAG_ALLOW_VENDORCHANGE, 1);
3115 if (mainmode == MODE_ERASE)
3116 solver_set_flag(solv, SOLVER_FLAG_ALLOW_UNINSTALL, 1); /* don't nag */
3117 solver_set_flag(solv, SOLVER_FLAG_BEST_OBEY_POLICY, 1);
3121 Id problem, solution;
3124 if (!solver_solve(solv, &job))
3126 pcnt = solver_problem_count(solv);
3127 printf("Found %d problems:\n", pcnt);
3128 for (problem = 1; problem <= pcnt; problem++)
3131 printf("Problem %d/%d:\n", problem, pcnt);
3132 solver_printprobleminfo(solv, problem);
3134 scnt = solver_solution_count(solv, problem);
3135 for (solution = 1; solution <= scnt; solution++)
3137 printf("Solution %d:\n", solution);
3138 solver_printsolution(solv, problem, solution);
3143 char inbuf[128], *ip;
3144 printf("Please choose a solution: ");
3147 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
3152 while (*ip == ' ' || *ip == '\t')
3154 if (*ip >= '0' && *ip <= '9')
3157 if (take >= 1 && take <= scnt)
3173 solver_take_solution(solv, problem, take, &job);
3177 trans = solver_create_transaction(solv);
3178 if (!trans->steps.count)
3180 printf("Nothing to do.\n");
3181 transaction_free(trans);
3185 free_repoinfos(repoinfos, nrepoinfos);
3186 solv_free(commandlinepkgs);
3188 yum_substitute(pool, 0);
3193 /* display transaction to the user and ask for confirmation */
3195 printf("Transaction summary:\n\n");
3196 transaction_print(trans);
3198 showdiskusagechanges(trans);
3200 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
3203 if (!yesno("OK to continue (y/n)? "))
3206 transaction_free(trans);
3210 free_repoinfos(repoinfos, nrepoinfos);
3211 solv_free(commandlinepkgs);
3213 yum_substitute(pool, 0);
3218 /* download all new packages */
3219 queue_init(&checkq);
3220 newpkgs = transaction_installedresult(trans, &checkq);
3224 int downloadsize = 0;
3225 for (i = 0; i < newpkgs; i++)
3229 p = checkq.elements[i];
3230 s = pool_id2solvable(pool, p);
3231 downloadsize += solvable_lookup_sizek(s, SOLVABLE_DOWNLOADSIZE, 0);
3233 printf("Downloading %d packages, %d K\n", newpkgs, downloadsize);
3234 newpkgsfps = solv_calloc(newpkgs, sizeof(*newpkgsfps));
3235 for (i = 0; i < newpkgs; i++)
3237 unsigned int medianr;
3240 struct repoinfo *cinfo;
3241 const unsigned char *chksum;
3244 p = checkq.elements[i];
3245 s = pool_id2solvable(pool, p);
3246 if (s->repo == commandlinerepo)
3248 loc = solvable_lookup_location(s, &medianr);
3251 if (!(newpkgsfps[i] = fopen(loc, "r")))
3259 cinfo = s->repo->appdata;
3262 printf("%s: no repository information\n", s->repo->name);
3265 loc = solvable_lookup_location(s, &medianr);
3268 #if defined(ENABLE_RPMDB)
3269 if (pool->installed && pool->installed->nsolvables)
3271 if ((newpkgsfps[i] = trydeltadownload(s, cinfo, loc)) != 0)
3275 continue; /* delta worked! */
3279 #ifdef ENABLE_SUSEREPO
3280 if (cinfo->type == TYPE_SUSETAGS)
3282 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
3283 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
3287 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
3288 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
3290 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
3299 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3300 /* check for file conflicts */
3304 struct fcstate fcstate;
3306 printf("Searching for file conflicts\n");
3307 queue_init(&conflicts);
3308 fcstate.rpmstate = rpm_state_create(pool, rootdir);
3309 fcstate.newpkgscnt = newpkgs;
3310 fcstate.checkq = &checkq;
3311 fcstate.newpkgsfps = newpkgsfps;
3312 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, FINDFILECONFLICTS_USE_SOLVABLEFILELIST | FINDFILECONFLICTS_CHECK_DIRALIASING | FINDFILECONFLICTS_USE_ROOTDIR, &fileconflict_cb, &fcstate);
3313 fcstate.rpmstate = rpm_state_free(fcstate.rpmstate);
3314 if (conflicts.count)
3317 for (i = 0; i < conflicts.count; i += 6)
3318 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]));
3320 if (yesno("Re-run solver (y/n/q)? "))
3322 for (i = 0; i < newpkgs; i++)
3324 fclose(newpkgsfps[i]);
3325 newpkgsfps = solv_free(newpkgsfps);
3328 pool_add_fileconflicts_deps(pool, &conflicts);
3332 queue_free(&conflicts);
3336 /* and finally commit the transaction */
3337 printf("Committing transaction:\n\n");
3338 transaction_order(trans, 0);
3339 for (i = 0; i < trans->steps.count; i++)
3341 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3342 const char *evr, *evrp, *nvra;
3349 p = trans->steps.elements[i];
3350 s = pool_id2solvable(pool, p);
3351 type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
3354 case SOLVER_TRANSACTION_ERASE:
3355 printf("erase %s\n", pool_solvid2str(pool, p));
3356 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3357 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
3359 /* strip epoch from evr */
3360 evr = evrp = pool_id2str(pool, s->evr);
3361 while (*evrp >= '0' && *evrp <= '9')
3363 if (evrp > evr && evrp[0] == ':' && evrp[1])
3365 nvra = pool_tmpjoin(pool, pool_id2str(pool, s->name), "-", evr);
3366 nvra = pool_tmpappend(pool, nvra, ".", pool_id2str(pool, s->arch));
3367 runrpm("-e", nvra, -1, rootdir); /* too bad that --querybynumber doesn't work */
3369 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3370 rundpkg("--remove", pool_id2str(pool, s->name), 0, rootdir);
3373 case SOLVER_TRANSACTION_INSTALL:
3374 case SOLVER_TRANSACTION_MULTIINSTALL:
3375 printf("install %s\n", pool_solvid2str(pool, p));
3376 for (j = 0; j < newpkgs; j++)
3377 if (checkq.elements[j] == p)
3379 fp = j < newpkgs ? newpkgsfps[j] : 0;
3383 lseek(fileno(fp), 0, SEEK_SET);
3384 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA))
3385 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp), rootdir);
3387 #if defined(ENABLE_DEBIAN) && defined(DEBIAN)
3388 rundpkg("--install", "/dev/fd/3", fileno(fp), rootdir);
3398 for (i = 0; i < newpkgs; i++)
3400 fclose(newpkgsfps[i]);
3401 solv_free(newpkgsfps);
3402 queue_free(&checkq);
3403 transaction_free(trans);
3407 free_repoinfos(repoinfos, nrepoinfos);
3408 solv_free(commandlinepkgs);
3410 yum_substitute(pool, 0);