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>
39 #include "solverdebug.h"
41 #include "repo_solv.h"
43 #include "repo_write.h"
44 #include "repo_rpmdb.h"
45 #include "repo_products.h"
46 #include "repo_rpmmd.h"
47 #include "repo_susetags.h"
48 #include "repo_repomdxml.h"
49 #include "repo_updateinfoxml.h"
50 #include "repo_deltainfoxml.h"
51 #include "repo_content.h"
52 #include "pool_fileconflicts.h"
56 # define REPOINFO_PATH "/etc/yum.repos.d"
58 # define REPOINFO_PATH "/etc/zypp/repos.d"
59 # define PRODUCTS_PATH "/etc/products.d"
62 #define SOLVCACHE_PATH "/var/cache/solv"
64 #define METADATA_EXPIRE (60 * 90)
82 unsigned char extcookie[32];
87 yum_substitute(Pool *pool, char *line)
92 while ((p2 = strchr(p, '$')) != 0)
94 if (!strncmp(p2, "$releasever", 11))
96 static char *releaseevr;
102 rpm_installedrpmdbids(0, "Providename", "redhat-release", &q);
105 void *handle, *state = 0;
107 handle = rpm_byrpmdbid(q.elements[0], 0, &state);
108 releaseevr = rpm_query(handle, SOLVABLE_EVR);
109 rpm_byrpmdbid(0, 0, &state);
110 if ((p = strchr(releaseevr, '-')) != 0)
115 releaseevr = strdup("?");
118 p = pool_tmpjoin(pool, line, releaseevr, p2 + 11);
119 p2 = p + (p2 - line);
121 p = p2 + strlen(releaseevr);
124 if (!strncmp(p2, "$basearch", 9))
126 static char *basearch;
135 basearch = strdup(un.machine);
136 if (basearch[0] == 'i' && basearch[1] && !strcmp(basearch + 2, "86"))
140 p = pool_tmpjoin(pool, line, basearch, p2 + 9);
141 p2 = p + (p2 - line);
143 p = p2 + strlen(basearch);
152 #define TYPE_UNKNOWN 0
153 #define TYPE_SUSETAGS 1
155 #define TYPE_PLAINDIR 3
158 read_repoinfos_sort(const void *ap, const void *bp)
160 const struct repoinfo *a = ap;
161 const struct repoinfo *b = bp;
162 return strcmp(a->alias, b->alias);
166 read_repoinfos(Pool *pool, const char *reposdir, int *nrepoinfosp)
169 char buf2[4096], *kp, *vp, *kpe;
174 struct repoinfo *repoinfos = 0, *cinfo;
177 rdlen = strlen(reposdir);
178 dir = opendir(reposdir);
184 while ((ent = readdir(dir)) != 0)
186 l = strlen(ent->d_name);
187 if (l < 6 || rdlen + 2 + l >= sizeof(buf) || strcmp(ent->d_name + l - 5, ".repo") != 0)
189 snprintf(buf, sizeof(buf), "%s/%s", reposdir, ent->d_name);
190 if ((fp = fopen(buf, "r")) == 0)
196 while(fgets(buf2, sizeof(buf2), fp))
201 while (buf2[l - 1] == '\n' || buf2[l - 1] == ' ' || buf2[l - 1] == '\t')
204 while (*kp == ' ' || *kp == '\t')
206 if (!*kp || *kp == '#')
210 kp = yum_substitute(pool, kp);
214 vp = strrchr(kp, ']');
218 repoinfos = sat_extend(repoinfos, nrepoinfos, 1, sizeof(*repoinfos), 15);
219 cinfo = repoinfos + nrepoinfos++;
220 memset(cinfo, 0, sizeof(*cinfo));
221 cinfo->alias = strdup(kp + 1);
222 cinfo->type = TYPE_RPMMD;
223 cinfo->autorefresh = 1;
224 cinfo->metadata_expire = METADATA_EXPIRE;
229 vp = strchr(kp, '=');
232 for (kpe = vp - 1; kpe >= kp; kpe--)
233 if (*kpe != ' ' && *kpe != '\t')
238 while (*vp == ' ' || *vp == '\t')
241 if (!strcmp(kp, "name"))
242 cinfo->name = strdup(vp);
243 else if (!strcmp(kp, "enabled"))
244 cinfo->enabled = *vp == '0' ? 0 : 1;
245 else if (!strcmp(kp, "autorefresh"))
246 cinfo->autorefresh = *vp == '0' ? 0 : 1;
247 else if (!strcmp(kp, "gpgcheck"))
248 cinfo->gpgcheck = *vp == '0' ? 0 : 1;
249 else if (!strcmp(kp, "baseurl"))
250 cinfo->baseurl = strdup(vp);
251 else if (!strcmp(kp, "mirrorlist"))
253 if (strstr(vp, "metalink"))
254 cinfo->metalink = strdup(vp);
256 else if (!strcmp(kp, "path"))
258 if (vp && strcmp(vp, "/") != 0)
259 cinfo->path = strdup(vp);
261 else if (!strcmp(kp, "type"))
263 if (!strcmp(vp, "yast2"))
264 cinfo->type = TYPE_SUSETAGS;
265 else if (!strcmp(vp, "rpm-md"))
266 cinfo->type = TYPE_RPMMD;
267 else if (!strcmp(vp, "plaindir"))
268 cinfo->type = TYPE_PLAINDIR;
270 cinfo->type = TYPE_UNKNOWN;
272 else if (!strcmp(kp, "priority"))
273 cinfo->priority = atoi(vp);
274 else if (!strcmp(kp, "keeppackages"))
275 cinfo->keeppackages = *vp == '0' ? 0 : 1;
281 qsort(repoinfos, nrepoinfos, sizeof(*repoinfos), read_repoinfos_sort);
282 *nrepoinfosp = nrepoinfos;
287 free_repoinfos(struct repoinfo *repoinfos, int nrepoinfos)
290 for (i = 0; i < nrepoinfos; i++)
292 struct repoinfo *cinfo = repoinfos + i;
293 sat_free(cinfo->name);
294 sat_free(cinfo->alias);
295 sat_free(cinfo->path);
296 sat_free(cinfo->metalink);
297 sat_free(cinfo->baseurl);
308 strcpy(tmpl, "/var/tmp/solvXXXXXX");
320 verify_checksum(int fd, const char *file, const unsigned char *chksum, Id chksumtype)
327 h = sat_chksum_create(chksumtype);
330 printf("%s: unknown checksum type\n", file);
333 while ((l = read(fd, buf, sizeof(buf))) > 0)
334 sat_chksum_add(h, buf, l);
335 lseek(fd, 0, SEEK_SET);
337 sum = sat_chksum_get(h, &l);
338 if (memcmp(sum, chksum, l))
340 printf("%s: checksum mismatch\n", file);
347 findmetalinkurl(FILE *fp)
349 char buf[4096], *bp, *ep;
350 while((bp = fgets(buf, sizeof(buf), fp)) != 0)
352 while (*bp == ' ' || *bp == '\t')
354 if (strncmp(bp, "<url", 4))
356 bp = strchr(bp, '>');
360 ep = strstr(bp, "repodata/repomd.xml</url>");
364 if (strncmp(bp, "http", 4))
372 cookie_gzread(void *cookie, char *buf, size_t nbytes)
374 return gzread((gzFile *)cookie, buf, nbytes);
378 cookie_gzclose(void *cookie)
380 return gzclose((gzFile *)cookie);
384 curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int *badchecksump)
390 const char *baseurl = cinfo->baseurl;
394 if (!cinfo->metalink)
396 if (file != cinfo->metalink)
398 FILE *fp = curlfopen(cinfo, cinfo->metalink, 0, 0, 0, 0);
401 cinfo->baseurl = findmetalinkurl(fp);
405 return curlfopen(cinfo, file, uncompress, chksum, chksumtype, badchecksump);
407 snprintf(url, sizeof(url), "%s", file);
412 if (l && baseurl[l - 1] == '/')
413 snprintf(url, sizeof(url), "%s%s", baseurl, file);
415 snprintf(url, sizeof(url), "%s/%s", baseurl, file);
418 if ((pid = fork()) == (pid_t)-1)
430 execlp("curl", "curl", "-f", "-s", "-L", url, (char *)0);
435 while (waitpid(pid, &status, 0) != pid)
437 if (lseek(fd, 0, SEEK_END) == 0 && (!status || !chksumtype))
443 lseek(fd, 0, SEEK_SET);
446 printf("%s: download error %d\n", file, status >> 8 ? status >> 8 : status);
452 if (chksumtype && !verify_checksum(fd, file, chksum, chksumtype))
462 cookie_io_functions_t cio;
465 sprintf(tmpl, "/dev/fd/%d", fd);
466 gzf = gzopen(tmpl, "r");
470 fprintf(stderr, "could not open /dev/fd/%d, /proc not mounted?\n", fd);
473 memset(&cio, 0, sizeof(cio));
474 cio.read = cookie_gzread;
475 cio.close = cookie_gzclose;
476 return fopencookie(gzf, "r", cio);
478 fcntl(fd, F_SETFD, FD_CLOEXEC);
479 return fdopen(fd, "r");
483 cleanupgpg(char *gpgdir)
486 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
488 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
490 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
492 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
494 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
500 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
509 off_t posfp, possigfp;
512 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
515 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
516 if (!(kfp = fopen(keysfile, "w")) )
522 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
526 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
527 if (!pubkey || !*pubkey)
529 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
531 if (fputc('\n', kfp) == EOF) /* Just in case... */
535 if (fclose(kfp) || !nkeys)
540 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
543 fprintf(stderr, "key import error\n");
548 posfp = lseek(fileno(fp), 0, SEEK_CUR);
549 lseek(fileno(fp), 0, SEEK_SET);
550 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
551 lseek(fileno(sigfp), 0, SEEK_SET);
552 snprintf(cmd, sizeof(cmd), "gpg -q --homedir %s --verify /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, fileno(sigfp), fileno(fp));
553 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
554 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
556 lseek(fileno(sigfp), possigfp, SEEK_SET);
557 lseek(fileno(fp), posfp, SEEK_SET);
558 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
559 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
561 return r == 0 ? 1 : 0;
564 #define CHKSUM_IDENT "1.1"
567 calc_checksum_fp(FILE *fp, Id chktype, unsigned char *out)
570 void *h = sat_chksum_create(chktype);
573 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
574 while ((l = fread(buf, 1, sizeof(buf), fp)) > 0)
575 sat_chksum_add(h, buf, l);
577 sat_chksum_free(h, out);
581 calc_checksum_stat(struct stat *stb, Id chktype, unsigned char *out)
583 void *h = sat_chksum_create(chktype);
584 sat_chksum_add(h, CHKSUM_IDENT, strlen(CHKSUM_IDENT));
585 sat_chksum_add(h, &stb->st_dev, sizeof(stb->st_dev));
586 sat_chksum_add(h, &stb->st_ino, sizeof(stb->st_ino));
587 sat_chksum_add(h, &stb->st_size, sizeof(stb->st_size));
588 sat_chksum_add(h, &stb->st_mtime, sizeof(stb->st_mtime));
589 sat_chksum_free(h, out);
601 pool_setarch(pool, un.machine);
604 char *calccachepath(Repo *repo, const char *repoext)
606 char *q, *p = pool_tmpjoin(repo->pool, SOLVCACHE_PATH, "/", repo->name);
609 p = pool_tmpjoin(repo->pool, p, "_", repoext);
610 p = pool_tmpjoin(repo->pool, p, ".solvx", 0);
613 p = pool_tmpjoin(repo->pool, p, ".solv", 0);
614 q = p + strlen(SOLVCACHE_PATH) + 1;
624 usecachedrepo(Repo *repo, const char *repoext, unsigned char *cookie, int mark)
627 unsigned char mycookie[32];
628 struct repoinfo *cinfo;
631 cinfo = repo->appdata;
632 if (!(fp = fopen(calccachepath(repo, repoext), "r")))
634 if (fseek(fp, -sizeof(mycookie), SEEK_END) || fread(mycookie, sizeof(mycookie), 1, fp) != 1)
639 if (cookie && memcmp(cookie, mycookie, sizeof(mycookie)))
648 flags = REPO_USE_LOADING|REPO_EXTEND_SOLVABLES;
649 if (repoext && strcmp(repoext, "DL") != 0)
650 flags |= REPO_LOCALPOOL; /* no local pool for DL so that we can compare IDs */
652 if (repo_add_solv_flags(repo, fp, flags))
657 if (cinfo && !repoext)
659 /* set the checksum so that we can use it with the stub loads */
661 if (!fstat(fileno(fp), &stb))
662 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cinfo->extcookie);
665 futimes(fileno(fp), 0); /* try to set modification time */
671 writecachedrepo(Repo *repo, Repodata *info, const char *repoext, unsigned char *cookie)
673 Id *addedfileprovides = 0;
678 struct repoinfo *cinfo;
681 cinfo = repo->appdata;
682 mkdir(SOLVCACHE_PATH, 0755);
683 tmpl = sat_dupjoin(SOLVCACHE_PATH, "/", ".newsolv-XXXXXX");
691 if (!(fp = fdopen(fd, "w")))
700 for (i = repo->start; i < repo->end; i++)
701 if (repo->pool->solvables[i].repo != repo)
710 info = repo_add_repodata(repo, 0);
713 pool_addfileprovides_ids(repo->pool, 0, &addedfileprovides);
714 if (addedfileprovides && *addedfileprovides)
716 for (i = 0; addedfileprovides[i]; i++)
717 repodata_add_idarray(info, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, addedfileprovides[i]);
719 sat_free(addedfileprovides);
720 repodata_internalize(info);
721 repo_write(repo, fp, repo_write_stdkeyfilter, 0, 0);
724 repodata_write(info, fp, repo_write_stdkeyfilter, 0);
727 if (fwrite(cookie, 32, 1, fp) != 1)
740 if (!repoext && cinfo)
742 /* set the checksum so that we can use it with the stub loads */
744 if (!stat(tmpl, &stb))
745 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cinfo->extcookie);
749 /* switch to just saved repo to activate paging and save memory */
750 FILE *fp = fopen(tmpl, "r");
757 if (repo_add_solv(repo, fp))
759 /* oops, no way to recover from here */
760 fprintf(stderr, "internal error\n");
766 /* make sure repodata contains complete repo */
767 /* (this is how repodata_write saves it) */
768 repodata_extend_block(info, repo->start, repo->end - repo->start);
769 info->state = REPODATA_LOADING;
770 /* no need for LOCALPOOL as pool already contains ids */
771 repo_add_solv_flags(repo, fp, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
772 info->state = REPODATA_AVAILABLE; /* in case the load failed */
777 if (!rename(tmpl, calccachepath(repo, repoext)))
786 Pool *sigpool = pool_create();
787 Repo *repo = repo_create(sigpool, "rpmdbkeys");
788 repo_add_rpmdb_pubkeys(repo, 0, 0);
795 static inline const char *
796 repomd_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
798 Pool *pool = repo->pool;
800 const char *filename;
805 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
806 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
807 if (dataiterator_step(&di))
809 dataiterator_setpos_parent(&di);
810 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
811 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, chksumtypep);
813 dataiterator_free(&di);
814 if (filename && !*chksumtypep)
816 printf("no %s file checksum!\n", what);
823 repomd_add_ext(Repo *repo, Repodata *data, const char *what)
825 Pool *pool = repo->pool;
827 Id chksumtype, handle;
828 const unsigned char *chksum;
829 const char *filename;
831 dataiterator_init(&di, pool, repo, SOLVID_META, REPOSITORY_REPOMD_TYPE, what, SEARCH_STRING);
832 dataiterator_prepend_keyname(&di, REPOSITORY_REPOMD);
833 if (!dataiterator_step(&di))
835 dataiterator_free(&di);
838 if (!strcmp(what, "prestodelta"))
840 dataiterator_setpos_parent(&di);
841 filename = pool_lookup_str(pool, SOLVID_POS, REPOSITORY_REPOMD_LOCATION);
842 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, REPOSITORY_REPOMD_CHECKSUM, &chksumtype);
843 if (!filename || !chksum)
845 dataiterator_free(&di);
848 handle = repodata_new_handle(data);
849 repodata_set_poolstr(data, handle, REPOSITORY_REPOMD_TYPE, what);
850 repodata_set_str(data, handle, REPOSITORY_REPOMD_LOCATION, filename);
852 repodata_set_bin_checksum(data, handle, REPOSITORY_REPOMD_CHECKSUM, chksumtype, chksum);
853 if (!strcmp(what, "deltainfo"))
855 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOSITORY_DELTAINFO);
856 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_FLEXARRAY);
858 if (!strcmp(what, "filelists"))
860 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
861 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
863 dataiterator_free(&di);
864 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
869 /* susetags helpers */
871 static inline const char *
872 susetags_find(Repo *repo, const char *what, const unsigned char **chksump, Id *chksumtypep)
874 Pool *pool = repo->pool;
876 const char *filename;
881 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, what, SEARCH_STRING);
882 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
883 if (dataiterator_step(&di))
885 dataiterator_setpos_parent(&di);
886 *chksump = pool_lookup_bin_checksum(pool, SOLVID_POS, SUSETAGS_FILE_CHECKSUM, chksumtypep);
889 dataiterator_free(&di);
890 if (filename && !*chksumtypep)
892 printf("no %s file checksum!\n", what);
898 static Id susetags_langtags[] = {
899 SOLVABLE_SUMMARY, REPOKEY_TYPE_STR,
900 SOLVABLE_DESCRIPTION, REPOKEY_TYPE_STR,
901 SOLVABLE_EULA, REPOKEY_TYPE_STR,
902 SOLVABLE_MESSAGEINS, REPOKEY_TYPE_STR,
903 SOLVABLE_MESSAGEDEL, REPOKEY_TYPE_STR,
904 SOLVABLE_CATEGORY, REPOKEY_TYPE_ID,
909 susetags_add_ext(Repo *repo, Repodata *data)
911 Pool *pool = repo->pool;
914 Id handle, filechksumtype;
915 const unsigned char *filechksum;
918 dataiterator_init(&di, pool, repo, SOLVID_META, SUSETAGS_FILE_NAME, 0, 0);
919 dataiterator_prepend_keyname(&di, SUSETAGS_FILE);
920 while (dataiterator_step(&di))
922 if (strncmp(di.kv.str, "packages.", 9) != 0)
924 if (!di.kv.str[9] || !di.kv.str[10] || (di.kv.str[11] && di.kv.str[11] != '.'))
926 ext[0] = di.kv.str[9];
927 ext[1] = di.kv.str[10];
929 if (!susetags_find(repo, di.kv.str, &filechksum, &filechksumtype))
931 handle = repodata_new_handle(data);
932 repodata_set_str(data, handle, SUSETAGS_FILE_NAME, di.kv.str);
934 repodata_set_bin_checksum(data, handle, SUSETAGS_FILE_CHECKSUM, filechksumtype, filechksum);
935 if (!strcmp(ext, "DU"))
937 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_DISKUSAGE);
938 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRNUMNUMARRAY);
940 if (!strcmp(ext, "FL"))
942 repodata_add_idarray(data, handle, REPOSITORY_KEYS, SOLVABLE_FILELIST);
943 repodata_add_idarray(data, handle, REPOSITORY_KEYS, REPOKEY_TYPE_DIRSTRARRAY);
947 for (i = 0; susetags_langtags[i]; i += 2)
949 repodata_add_idarray(data, handle, REPOSITORY_KEYS, pool_id2langid(pool, susetags_langtags[i], ext, 1));
950 repodata_add_idarray(data, handle, REPOSITORY_KEYS, susetags_langtags[i + 1]);
953 repodata_add_flexarray(data, SOLVID_META, REPOSITORY_EXTERNAL, handle);
955 dataiterator_free(&di);
960 iscompressed(const char *name)
962 int l = strlen(name);
963 return l > 3 && !strcmp(name + l - 3, ".gz") ? 1 : 0;
970 load_stub(Pool *pool, Repodata *data, void *dp)
972 const char *filename, *descrdir, *repomdtype;
973 const unsigned char *filechksum;
975 struct repoinfo *cinfo;
980 cinfo = data->repo->appdata;
982 filename = repodata_lookup_str(data, SOLVID_META, SUSETAGS_FILE_NAME);
986 ext[0] = filename[9];
987 ext[1] = filename[10];
990 printf("[%s:%s", data->repo->name, ext);
992 if (usecachedrepo(data->repo, ext, cinfo->extcookie, 0))
994 printf(" cached]\n"); fflush(stdout);
998 printf(" loading]\n"); fflush(stdout);
1000 defvendor = repo_lookup_id(data->repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1001 descrdir = repo_lookup_str(data->repo, SOLVID_META, SUSETAGS_DESCRDIR);
1003 descrdir = "suse/setup/descr";
1005 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1006 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1008 repo_add_susetags(data->repo, fp, defvendor, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1010 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
1014 repomdtype = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_TYPE);
1017 if (!strcmp(repomdtype, "filelists"))
1019 else if (!strcmp(repomdtype, "deltainfo"))
1024 printf("[%s:%s", data->repo->name, ext);
1026 if (usecachedrepo(data->repo, ext, cinfo->extcookie, 0))
1028 printf(" cached]\n");fflush(stdout);
1031 printf(" loading]\n"); fflush(stdout);
1032 filename = repodata_lookup_str(data, SOLVID_META, REPOSITORY_REPOMD_LOCATION);
1034 filechksum = repodata_lookup_bin_checksum(data, SOLVID_META, SUSETAGS_FILE_CHECKSUM, &filechksumtype);
1035 if ((fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, 0)) == 0)
1037 if (!strcmp(ext, "FL"))
1038 repo_add_rpmmd(data->repo, fp, ext, REPO_USE_LOADING|REPO_EXTEND_SOLVABLES);
1039 else if (!strcmp(ext, "DL"))
1040 repo_add_deltainfoxml(data->repo, fp, REPO_USE_LOADING);
1042 writecachedrepo(data->repo, data, ext, cinfo->extcookie);
1050 read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos)
1053 struct repoinfo *cinfo;
1057 const char *filename;
1058 const unsigned char *filechksum;
1060 const char *descrdir;
1063 unsigned char cookie[32];
1069 repo = repo_create(pool, "@System");
1070 printf("rpm database:");
1071 if (stat("/var/lib/rpm/Packages", &stb))
1072 memset(&stb, 0, sizeof(&stb));
1073 calc_checksum_stat(&stb, REPOKEY_TYPE_SHA256, cookie);
1074 if (usecachedrepo(repo, 0, cookie, 0))
1075 printf(" cached\n");
1079 printf(" reading\n");
1082 #ifdef PRODUCTS_PATH
1083 repo_add_products(repo, PRODUCTS_PATH, 0, REPO_NO_INTERNALIZE);
1085 if ((ofp = fopen(calccachepath(repo, 0), "r")) != 0)
1087 Repo *ref = repo_create(pool, "@System.old");
1088 if (!repo_add_solv(ref, ofp))
1090 repo_add_rpmdb(repo, ref, 0, REPO_REUSE_REPODATA);
1097 repo_add_rpmdb(repo, 0, 0, REPO_REUSE_REPODATA);
1098 writecachedrepo(repo, 0, 0, cookie);
1100 pool_set_installed(pool, repo);
1102 for (i = 0; i < nrepoinfos; i++)
1104 cinfo = repoinfos + i;
1105 if (!cinfo->enabled)
1108 repo = repo_create(pool, cinfo->alias);
1110 repo->appdata = cinfo;
1111 repo->priority = 99 - cinfo->priority;
1113 dorefresh = cinfo->autorefresh;
1114 if (dorefresh && cinfo->metadata_expire && stat(calccachepath(repo, 0), &stb) == 0)
1116 if (time(0) - stb.st_mtime < cinfo->metadata_expire)
1119 if (!dorefresh && usecachedrepo(repo, 0, 0, 0))
1121 printf("repo '%s':", cinfo->alias);
1122 printf(" cached\n");
1126 switch (cinfo->type)
1129 printf("rpmmd repo '%s':", cinfo->alias);
1131 if ((fp = curlfopen(cinfo, "repodata/repomd.xml", 0, 0, 0, 0)) == 0)
1133 printf(" no repomd.xml file, skipped\n");
1138 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cookie);
1139 if (usecachedrepo(repo, 0, cookie, 1))
1141 printf(" cached\n");
1145 sigfp = curlfopen(cinfo, "repodata/repomd.xml.asc", 0, 0, 0, 0);
1149 printf(" unsigned, skipped\n");
1157 sigpool = read_sigs();
1158 if (!checksig(sigpool, fp, sigfp))
1160 printf(" checksig failed, skipped\n");
1167 repo_add_repomdxml(repo, fp, 0);
1169 printf(" reading\n");
1170 filename = repomd_find(repo, "primary", &filechksum, &filechksumtype);
1171 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1173 repo_add_rpmmd(repo, fp, 0, 0);
1177 break; /* hopeless */
1179 filename = repomd_find(repo, "updateinfo", &filechksum, &filechksumtype);
1180 if (filename && (fp = curlfopen(cinfo, filename, iscompressed(filename), filechksum, filechksumtype, &badchecksum)) != 0)
1182 repo_add_updateinfoxml(repo, fp, 0);
1186 data = repo_last_repodata(repo);
1187 if (!repomd_add_ext(repo, data, "deltainfo"))
1188 repomd_add_ext(repo, data, "prestodelta");
1189 repomd_add_ext(repo, data, "filelists");
1190 repodata_internalize(data);
1192 writecachedrepo(repo, data, 0, cookie);
1193 repodata_create_stubs(data);
1197 printf("susetags repo '%s':", cinfo->alias);
1201 if ((fp = curlfopen(cinfo, "content", 0, 0, 0, 0)) == 0)
1203 printf(" no content file, skipped\n");
1208 calc_checksum_fp(fp, REPOKEY_TYPE_SHA256, cookie);
1209 if (usecachedrepo(repo, 0, cookie, 1))
1211 printf(" cached\n");
1215 sigfp = curlfopen(cinfo, "content.asc", 0, 0, 0, 0);
1218 printf(" unsigned, skipped\n");
1225 sigpool = read_sigs();
1226 if (!checksig(sigpool, fp, sigfp))
1228 printf(" checksig failed, skipped\n");
1235 repo_add_content(repo, fp, 0);
1237 defvendor = repo_lookup_id(repo, SOLVID_META, SUSETAGS_DEFAULTVENDOR);
1238 descrdir = repo_lookup_str(repo, SOLVID_META, SUSETAGS_DESCRDIR);
1240 descrdir = "suse/setup/descr";
1241 filename = susetags_find(repo, "packages.gz", &filechksum, &filechksumtype);
1243 filename = susetags_find(repo, "packages", &filechksum, &filechksumtype);
1246 printf(" no packages file entry, skipped\n");
1249 printf(" reading\n");
1250 if ((fp = curlfopen(cinfo, pool_tmpjoin(pool, descrdir, "/", filename), iscompressed(filename), filechksum, filechksumtype, &badchecksum)) == 0)
1251 break; /* hopeless */
1252 repo_add_susetags(repo, fp, defvendor, 0, 0);
1254 data = repo_last_repodata(repo);
1255 susetags_add_ext(repo, data);
1256 repodata_internalize(data);
1258 writecachedrepo(repo, data, 0, cookie);
1259 repodata_create_stubs(data);
1262 printf("unsupported repo '%s': skipped\n", cinfo->alias);
1274 str2archid(Pool *pool, char *arch)
1279 id = str2id(pool, arch, 0);
1280 if (id == ARCH_SRC || id == ARCH_NOSRC || id == ARCH_NOARCH)
1282 if (pool->id2arch && (id > pool->lastarch || !pool->id2arch[id]))
1288 depglob(Pool *pool, char *name, Queue *job)
1291 Id id = str2id(pool, name, 0);
1296 FOR_PROVIDES(p, pp, id)
1298 Solvable *s = pool->solvables + p;
1302 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
1308 printf("[using capability match for '%s']\n", name);
1309 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
1314 if (strpbrk(name, "[*?") == 0)
1317 /* looks like a name glob. hard work. */
1318 for (p = 1; p < pool->nsolvables; p++)
1320 Solvable *s = pool->solvables + p;
1321 if (!s->repo || !pool_installable(pool, s))
1324 if (fnmatch(name, id2str(pool, id), 0) == 0)
1326 for (i = 0; i < job->count; i += 2)
1327 if (job->elements[i] == SOLVER_SOLVABLE_NAME && job->elements[i + 1] == id)
1329 if (i == job->count)
1330 queue_push2(job, SOLVER_SOLVABLE_NAME, id);
1336 /* looks like a dep glob. really hard work. */
1337 for (id = 1; id < pool->ss.nstrings; id++)
1339 if (!pool->whatprovides[id])
1341 if (fnmatch(name, id2str(pool, id), 0) == 0)
1344 printf("[using capability match for '%s']\n", name);
1345 for (i = 0; i < job->count; i += 2)
1346 if (job->elements[i] == SOLVER_SOLVABLE_PROVIDES && job->elements[i + 1] == id)
1348 if (i == job->count)
1349 queue_push2(job, SOLVER_SOLVABLE_PROVIDES, id);
1359 addrelation(Pool *pool, Queue *job, int flags, Id evr)
1362 for (i = 0; i < job->count; i += 2)
1364 if (job->elements[i] != SOLVER_SOLVABLE_NAME && job->elements[i] != SOLVER_SOLVABLE_PROVIDES)
1366 job->elements[i + 1] = rel2id(pool, job->elements[i + 1], evr, flags, 1);
1371 limitevr(Pool *pool, char *evr, Queue *job, Id archid)
1380 for (i = 0; i < job->count; i += 2)
1383 FOR_JOB_SELECT(p, pp, job->elements[i], job->elements[i + 1])
1385 s = pool_id2solvable(pool, p);
1386 if (archid && s->arch != archid)
1388 if (evrcmp_str(pool, id2str(pool, s->evr), evr, EVRCMP_MATCH) == 0)
1395 queue_deleten(job, 0, i);
1399 /* if all solvables have the same evr */
1400 s = pool_id2solvable(pool, mq.elements[0]);
1402 for (j = 0; j < mq.count; j++)
1404 s = pool_id2solvable(pool, mq.elements[j]);
1405 if (s->evr != evrid)
1408 if (j == mq.count && j > 1)
1410 prune_to_best_arch(pool, &mq);
1411 // prune_to_highest_prio(pool, &mq);
1416 job->elements[i] = SOLVER_SOLVABLE_ONE_OF;
1417 job->elements[i + 1] = pool_queuetowhatprovides(pool, &mq);
1421 job->elements[i] = SOLVER_SOLVABLE;
1422 job->elements[i + 1] = mq.elements[0];
1427 queue_deleten(job, i, 2);
1437 if ((r = strrchr(evr, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
1440 if (limitevr(pool, evr, job, archid))
1452 mkselect(Pool *pool, int mode, char *name, Queue *job)
1464 dataiterator_init(&di, pool, mode == SOLVER_ERASE ? pool->installed : 0, 0, SOLVABLE_FILELIST, name, SEARCH_STRING|SEARCH_FILES|SEARCH_COMPLETE_FILELIST);
1465 while (dataiterator_step(&di))
1467 Solvable *s = pool->solvables + di.solvid;
1468 if (!s->repo || !pool_installable(pool, s))
1470 queue_push(&q, di.solvid);
1471 dataiterator_skip_solvable(&di);
1473 dataiterator_free(&di);
1476 printf("[using file list match for '%s']\n", name);
1479 queue_push2(job, SOLVER_SOLVABLE_ONE_OF, pool_queuetowhatprovides(pool, &q));
1481 queue_push2(job, SOLVER_SOLVABLE, q.elements[0]);
1487 if ((r = strpbrk(name, "<=>")) != 0)
1489 /* relation case, support:
1494 int nend = r - name;
1506 while (*r && *r == ' ' && *r == '\t')
1508 while (nend && (name[nend - 1] == ' ' || name[nend -1 ] == '\t'))
1513 fprintf(stderr, "bad relation\n");
1516 if (depglob(pool, name, job))
1518 addrelation(pool, job, rflags, str2id(pool, r, 1));
1521 if ((r2 = strrchr(name, '.')) != 0 && r2[1] && (archid = str2archid(pool, r2 + 1)) != 0)
1524 if (depglob(pool, name, job))
1527 addrelation(pool, job, REL_ARCH, archid);
1528 addrelation(pool, job, rflags, str2id(pool, r, 1));
1536 /* no relation case, support:
1539 * depglob-version-release
1540 * depglob-version-release.arch
1542 if (depglob(pool, name, job))
1545 if ((r = strrchr(name, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0)
1548 if (depglob(pool, name, job))
1551 addrelation(pool, job, REL_ARCH, archid);
1556 if ((r = strrchr(name, '-')) != 0)
1559 if (depglob(pool, name, job))
1561 /* have just the version */
1563 if (limitevr(pool, r + 1, job, 0))
1566 if ((r2 = strrchr(name, '-')) != 0)
1570 if (depglob(pool, name, job))
1573 if (limitevr(pool, r2 + 1, job, 0))
1581 fprintf(stderr, "nothing matches '%s'\n", name);
1587 yesno(const char *str)
1589 char inbuf[128], *ip;
1596 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
1601 while (*ip == ' ' || *ip == '\t')
1608 if (*ip == 'y' || *ip == 'n')
1609 return *ip == 'y' ? 1 : 0;
1621 fc_cb(Pool *pool, Id p, void *cbdata)
1623 struct fcstate *fcstate = cbdata;
1631 rpm_byrpmdbid(0, 0, &fcstate->rpmdbstate);
1634 s = pool_id2solvable(pool, p);
1635 if (pool->installed && s->repo == pool->installed)
1637 if (!s->repo->rpmdbid)
1639 rpmdbid = s->repo->rpmdbid[p - s->repo->start];
1642 return rpm_byrpmdbid(rpmdbid, 0, &fcstate->rpmdbstate);
1644 for (i = 0; i < fcstate->newpkgscnt; i++)
1645 if (fcstate->checkq->elements[i] == p)
1647 if (i == fcstate->newpkgscnt)
1649 fp = fcstate->newpkgsfps[i];
1653 return rpm_byfp(fp, solvable2str(pool, s), &fcstate->rpmdbstate);
1657 runrpm(const char *arg, const char *name, int dupfd3)
1662 if ((pid = fork()) == (pid_t)-1)
1669 if (dupfd3 != -1 && dupfd3 != 3)
1675 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
1676 if (strcmp(arg, "-e") == 0)
1677 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
1679 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
1683 while (waitpid(pid, &status, 0) != pid)
1687 printf("rpm failed\n");
1693 nscallback(Pool *pool, void *data, Id name, Id evr)
1695 if (name == NAMESPACE_PRODUCTBUDDY)
1697 /* SUSE specific hack: each product has an associated rpm */
1698 Solvable *s = pool->solvables + evr;
1701 cap = str2id(pool, pool_tmpjoin(pool, "product(", id2str(pool, s->name) + 8, ")"), 0);
1704 cap = rel2id(pool, cap, s->evr, REL_EQ, 0);
1707 FOR_PROVIDES(p, pp, cap)
1709 Solvable *ps = pool->solvables + p;
1710 if (ps->repo == s->repo && ps->arch == s->arch)
1720 main(int argc, char **argv)
1723 Repo *commandlinerepo = 0;
1724 Id *commandlinepkgs = 0;
1726 struct repoinfo *repoinfos;
1728 int i, mode, newpkgs;
1732 char inbuf[128], *ip;
1734 int distupgrade = 0;
1737 struct fcstate fcstate;
1743 fprintf(stderr, "Usage: solv install|erase|update|show <select>\n");
1746 if (!strcmp(argv[0], "install") || !strcmp(argv[0], "in"))
1747 mode = SOLVER_INSTALL;
1748 else if (!strcmp(argv[0], "patch"))
1750 mode = SOLVER_UPDATE;
1753 else if (!strcmp(argv[0], "erase") || !strcmp(argv[0], "rm"))
1754 mode = SOLVER_ERASE;
1755 else if (!strcmp(argv[0], "show"))
1757 else if (!strcmp(argv[0], "update") || !strcmp(argv[0], "up"))
1758 mode = SOLVER_UPDATE;
1759 else if (!strcmp(argv[0], "dist-upgrade") || !strcmp(argv[0], "dup"))
1761 mode = SOLVER_UPDATE;
1766 fprintf(stderr, "Usage: solv install|erase|update|show <select>\n");
1770 pool = pool_create();
1771 pool_setloadcallback(pool, load_stub, 0);
1772 pool->nscallback = nscallback;
1773 // pool_setdebuglevel(pool, 2);
1775 repoinfos = read_repoinfos(pool, REPOINFO_PATH, &nrepoinfos);
1776 read_repos(pool, repoinfos, nrepoinfos);
1778 if (mode == 0 || mode == SOLVER_INSTALL)
1780 for (i = 1; i < argc; i++)
1783 l = strlen(argv[i]);
1784 if (l <= 4 || strcmp(argv[i] + l - 4, ".rpm"))
1786 if (access(argv[i], R_OK))
1791 if (!commandlinepkgs)
1792 commandlinepkgs = sat_calloc(argc, sizeof(Id));
1793 if (!commandlinerepo)
1794 commandlinerepo = repo_create(pool, "@commandline");
1795 repo_add_rpms(commandlinerepo, (const char **)argv + i, 1, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE);
1796 commandlinepkgs[i] = commandlinerepo->end - 1;
1798 if (commandlinerepo)
1799 repo_internalize(commandlinerepo);
1802 // FOR_REPOS(i, repo)
1803 // printf("%s: %d solvables\n", repo->name, repo->nsolvables);
1804 pool_addfileprovides(pool);
1805 pool_createwhatprovides(pool);
1808 for (i = 1; i < argc; i++)
1810 if (commandlinepkgs && commandlinepkgs[i])
1812 queue_push2(&job, SOLVER_SOLVABLE, commandlinepkgs[i]);
1815 mkselect(pool, mode, argv[i], &job);
1817 if (!job.count && mode == SOLVER_UPDATE)
1819 else if (!job.count)
1821 printf("no package matched\n");
1827 /* show mode, no solver needed */
1828 for (i = 0; i < job.count; i += 2)
1830 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
1832 Solvable *s = pool_id2solvable(pool, p);
1833 const char *sum = solvable_lookup_str_lang(s, SOLVABLE_SUMMARY, "de");
1834 printf(" - %s [%s]\n", solvable2str(pool, s), s->repo->name);
1836 printf(" %s\n", sum);
1841 free_repoinfos(repoinfos, nrepoinfos);
1842 sat_free(commandlinepkgs);
1846 if (updateall && patchmode)
1852 map_init(&installedmap, pool->nsolvables);
1853 if (pool->installed)
1854 FOR_REPO_SOLVABLES(pool->installed, p, s)
1855 MAPSET(&installedmap, p);
1857 /* install all patches */
1859 mode = SOLVER_INSTALL;
1860 for (p = 1; p < pool->nsolvables; p++)
1866 s = pool->solvables + p;
1867 if (strncmp(id2str(pool, s->name), "patch:", 6) != 0)
1869 FOR_PROVIDES(p2, pp, s->name)
1871 Solvable *s2 = pool->solvables + p2;
1872 if (s2->name != s->name)
1874 r = evrcmp(pool, s->evr, s2->evr, EVRCMP_COMPARE);
1875 if (r < 0 || (r == 0 && p > p2))
1880 type = solvable_lookup_str(s, SOLVABLE_PATCHCATEGORY);
1881 if (type && !strcmp(type, "optional"))
1883 r = solvable_trivial_installable_map(s, &installedmap, 0);
1886 if (solvable_lookup_bool(s, UPDATE_RESTART) && r == 0)
1893 queue_push2(&job, SOLVER_SOLVABLE, p);
1895 map_free(&installedmap);
1899 for (i = 0; i < job.count; i += 2)
1901 if (mode == SOLVER_UPDATE)
1903 FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
1904 if (pool->installed && pool->solvables[p].repo == pool->installed)
1908 job.elements[i] |= SOLVER_INSTALL;
1912 job.elements[i] |= mode;
1915 // multiversion test
1916 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae", 1));
1917 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-base", 1));
1918 // queue_push2(&job, SOLVER_NOOBSOLETES|SOLVER_SOLVABLE_NAME, str2id(pool, "kernel-pae-extra", 1));
1923 Id problem, solution;
1926 solv = solver_create(pool);
1927 solv->ignorealreadyrecommended = 1;
1928 solv->updatesystem = updateall;
1929 solv->dosplitprovides = updateall;
1930 if (updateall && distupgrade)
1932 solv->distupgrade = 1;
1933 solv->allowdowngrade = 1;
1934 solv->allowarchchange = 1;
1935 solv->allowvendorchange = 1;
1937 // queue_push2(&job, SOLVER_DISTUPGRADE, 3);
1938 solver_solve(solv, &job);
1939 if (!solv->problems.count)
1941 pcnt = solver_problem_count(solv);
1942 printf("Found %d problems:\n", pcnt);
1943 for (problem = 1; problem <= pcnt; problem++)
1946 printf("Problem %d:\n", problem);
1947 solver_printprobleminfo(solv, problem);
1949 scnt = solver_solution_count(solv, problem);
1950 for (solution = 1; solution <= scnt; solution++)
1952 printf("Solution %d:\n", solution);
1953 solver_printsolution(solv, problem, solution);
1958 printf("Please choose a solution: ");
1961 if (!(ip = fgets(inbuf, sizeof(inbuf), stdin)))
1966 while (*ip == ' ' || *ip == '\t')
1968 if (*ip >= '0' && *ip <= '9')
1971 if (take >= 1 && take <= scnt)
1987 solver_take_solution(solv, problem, take, &job);
1993 trans = &solv->trans;
1994 if (!trans->steps.count)
1996 printf("Nothing to do.\n");
2000 printf("Transaction summary:\n\n");
2001 solver_printtransaction(solv);
2010 duc[1].path = "/usr/share/man";
2011 duc[2].path = "/sbin";
2012 duc[3].path = "/etc";
2013 transaction_calc_duchanges(trans, duc, 4);
2014 for (i = 0; i < 4; i++)
2015 printf("duchanges %s: %d K %d\n", duc[i].path, duc[i].kbytes, duc[i].files);
2016 printf("install size change: %d K\n", transaction_calc_installsizechange(trans));
2020 if (!yesno("OK to continue (y/n)? "))
2026 queue_init(&checkq);
2027 newpkgs = transaction_installedresult(trans, &checkq);
2032 printf("Downloading %d packages\n", newpkgs);
2033 newpkgsfps = sat_calloc(newpkgs, sizeof(*newpkgsfps));
2034 for (i = 0; i < newpkgs; i++)
2036 unsigned int medianr;
2039 struct repoinfo *cinfo;
2040 const unsigned char *chksum;
2044 p = checkq.elements[i];
2045 s = pool_id2solvable(pool, p);
2046 if (s->repo == commandlinerepo)
2048 loc = solvable_get_location(s, &medianr);
2049 if (!(newpkgsfps[i] = fopen(loc, "r")))
2057 cinfo = s->repo->appdata;
2060 printf("%s: no repository information\n", s->repo->name);
2063 loc = solvable_get_location(s, &medianr);
2067 if (pool->installed && pool->installed->nsolvables)
2069 /* try a delta first */
2070 dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, id2str(pool, s->name), SEARCH_STRING);
2071 dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO);
2072 while (dataiterator_step(&di))
2076 dataiterator_setpos_parent(&di);
2077 if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr ||
2078 pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch)
2080 baseevr = pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR);
2081 FOR_PROVIDES(op, pp, s->name)
2083 Solvable *os = pool->solvables + op;
2084 if (os->repo == pool->installed && os->name == s->name && os->arch == s->arch && os->evr == baseevr)
2087 if (op && access("/usr/bin/applydeltarpm", X_OK) == 0)
2089 /* base is installed, run sequence check */
2090 const char *seqname;
2099 seqname = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NAME);
2100 seqevr = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_EVR);
2101 seqnum = pool_lookup_str(pool, SOLVID_POS, DELTA_SEQ_NUM);
2102 seq = pool_tmpjoin(pool, seqname, "-", seqevr);
2103 seq = pool_tmpjoin(pool, seq, "-", seqnum);
2104 if (system(pool_tmpjoin(pool, "/usr/bin/applydeltarpm -c -s ", seq, 0)) != 0)
2105 continue; /* didn't match */
2106 /* looks good, download delta */
2108 chksum = pool_lookup_bin_checksum(pool, SOLVID_POS, DELTA_CHECKSUM, &chksumtype);
2110 continue; /* no way! */
2111 dloc = pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_DIR);
2112 dloc = pool_tmpjoin(pool, dloc, "/", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_NAME));
2113 dloc = pool_tmpjoin(pool, dloc, "-", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_EVR));
2114 dloc = pool_tmpjoin(pool, dloc, ".", pool_lookup_str(pool, SOLVID_POS, DELTA_LOCATION_SUFFIX));
2115 if ((fp = curlfopen(cinfo, dloc, 0, chksum, chksumtype, 0)) == 0)
2117 /* got it, now reconstruct */
2118 newfd = opentmpfile();
2119 sprintf(cmd, "applydeltarpm /dev/fd/%d /dev/fd/%d", fileno(fp), newfd);
2120 fcntl(fileno(fp), F_SETFD, 0);
2127 lseek(newfd, 0, SEEK_SET);
2129 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
2130 if (chksumtype && !verify_checksum(newfd, loc, chksum, chksumtype))
2136 newpkgsfps[i] = fdopen(newfd, "r");
2141 dataiterator_free(&di);
2148 continue; /* delta worked! */
2150 if (cinfo->type == TYPE_SUSETAGS)
2152 const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
2153 loc = pool_tmpjoin(pool, datadir ? datadir : "suse", "/", loc);
2156 chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype);
2157 if ((newpkgsfps[i] = curlfopen(cinfo, loc, 0, chksum, chksumtype, 0)) == 0)
2159 printf("\n%s: %s not found in repository\n", s->repo->name, loc);
2172 printf("Searching for file conflicts\n");
2173 queue_init(&conflicts);
2174 fcstate.rpmdbstate = 0;
2175 fcstate.newpkgscnt = newpkgs;
2176 fcstate.checkq = &checkq;
2177 fcstate.newpkgsfps = newpkgsfps;
2178 pool_findfileconflicts(pool, &checkq, newpkgs, &conflicts, &fc_cb, &fcstate);
2179 if (conflicts.count)
2182 for (i = 0; i < conflicts.count; i += 5)
2183 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]));
2185 if (yesno("Re-run solver (y/n/q)? "))
2187 for (i = 0; i < newpkgs; i++)
2189 fclose(newpkgsfps[i]);
2190 newpkgsfps = sat_free(newpkgsfps);
2192 pool_add_fileconflicts_deps(pool, &conflicts);
2193 pool_createwhatprovides(pool); /* Hmm... */
2197 queue_free(&conflicts);
2200 printf("Committing transaction:\n\n");
2201 transaction_order(trans, 0);
2202 for (i = 0; i < trans->steps.count; i++)
2204 const char *evr, *evrp, *nvra;
2209 p = trans->steps.elements[i];
2210 s = pool_id2solvable(pool, p);
2211 Id type = transaction_type(trans, p, SOLVER_TRANSACTION_RPM_ONLY);
2214 case SOLVER_TRANSACTION_ERASE:
2215 printf("erase %s\n", solvid2str(pool, p));
2216 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
2218 /* strip epoch from evr */
2219 evr = evrp = id2str(pool, s->evr);
2220 while (*evrp >= '0' && *evrp <= '9')
2222 if (evrp > evr && evrp[0] == ':' && evrp[1])
2224 nvra = pool_tmpjoin(pool, id2str(pool, s->name), "-", evr);
2225 nvra = pool_tmpjoin(pool, nvra, ".", id2str(pool, s->arch));
2226 runrpm("-e", nvra, -1); /* to bad that --querybynumber doesn't work */
2228 case SOLVER_TRANSACTION_INSTALL:
2229 case SOLVER_TRANSACTION_MULTIINSTALL:
2230 printf("install %s\n", solvid2str(pool, p));
2231 for (j = 0; j < newpkgs; j++)
2232 if (checkq.elements[j] == p)
2234 fp = j < newpkgs ? newpkgsfps[j] : 0;
2238 lseek(fileno(fp), 0, SEEK_SET);
2239 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp));
2248 for (i = 0; i < newpkgs; i++)
2250 fclose(newpkgsfps[i]);
2251 sat_free(newpkgsfps);
2252 queue_free(&checkq);
2256 free_repoinfos(repoinfos, nrepoinfos);
2257 sat_free(commandlinepkgs);