1 #if defined(ENABLE_RPMDB) && (defined(SUSE) || defined(FEDORA) || defined(MANDRIVA) || defined(MAGEIA))
13 #include "repo_rpmdb.h"
14 #if defined(ENABLE_SUSEREPO) && defined(SUSE)
15 #include "repo_products.h"
17 #if defined(ENABLE_APPDATA)
18 #include "repo_appdata.h"
21 #include "repo_autopattern.h"
23 #include "transaction.h"
26 #include "repoinfo_cache.h"
27 #include "repoinfo_system_rpm.h"
30 # define PRODUCTS_PATH "/etc/products.d"
33 # define APPDATA_PATH "/usr/share/metainfo"
34 # define APPDATA_LEGACY_PATH "/usr/share/appdata"
38 runrpm(const char *arg, const char *name, int dupfd3, const char *rootdir)
43 if ((pid = fork()) == (pid_t)-1)
52 if (dupfd3 != -1 && dupfd3 != 3)
58 fcntl(3, F_SETFD, 0); /* clear CLOEXEC */
59 if (strcmp(arg, "-e") == 0)
60 execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
62 execlp("rpm", "rpm", arg, "--force", "--nodeps", "--nodigest", "--nosignature", "--root", rootdir, name, (char *)0);
66 while (waitpid(pid, &status, 0) != pid)
70 printf("rpm failed\n");
76 read_installed_rpm(struct repoinfo *cinfo)
78 Repo *repo = cinfo->repo;
79 Pool *pool = repo->pool;
83 memset(&stb, 0, sizeof(stb));
84 printf("rpm database:");
85 if (stat(pool_prepend_rootdir_tmp(pool, "/var/lib/rpm/Packages"), &stb))
86 memset(&stb, 0, sizeof(stb));
87 calc_cookie_stat(&stb, REPOKEY_TYPE_SHA256, 0, cinfo->cookie);
89 if (usecachedrepo(cinfo, 0, 0))
95 #if defined(ENABLE_SUSEREPO) && defined(PRODUCTS_PATH)
96 if (repo_add_products(repo, PRODUCTS_PATH, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
98 fprintf(stderr, "product reading failed: %s\n", pool_errstr(pool));
102 #if defined(ENABLE_APPDATA) && defined(APPDATA_PATH)
103 if (repo_add_appdata_dir(repo, APPDATA_PATH, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
105 fprintf(stderr, "appdata reading failed: %s\n", pool_errstr(pool));
108 #elif defined(ENABLE_APPDATA) && defined(APPDATA_LEGACY_PATH)
109 if (repo_add_appdata_dir(repo, APPDATA_LEGACY_PATH, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
111 fprintf(stderr, "appdata reading from legacy dir failed: %s\n", pool_errstr(pool));
115 ofp = fopen(calc_cachepath(repo, 0, 0), "r");
116 if (repo_add_rpmdb_reffp(repo, ofp, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | REPO_USE_ROOTDIR))
118 fprintf(stderr, "installed db: %s\n", pool_errstr(pool));
123 repo_internalize(repo);
125 repo_add_autopattern(repo, 0);
127 writecachedrepo(cinfo, 0, 0);
132 commit_transactionelement_rpm(Pool *pool, Id type, Id p, FILE *fp)
134 Solvable *s = pool_id2solvable(pool, p);
135 const char *rootdir = pool_get_rootdir(pool);
136 const char *evr, *evrp, *nvra;
140 case SOLVER_TRANSACTION_ERASE:
141 if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
143 /* strip epoch from evr */
144 evr = evrp = pool_id2str(pool, s->evr);
145 while (*evrp >= '0' && *evrp <= '9')
147 if (evrp > evr && evrp[0] == ':' && evrp[1])
149 nvra = pool_tmpjoin(pool, pool_id2str(pool, s->name), "-", evr);
150 nvra = pool_tmpappend(pool, nvra, ".", pool_id2str(pool, s->arch));
151 runrpm("-e", nvra, -1, rootdir); /* too bad that --querybynumber doesn't work */
153 case SOLVER_TRANSACTION_INSTALL:
154 case SOLVER_TRANSACTION_MULTIINSTALL:
156 lseek(fileno(fp), 0, SEEK_SET);
157 runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp), rootdir);