2 * Copyright (c) 2009, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
8 /* solv, a little software installer demoing the sat solver library */
11 * - vendor policy loading
12 * - soft locks file handling
13 * - multi version handling
26 #include <sys/utsname.h>
27 #include <sys/types.h>
37 #include "solverdebug.h"
39 #include "repo_solv.h"
41 #include "repo_write.h"
42 #include "repo_rpmdb.h"
43 #include "repo_products.h"
44 #include "repo_rpmmd.h"
45 #include "repo_susetags.h"
46 #include "repo_repomdxml.h"
47 #include "repo_updateinfoxml.h"
48 #include "repo_deltainfoxml.h"
49 #include "repo_content.h"
50 #include "pool_fileconflicts.h"
54 # define REPOINFO_PATH "/etc/yum.repos.d"
56 # define REPOINFO_PATH "/etc/zypp/repos.d"
57 # define PRODUCTS_PATH "/etc/products.d"
60 #define SOLVCACHE_PATH "/var/cache/solv"
78 unsigned char extcookie[32];
83 yum_substitute(Pool *pool, char *line)
88 while ((p2 = strchr(p, '$')) != 0)
90 if (!strncmp(p2, "$releasever", 11))
92 static char *releaseevr;
98 rpm_installedrpmdbids(0, "Providename", "redhat-release", &q);
101 void *handle, *state = 0;
103 handle = rpm_byrpmdbid(q.elements[0], 0, &state);
104 releaseevr = rpm_query(handle, SOLVABLE_EVR);
105 rpm_byrpmdbid(0, 0, &state);
106 if (p = strchr(releaseevr, '-'))
111 releaseevr = strdup("?");
114 p = pool_tmpjoin(pool, line, releaseevr, p2 + 11);
115 p2 = p + (p2 - line);
117 p = p2 + strlen(releaseevr);
120 if (!strncmp(p2, "$basearch", 9))
122 static char *basearch;
131 basearch = strdup(un.machine);
132 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
136 p = pool_tmpjoin(pool, line, basearch, p2 + 9);
137 p2 = p + (p2 - line);
139 p = p2 + strlen(basearch);
148 #define TYPE_UNKNOWN 0
149 #define TYPE_SUSETAGS 1
151 #define TYPE_PLAINDIR 3
154 read_repoinfos_sort(const void *ap, const void *bp)
156 const struct repoinfo *a = ap;
157 const struct repoinfo *b = bp;
158 return strcmp(a->alias, b->alias);
162 read_repoinfos(Pool *pool, const char *reposdir, int *nrepoinfosp)
165 char buf2[4096], *kp, *vp, *kpe;
170 struct repoinfo *repoinfos = 0, *cinfo;
173 rdlen = strlen(reposdir);
174 dir = opendir(reposdir);
180 while ((ent = readdir(dir)) != 0)
182 l = strlen(ent->d_name);
183 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
185 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
186 if ((fp = fopen(buf, "r")) == 0)
192 while(fgets(buf2, sizeof(buf2), fp))
197 while (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t')
200 while (*kp == ' ' || *kp == '\t')
202 if (!*kp || *kp == '#')
206 kp = yum_substitute(pool, kp);
210 vp = strrchr(kp, ']');
214 repoinfos = sat_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
215 cinfo = repoinfos + nrepoinfos++;
216 memset(cinfo, 0, sizeof(*cinfo));
217 cinfo->alias = strdup(kp + 1);
218 cinfo->type = TYPE_RPMMD;
219 cinfo->autorefresh = 1;
224 vp = strchr(kp, '=');
227 for (kpe = vp - 1; kpe >= kp; kpe--)
228 if (*kpe != ' ' && *kpe != '\t')
233 while (*vp == ' ' || *vp == '\t')
236 if (!strcmp(kp, "name"))
237 cinfo->name = strdup(vp);
238 else if (!strcmp(kp, "enabled"))
239 cinfo->enabled = *vp == '0' ? 0 : 1;
240 else if (!strcmp(kp, "autorefresh"))
241 cinfo->autorefresh = *vp == '0' ? 0 : 1;
242 else if (!strcmp(kp, "gpgcheck"))
243 cinfo->gpgcheck = *vp == '0' ? 0 : 1;
244 else if (!strcmp(kp, "baseurl"))
245 cinfo->baseurl = strdup(vp);
246 else if (!strcmp(kp, "mirrorlist"))
248 if (strstr(vp, "metalink"))
249 cinfo->metalink = strdup(vp);
251 else if (!strcmp(kp, "path"))
253 if (vp && strcmp(vp, "/") != 0)
254 cinfo->path = strdup(vp);
256 else if (!strcmp(kp, "type"))
258 if (!strcmp(vp, "yast2"))
259 cinfo->type = TYPE_SUSETAGS;
260 else if (!strcmp(vp, "rpm-md"))
261 cinfo->type = TYPE_RPMMD;
262 else if (!strcmp(vp, "plaindir"))
263 cinfo->type = TYPE_PLAINDIR;
265 cinfo->type = TYPE_UNKNOWN;
267 else if (!strcmp(kp, "priority"))
268 cinfo->priority = atoi(vp);
269 else if (!strcmp(kp, "keeppackages"))
270 cinfo->keeppackages = *vp == '0' ? 0 : 1;
276 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
277 *nrepoinfosp = nrepoinfos;
282 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
285 for (i = 0; i < nrepoinfos; i++)
287 struct repoinfo *cinfo = repoinfos + i;
288 sat_free(cinfo->name);
289 sat_free(cinfo->alias);
290 sat_free(cinfo->path);
291 sat_free(cinfo->metalink);
292 sat_free(cinfo->baseurl);
303 strcpy(tmpl, "/var/tmp/solvXXXXXX");
315 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
322 h = sat_chksum_create(chksumtype);
325 printf("%s: unknown checksum type\n", file);
328 while ((l = read(fd, buf, sizeof(buf))) > 0)
329 sat_chksum_add(h, buf, l);
330 lseek(fd, 0, SEEK_SET);
332 sum = sat_chksum_get(h, &l);
333 if (memcmp(sum, chksum, l))
335 printf("%s: checksum mismatch\n", file);
342 findmetalinkurl(FILE *fp)
344 char buf[4096], *bp, *ep;
345 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
347 while (*bp == ' ' || *bp == '\t')
349 if (strncmp(bp, "<url", 4))
351 bp = strchr(bp, '>');
355 ep = strstr(bp, "repodata/repomd.xml</url>");
359 if (strncmp(bp, "http", 4))
367 cookie_gzread(void *cookie, char *buf, size_t nbytes)
369 return gzread((gzFile *)cookie, buf, nbytes);
373 cookie_gzclose(void *cookie)
375 return gzclose((gzFile *)cookie);
379 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype)
385 const char *baseurl = cinfo->baseurl;
389 if (!cinfo->metalink)
391 if (file != cinfo->metalink)
393 FILE *fp = curlfopen(cinfo, cinfo->metalink, 0, 0, 0);
396 cinfo->baseurl = findmetalinkurl(fp);
400 return curlfopen(cinfo, file, uncompress, chksum, chksumtype);
402 snprintf(url, sizeof(url), "%s", file);
407 if (l && baseurl[l - 1] == '/')
408 snprintf(url, sizeof(url), "%s%s", baseurl, file);
410 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
413 if ((pid = fork()) == (pid_t)-1)
425 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
429 while (waitpid(pid, &status, 0) != pid)
431 if (lseek(fd, 0, SEEK_END) == 0)
437 lseek(fd, 0, SEEK_SET);
438 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
446 cookie_io_functions_t cio;
449 sprintf(tmpl, "/dev/fd/%d", fd);
450 gzf = gzopen(tmpl, "r");
454 memset(&cio, 0, sizeof(cio));
455 cio.read = cookie_gzread;
456 cio.close = cookie_gzclose;
457 return fopencookie(gzf, "r", cio);
459 fcntl(fd, F_SETFD, FD_CLOEXEC);
460 return fdopen(fd, "r");
464 cleanupgpg(char *gpgdir)
467 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
469 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
471 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
473 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
475 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
481 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
490 off_t posfp, possigfp;
493 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
496 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
497 if (!(kfp = fopen(keysfile, "w")) )
503 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
507 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
508 if (!pubkey || !*pubkey)
510 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
512 if (fputc('\n', kfp) == EOF) /* Just in case... */
516 if (fclose(kfp) || !nkeys)
521 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
524 fprintf(stderr, "key import error\n");
529 posfp = lseek(fileno(fp), 0, SEEK_CUR);
530 lseek(fileno(fp), 0, SEEK_SET);
531 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
532 lseek(fileno(sigfp), 0, SEEK_SET);
533 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
534 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
535 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
537 lseek(fileno(sigfp), possigfp, SEEK_SET);
538 lseek(fileno(fp), posfp, SEEK_SET);
539 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
540 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
542 return r == 0 ? 1 : 0;
545 #define CHKSUM_IDENT "1.1"
548 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
551 void *h = sat_chksum_create(chktype);
554 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
555 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
556 sat_chksum_add(h, buf, l);
558 sat_chksum_free(h, out);
562 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *out)
564 void *h = sat_chksum_create(chktype);
565 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
566 sat_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
567 sat_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
568 sat_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
569 sat_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
570 sat_chksum_free(h, out);
582 pool_setarch(pool, un.machine);
585 char *calccachepath(Repo *repo, const char *repoext)
587 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
590 p = pool_tmpjoin(repo->pool, p, "_", repoext);
591 p = pool_tmpjoin(repo->pool, p, ".solvx", 0);
594 p = pool_tmpjoin(repo->pool, p, ".solv", 0);
595 q = p + strlen(SOLVCACHE_PATH) + 1;
605 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie)
608 unsigned char mycookie[32];
609 struct repoinfo *cinfo;
612 cinfo = repo->appdata;
613 if (!(fp = fopen(calccachepath(repo, repoext), "r")))
615 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
620 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
629 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
630 if (repoext && strcmp(repoext, "DL") != 0)
631 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
633 if (repo_add_solv_flags(repo, fp, flags))
638 if (cinfo && !repoext)
640 /* set the checksum so that we can use it with the stub loads */
642 if (!fstat(fileno(fp), &stb))
643 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cinfo->extcookie);
650 myrepodatafilter(Repo *repo, Repokey *key, void *kfdata)
652 Repodata *data = kfdata;
654 /* XXX: special repodata selection hack */
655 if (key->name == 1 && key->size != data - repo->repodata)
657 if (key->storage == KEY_STORAGE_SOLVABLE)
658 return KEY_STORAGE_DROPPED;
659 return repo_write_stdkeyfilter(repo, key, kfdata);
663 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
665 Id *addedfileprovides = 0;
670 struct repoinfo *cinfo;
672 cinfo = repo->appdata;
673 mkdir(SOLVCACHE_PATH, 0755);
674 tmpl = sat_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
682 if (!(fp = fdopen(fd, "w")))
693 info = repo_add_repodata(repo, 0);
696 pool_addfileprovides_ids(repo->pool, 0, &addedfileprovides);
697 if (addedfileprovides && *addedfileprovides)
699 for (i = 0; addedfileprovides[i]; i++)
700 repodata_add_idarray(info, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, addedfileprovides[i]);
702 sat_free(addedfileprovides);
703 repodata_internalize(info);
704 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
707 repo_write(repo, fp, myrepodatafilter, info, 0);
710 if (fwrite(cookie, 32, 1, fp) != 1)
723 if (!repoext && cinfo)
725 /* set the checksum so that we can use it with the stub loads */
727 if (!stat(tmpl, &stb))
728 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cinfo->extcookie);
730 if (!rename(tmpl, calccachepath(repo, repoext)))
739 Pool *sigpool = pool_create();
740 Repo *repo = repo_create(sigpool, "rpmdbkeys");
741 repo_add_rpmdb_pubkeys(repo, 0, 0);
748 static inline const char *
749 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
751 Pool *pool = repo->pool;
753 const char *filename;
758 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
759 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
760 if (dataiterator_step(&di))
762 dataiterator_setpos_parent(&di);
763 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
764 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
766 dataiterator_free(&di);
767 if (filename && !*chksumtypep)
769 printf("no %s file checksum!\n", what);
776 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
778 Pool *pool = repo->pool;
780 Id chksumtype, handle;
781 const unsigned char *chksum;
782 const char *filename;
784 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
785 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
786 if (!dataiterator_step(&di))
788 dataiterator_free(&di);
791 if (!strcmp(what, "prestodelta"))
793 dataiterator_setpos_parent(&di);
794 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
795 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, &chksumtype);
796 if (!filename || !chksum)
798 dataiterator_free(&di);
801 handle = repodata_new_handle(data);
802 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
803 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
805 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
806 if (!strcmp(what, "deltainfo"))
808 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
809 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
811 if (!strcmp(what, "filelists"))
813 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
814 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
816 dataiterator_free(&di);
817 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
822 /* susetags helpers */
824 static inline const char *
825 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
827 Pool *pool = repo->pool;
829 const char *filename;
834 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
835 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
836 if (dataiterator_step(&di))
838 dataiterator_setpos_parent(&di);
839 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
842 dataiterator_free(&di);
843 if (filename && !*chksumtypep)
845 printf("no %s file checksum!\n", what);
851 static Id susetags_langtags[] = {
852 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
853 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
854 SOLVABLE_EULA, REPOKEY_TYPE_STR,
855 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
856 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
857 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
862 susetags_add_ext(Repo *repo, Repodata *data)
864 Pool *pool = repo->pool;
867 Id handle, filechksumtype;
868 const unsigned char *filechksum;
871 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
872 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
873 while (dataiterator_step(&di))
875 if (strncmp(di.kv.str, "packages.", 9) != 0)
877 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
879 ext[0] = di.kv.str[9];
880 ext[1] = di.kv.str[10];
882 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
884 handle = repodata_new_handle(data);
885 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
887 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
888 if (!strcmp(ext, "DU"))
890 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
891 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
893 if (!strcmp(ext, "FL"))
895 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
896 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
900 for (i = 0; susetags_langtags[i]; i += 2)
902 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
903 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
906 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
908 dataiterator_free(&di);
913 iscompressed(const char *name)
915 int l = strlen(name);
916 return l > 3 && !strcmp(name + l - 3, ".gz") ? 1 : 0;
923 load_stub(Pool *pool, Repodata *data, void *dp)
925 const char *filename, *descrdir, *repomdtype;
926 const unsigned char *filechksum;
928 struct repoinfo *cinfo;
933 cinfo = data->repo->appdata;
935 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
939 ext[0] = filename[9];
940 ext[1] = filename[10];
943 printf("[%s:%s", data->repo->name, ext);
945 if (usecachedrepo(data->repo, ext, cinfo->extcookie))
947 printf(" cached]\n"); fflush(stdout);
951 printf(" loading]\n"); fflush(stdout);
953 defvendor = repo_lookup_id(data->repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
954 descrdir = repo_lookup_str(data->repo, SOLVID_META, SUSETAGS_DESCRDIR);
956 descrdir = "suse/setup/descr";
958 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
959 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype)) == 0)
961 repo_add_susetags(data->repo, fp, defvendor, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
963 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
967 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
970 if (!strcmp(repomdtype, "filelists"))
972 else if (!strcmp(repomdtype, "deltainfo"))
977 printf("[%s:%s", data->repo->name, ext);
979 if (usecachedrepo(data->repo, ext, cinfo->extcookie))
981 printf(" cached]\n");fflush(stdout);
984 printf(" loading]\n"); fflush(stdout);
985 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
987 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
988 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype)) == 0)
990 if (!strcmp(ext, "FL"))
991 repo_add_rpmmd(data->repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
992 else if (!strcmp(ext, "DL"))
993 repo_add_deltainfoxml(data->repo, fp, REPO_USE_LOADING);
995 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
1003 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1006 struct repoinfo *cinfo;
1010 const char *filename;
1011 const unsigned char *filechksum;
1013 const char *descrdir;
1016 unsigned char cookie[32];
1020 repo = repo_create(pool, "@System");
1021 printf("rpm database:");
1022 if (stat("/var/lib/rpm/Packages", &stb))
1023 memset(&stb, 0, sizeof(&stb));
1024 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cookie);
1025 if (usecachedrepo(repo, 0, cookie))
1026 printf(" cached\n");
1030 printf(" reading\n");
1033 #ifdef PRODUCTS_PATH
1034 repo_add_products(repo, PRODUCTS_PATH, 0, REPO_NO_INTERNALIZE);
1036 if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
1038 Repo *ref = repo_create(pool, "@System.old");
1039 if (!repo_add_solv(ref, ofp))
1041 repo_add_rpmdb(repo, ref, 0, REPO_REUSE_REPODATA);
1048 repo_add_rpmdb(repo, 0, 0, REPO_REUSE_REPODATA);
1049 writecachedrepo(repo, 0, 0, cookie);
1051 pool_set_installed(pool, repo);
1053 for (i = 0; i < nrepoinfos; i++)
1055 cinfo = repoinfos + i;
1056 if (!cinfo->enabled)
1059 repo = repo_create(pool, cinfo->alias);
1061 repo->appdata = cinfo;
1062 repo->priority = 99 - cinfo->priority;
1064 if (!cinfo->autorefresh && usecachedrepo(repo, 0, 0))
1066 printf("repo '%s':", cinfo->alias);
1067 printf(" cached\n");
1070 switch (cinfo->type)
1073 printf("rpmmd repo '%s':", cinfo->alias);
1075 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0)) == 0)
1077 printf(" no repomd.xml file, skipped\n");
1082 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cookie);
1083 if (usecachedrepo(repo, 0, cookie))
1085 printf(" cached\n");
1089 sigfp = curlfopen(cinfo, "repodata/repomd.xml.asc", 0, 0, 0);
1093 printf(" unsigned, skipped\n");
1101 sigpool = read_sigs();
1102 if (!checksig(sigpool, fp, sigfp))
1104 printf(" checksig failed, skipped\n");
1111 repo_add_repomdxml(repo, fp, 0);
1113 printf(" reading\n");
1114 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1115 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype)) != 0)
1117 repo_add_rpmmd(repo, fp, 0, 0);
1121 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1122 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype)) != 0)
1124 repo_add_updateinfoxml(repo, fp, 0);
1128 data = repo_last_repodata(repo);
1129 if (!repomd_add_ext(repo, data, "deltainfo"))
1130 repomd_add_ext(repo, data, "prestodelta");
1131 repomd_add_ext(repo, data, "filelists");
1132 repodata_internalize(data);
1133 writecachedrepo(repo, data, 0, cookie);
1134 repodata_create_stubs(data);
1138 printf("susetags repo '%s':", cinfo->alias);
1142 if ((fp = curlfopen(cinfo, "content", 0, 0, 0)) == 0)
1144 printf(" no content file, skipped\n");
1149 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cookie);
1150 if (usecachedrepo(repo, 0, cookie))
1152 printf(" cached\n");
1156 sigfp = curlfopen(cinfo, "content.asc", 0, 0, 0);
1159 printf(" unsigned, skipped\n");
1166 sigpool = read_sigs();
1167 if (!checksig(sigpool, fp, sigfp))
1169 printf(" checksig failed, skipped\n");
1176 repo_add_content(repo, fp, 0);
1178 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1179 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1181 descrdir = "suse/setup/descr";
1182 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1184 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1187 printf(" no packages file entry, skipped\n");
1190 printf(" reading\n");
1191 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype)) == 0)
1193 repo_add_susetags(repo, fp, defvendor, 0, 0);
1195 data = repo_last_repodata(repo);
1196 susetags_add_ext(repo, data);
1197 repodata_internalize(data);
1198 writecachedrepo(repo, data, 0, cookie);
1199 repodata_create_stubs(data);
1202 printf("unsupported repo '%s': skipped\n", cinfo->alias);
1214 str2archid(Pool *pool, char *arch)
1219 id = str2id(pool, arch, 0);
1220 if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH)
1222 if (pool->id2arch && (id > pool->lastarch || !pool->id2arch[id]))
1228 depglob(Pool *pool, char *name, Queue *job)
1231 Id id = str2id(pool, name, 0);
1236 FOR_PROVIDES(p, pp, id)
1238 Solvable *s = pool->solvables + p;
1242 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
1248 printf("[using capability match for '%s']\n", name);
1249 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
1254 if (strpbrk(name, "[*?") == 0)
1257 /* looks like a name glob. hard work. */
1258 for (p = 1; p < pool->nsolvables; p++)
1260 Solvable *s = pool->solvables + p;
1261 if (!s->repo || !pool_installable(pool, s))
1264 if (fnmatch(name, id2str(pool, id), 0) == 0)
1266 for (i = 0; i < job->count; i += 2)
1267 if (job->elements[i] == SOLVER_SOLVABLE_NAME && job->elements[i + 1] == id)
1269 if (i == job->count)
1270 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
1276 /* looks like a dep glob. really hard work. */
1277 for (id = 1; id < pool->ss.nstrings; id++)
1279 if (!pool->whatprovides[id])
1281 if (fnmatch(name, id2str(pool, id), 0) == 0)
1284 printf("[using capability match for '%s']\n", name);
1285 for (i = 0; i < job->count; i += 2)
1286 if (job->elements[i] == SOLVER_SOLVABLE_PROVIDES && job->elements[i + 1] == id)
1288 if (i == job->count)
1289 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
1299 addrelation(Pool *pool, Queue *job, int flags, Id evr)
1302 for (i = 0; i < job->count; i += 2)
1304 if (job->elements[i] != SOLVER_SOLVABLE_NAME && job->elements[i] != SOLVER_SOLVABLE_PROVIDES)
1306 job->elements[i + 1] = rel2id(pool, job->elements[i + 1], evr, flags, 1);
1311 limitevr(Pool *pool, char *evr, Queue *job, Id archid)
1320 for (i = 0; i < job->count; i += 2)
1323 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
1325 s = pool_id2solvable(pool, p);
1326 if (archid && s->arch != archid)
1328 if (evrcmp_str(pool, id2str(pool, s->evr), evr, EVRCMP_MATCH) == 0)
1335 queue_deleten(job, 0, i);
1339 /* if all solvables have the same evr */
1340 s = pool_id2solvable(pool, mq.elements[0]);
1342 for (j = 0; j < mq.count; j++)
1344 s = pool_id2solvable(pool, mq.elements[j]);
1345 if (s->evr != evrid)
1348 if (j == mq.count && j > 1)
1350 prune_to_best_arch(pool, &mq);
1351 // prune_to_highest_prio(pool, &mq);
1356 job->elements[i] = SOLVER_SOLVABLE_ONE_OF;
1357 job->elements[i + 1] = pool_queuetowhatprovides(pool, &mq);
1361 job->elements[i] = SOLVER_SOLVABLE;
1362 job->elements[i + 1] = mq.elements[0];
1367 queue_deleten(job, i, 2);
1377 if ((r = strrchr(evr, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
1380 if (limitevr(pool, evr, job, archid))
1392 mkselect(Pool *pool, char *name, Queue *job)
1404 dataiterator_init(&di, pool, 0, 0, SOLVABLE_FILELIST, name, SEARCH_STRING|SEARCH_FILES|SEARCH_COMPLETE_FILELIST);
1405 while (dataiterator_step(&di))
1407 queue_push(&q, di.solvid);
1408 dataiterator_skip_solvable(&di);
1410 dataiterator_free(&di);
1413 printf("[using file list match for '%s']\n", name);
1415 queue_push2(job, SOLVER_SOLVABLE_ONE_OF, pool_queuetowhatprovides(pool, &q));
1421 if ((r = strpbrk(name, "<=>")) != 0)
1423 /* relation case, support:
1428 int nend = r - name;
1440 while (*r && *r == ' ' && *r == '\t')
1442 while (nend && (name[nend - 1] == ' ' || name[nend -1 ] == '\t'))
1447 fprintf(stderr, "bad relation\n");
1450 if (depglob(pool, name, job))
1452 addrelation(pool, job, rflags, str2id(pool, r, 1));
1455 if ((r2 = strrchr(name, '.')) != 0 && r2[1] && (archid = str2archid(pool, r2 + 1)) != 0)
1458 if (depglob(pool, name, job))
1461 addrelation(pool, job, REL_ARCH, archid);
1462 addrelation(pool, job, rflags, str2id(pool, r, 1));
1470 /* no relation case, support:
1473 * depglob-version-release
1474 * depglob-version-release.arch
1476 if (depglob(pool, name, job))
1479 if ((r = strrchr(name, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
1482 if (depglob(pool, name, job))
1485 addrelation(pool, job, REL_ARCH, archid);
1490 if ((r = strrchr(name, '-')) != 0)
1493 if (depglob(pool, name, job))
1495 /* have just the version */
1497 if (limitevr(pool, r + 1, job, 0))
1500 if ((r2 = strrchr(name, '-')) != 0)
1504 if (depglob(pool, name, job))
1507 if (limitevr(pool, r2 + 1, job, 0))
1515 fprintf(stderr, "nothing matches '%s'\n", name);
1521 yesno(const char *str)
1523 char inbuf[128], *ip;
1530 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
1535 while (*ip == ' ' || *ip == '\t')
1542 if (*ip == 'y' || *ip == 'n')
1543 return *ip == 'y' ? 1 : 0;
1555 fc_cb(Pool *pool, Id p, void *cbdata)
1557 struct fcstate *fcstate = cbdata;
1565 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
1568 s = pool_id2solvable(pool, p);
1569 if (pool->installed && s->repo == pool->installed)
1571 if (!s->repo->rpmdbid)
1573 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
1576 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
1578 for (i = 0; i < fcstate->newpkgscnt; i++)
1579 if (fcstate->checkq->elements[i] == p)
1581 if (i == fcstate->newpkgscnt)
1583 fp = fcstate->newpkgsfps[i];
1587 return rpm_byfp(fp, solvable2str(pool, s), &fcstate->rpmdbstate);
1591 runrpm(const char *arg, const char *name, int dupfd3)
1596 if ((pid = fork()) == (pid_t)-1)
1603 if (dupfd3 != -1 && dupfd3 != 3)
1609 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
1610 if (strcmp(arg, "-e") == 0)
1611 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
1613 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
1617 while (waitpid(pid, &status, 0) != pid)
1621 printf("rpm failed\n");
1627 nscallback(Pool *pool, void *data, Id name, Id evr)
1629 if (name == NAMESPACE_PRODUCTBUDDY)
1631 /* SUSE specific hack: each product has an associated rpm */
1632 Solvable *s = pool->solvables + evr;
1635 cap = str2id(pool, pool_tmpjoin(pool, "product(", id2str(pool, s->name) + 8, ")"), 0);
1638 cap = rel2id(pool, cap, s->evr, REL_EQ, 0);
1641 FOR_PROVIDES(p, pp, cap)
1643 Solvable *ps = pool->solvables + p;
1644 if (ps->repo == s->repo && ps->arch == s->arch)
1654 main(int argc, char **argv)
1657 Repo *commandlinerepo = 0;
1658 Id *commandlinepkgs = 0;
1660 struct repoinfo *repoinfos;
1662 int i, mode, newpkgs;
1666 char inbuf[128], *ip;
1668 int distupgrade = 0;
1671 struct fcstate fcstate;
1677 fprintf(stderr, "Usage: solv install|erase|update|show <select>\n");
1680 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
1681 mode = SOLVER_INSTALL;
1682 else if (!strcmp(argv[0], "patch"))
1684 mode = SOLVER_UPDATE;
1687 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
1688 mode = SOLVER_ERASE;
1689 else if (!strcmp(argv[0], "show"))
1691 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
1692 mode = SOLVER_UPDATE;
1693 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
1695 mode = SOLVER_UPDATE;
1700 fprintf(stderr, "Usage: solv install|erase|update|show <select>\n");
1704 pool = pool_create();
1705 pool_setloadcallback(pool, load_stub, 0);
1706 pool->nscallback = nscallback;
1707 // pool_setdebuglevel(pool, 2);
1709 repoinfos = read_repoinfos(pool, REPOINFO_PATH, &nrepoinfos);
1710 read_repos(pool, repoinfos, nrepoinfos);
1712 if (mode == 0 || mode == SOLVER_INSTALL)
1714 for (i = 1; i < argc; i++)
1717 l = strlen(argv[i]);
1718 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
1720 if (access(argv[i], R_OK))
1725 if (!commandlinepkgs)
1726 commandlinepkgs = sat_calloc(argc, sizeof(Id));
1727 if (!commandlinerepo)
1728 commandlinerepo = repo_create(pool, "@commandline");
1729 repo_add_rpms(commandlinerepo, (const char **)argv + i, 1, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
1730 commandlinepkgs[i] = commandlinerepo->end - 1;
1732 if (commandlinerepo)
1733 repo_internalize(commandlinerepo);
1736 // FOR_REPOS(i, repo)
1737 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
1738 pool_addfileprovides(pool);
1739 pool_createwhatprovides(pool);
1742 for (i = 1; i < argc; i++)
1744 if (commandlinepkgs && commandlinepkgs[i])
1746 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
1749 mkselect(pool, argv[i], &job);
1751 if (!job.count && mode == SOLVER_UPDATE)
1753 else if (!job.count)
1755 printf("no package matched\n");
1761 /* show mode, no solver needed */
1762 for (i = 0; i < job.count; i += 2)
1764 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
1766 Solvable *s = pool_id2solvable(pool, p);
1767 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de");
1768 printf(" - %s [%s]\n", solvable2str(pool, s), s->repo->name);
1770 printf(" %s\n", sum);
1775 free_repoinfos(repoinfos, nrepoinfos);
1776 sat_free(commandlinepkgs);
1780 if (updateall && patchmode)
1786 map_init(&installedmap, pool->nsolvables);
1787 if (pool->installed)
1788 FOR_REPO_SOLVABLES(pool->installed, p, s)
1789 MAPSET(&installedmap, p);
1791 /* install all patches */
1793 mode = SOLVER_INSTALL;
1794 for (p = 1; p < pool->nsolvables; p++)
1800 s = pool->solvables + p;
1801 if (strncmp(id2str(pool, s->name), "patch:", 6) != 0)
1803 FOR_PROVIDES(p2, pp, s->name)
1805 Solvable *s2 = pool->solvables + p2;
1806 if (s2->name != s->name)
1808 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
1809 if (r < 0 || (r == 0 && p > p2))
1814 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
1815 if (type && !strcmp(type, "optional"))
1817 r = solvable_trivial_installable_map(s, &installedmap, 0);
1820 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
1827 queue_push2(&job, SOLVER_SOLVABLE, p);
1829 map_free(&installedmap);
1833 for (i = 0; i < job.count; i += 2)
1835 if (mode == SOLVER_UPDATE)
1837 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
1838 if (pool->installed && pool->solvables[p].repo == pool->installed)
1842 job.elements[i] |= SOLVER_INSTALL;
1846 job.elements[i] |= mode;
1849 // multiversion test
1850 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae", 1));
1851 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-base", 1));
1852 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-extra", 1));
1857 Id problem, solution;
1860 solv = solver_create(pool);
1861 solv->ignorealreadyrecommended = 1;
1862 solv->updatesystem = updateall;
1863 solv->dosplitprovides = updateall;
1864 if (updateall && distupgrade)
1866 solv->distupgrade = 1;
1867 solv->allowdowngrade = 1;
1868 solv->allowarchchange = 1;
1869 solv->allowvendorchange = 1;
1871 // queue_push2(&job, SOLVER_DISTUPGRADE, 3);
1872 solver_solve(solv, &job);
1873 if (!solv->problems.count)
1875 pcnt = solver_problem_count(solv);
1876 printf("Found %d problems:\n", pcnt);
1877 for (problem = 1; problem <= pcnt; problem++)
1880 printf("Problem %d:\n", problem);
1881 solver_printprobleminfo(solv, problem);
1883 scnt = solver_solution_count(solv, problem);
1884 for (solution = 1; solution <= scnt; solution++)
1886 printf("Solution %d:\n", solution);
1887 solver_printsolution(solv, problem, solution);
1892 printf("Please choose a solution: ");
1895 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
1900 while (*ip == ' ' || *ip == '\t')
1902 if (*ip >= '0' && *ip <= '9')
1905 if (take >= 1 && take <= scnt)
1921 solver_take_solution(solv, problem, take, &job);
1927 trans = &solv->trans;
1928 if (!trans->steps.count)
1930 printf("Nothing to do.\n");
1934 printf("Transaction summary:\n\n");
1935 solver_printtransaction(solv);
1944 duc[1].path = "/usr/share/man";
1945 duc[2].path = "/sbin";
1946 duc[3].path = "/etc";
1947 transaction_calc_duchanges(trans, duc, 4);
1948 for (i = 0; i < 4; i++)
1949 printf("duchanges %s: %d K %d\n", duc[i].path, duc[i].kbytes, duc[i].files);
1950 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
1954 if (!yesno("OK to continue (y/n)? "))
1960 queue_init(&checkq);
1961 newpkgs = transaction_installedresult(trans, &checkq);
1966 printf("Downloading %d packages\n", newpkgs);
1967 newpkgsfps = sat_calloc(newpkgs, sizeof(*newpkgsfps));
1968 for (i = 0; i < newpkgs; i++)
1970 unsigned int medianr;
1973 struct repoinfo *cinfo;
1974 const unsigned char *chksum;
1978 p = checkq.elements[i];
1979 s = pool_id2solvable(pool, p);
1980 if (s->repo == commandlinerepo)
1982 loc = solvable_get_location(s, &medianr);
1983 if (!(newpkgsfps[i] = fopen(loc, "r")))
1991 cinfo = s->repo->appdata;
1994 printf("%s: no repository information\n", s->repo->name);
1997 loc = solvable_get_location(s, &medianr);
2001 if (pool->installed && pool->installed->nsolvables)
2003 /* try a delta first */
2004 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, id2str(pool, s->name), SEARCH_STRING);
2005 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
2006 while (dataiterator_step(&di))
2010 dataiterator_setpos_parent(&di);
2011 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
2012 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
2014 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
2015 FOR_PROVIDES(op, pp, s->name)
2017 Solvable *os = pool->solvables + op;
2018 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
2021 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
2023 /* base is installed, run sequence check */
2024 const char *seqname;
2033 seqname = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME);
2034 seqevr = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR);
2035 seqnum = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM);
2036 seq = pool_tmpjoin(pool, seqname, "-", seqevr);
2037 seq = pool_tmpjoin(pool, seq, "-", seqnum);
2038 if (system(pool_tmpjoin(pool, "/usr/bin/applydeltarpm -c -s ", seq, 0)) != 0)
2039 continue; /* didn't match */
2040 /* looks good, download delta */
2042 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
2044 continue; /* no way! */
2045 dloc = pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_DIR);
2046 dloc = pool_tmpjoin(pool, dloc, "/", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_NAME));
2047 dloc = pool_tmpjoin(pool, dloc, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_EVR));
2048 dloc = pool_tmpjoin(pool, dloc, ".", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_SUFFIX));
2049 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype)) == 0)
2051 /* got it, now reconstruct */
2052 newfd = opentmpfile();
2053 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
2054 fcntl(fileno(fp), F_SETFD, 0);
2061 lseek(newfd, 0, SEEK_SET);
2063 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
2064 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
2070 newpkgsfps[i] = fdopen(newfd, "r");
2075 dataiterator_free(&di);
2082 continue; /* delta worked! */
2084 if (cinfo->type == TYPE_SUSETAGS)
2086 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
2087 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
2090 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
2091 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype)) == 0)
2093 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
2106 printf("Searching for file conflicts\n");
2107 queue_init(&conflicts);
2108 fcstate.rpmdbstate = 0;
2109 fcstate.newpkgscnt = newpkgs;
2110 fcstate.checkq = &checkq;
2111 fcstate.newpkgsfps = newpkgsfps;
2112 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fc_cb, &fcstate);
2113 if (conflicts.count)
2116 for (i = 0; i < conflicts.count; i += 5)
2117 printf("file %s of package %s conflicts with package %s\n", id2str(pool, conflicts.elements[i]), solvid2str(pool, conflicts.elements[i + 1]), solvid2str(pool, conflicts.elements[i + 3]));
2119 if (yesno("Re-run solver (y/n/q)? "))
2121 for (i = 0; i < newpkgs; i++)
2123 fclose(newpkgsfps[i]);
2124 newpkgsfps = sat_free(newpkgsfps);
2126 pool_add_fileconflicts_deps(pool, &conflicts);
2127 pool_createwhatprovides(pool); /* Hmm... */
2131 queue_free(&conflicts);
2134 printf("Committing transaction:\n\n");
2135 transaction_order(trans, 0);
2136 for (i = 0; i < trans->steps.count; i++)
2138 const char *evr, *evrp, *nvra;
2143 p = trans->steps.elements[i];
2144 s = pool_id2solvable(pool, p);
2145 Id type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
2148 case SOLVER_TRANSACTION_ERASE:
2149 printf("erase %s\n", solvid2str(pool, p));
2150 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
2152 /* strip epoch from evr */
2153 evr = evrp = id2str(pool, s->evr);
2154 while (*evrp >= '0' && *evrp <= '9')
2156 if (evrp > evr && evrp[0] == ':' && evrp[1])
2158 nvra = pool_tmpjoin(pool, id2str(pool, s->name), "-", evr);
2159 nvra = pool_tmpjoin(pool, nvra, ".", id2str(pool, s->arch));
2160 runrpm("-e", nvra, -1); /* to bad that --querybynumber doesn't work */
2162 case SOLVER_TRANSACTION_INSTALL:
2163 case SOLVER_TRANSACTION_MULTIINSTALL:
2164 printf("install %s\n", solvid2str(pool, p));
2165 for (j = 0; j < newpkgs; j++)
2166 if (checkq.elements[j] == p)
2168 fp = j < newpkgs ? newpkgsfps[j] : 0;
2172 lseek(fileno(fp), 0, SEEK_SET);
2173 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp));
2182 for (i = 0; i < newpkgs; i++)
2184 fclose(newpkgsfps[i]);
2185 sat_free(newpkgsfps);
2186 queue_free(&checkq);
2190 free_repoinfos(repoinfos, nrepoinfos);
2191 sat_free(commandlinepkgs);