diff options
author | Michael Schroeder <mls@suse.de> | 2012-10-23 12:37:25 +0200 |
---|---|---|
committer | Michael Schroeder <mls@suse.de> | 2012-10-23 12:37:25 +0200 |
commit | 765ead528d2b791e43e2a90212b5e4a0c2ad1302 (patch) | |
tree | df895b663861fa3894c5a3d713626b9709dd9ed5 /ext | |
parent | dbd528c82312931703cef9c3f932ee5c8bd4c635 (diff) | |
download | libsolv-765ead528d2b791e43e2a90212b5e4a0c2ad1302.tar.gz libsolv-765ead528d2b791e43e2a90212b5e4a0c2ad1302.tar.bz2 libsolv-765ead528d2b791e43e2a90212b5e4a0c2ad1302.zip |
implement pool_set_rootdir/REPO_USE_ROOTDIR instead of passing a rootdir to various functions.
Breaks the interface a bit, sorry. The new way seems to be much cleaner, though.
Extra apologies to Nate Skulic for removing his add_rpmdb_root method one day
after adding it.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/repo_arch.c | 6 | ||||
-rw-r--r-- | ext/repo_deb.c | 8 | ||||
-rw-r--r-- | ext/repo_deb.h | 2 | ||||
-rw-r--r-- | ext/repo_products.c | 41 | ||||
-rw-r--r-- | ext/repo_products.h | 2 | ||||
-rw-r--r-- | ext/repo_releasefile_products.c | 12 | ||||
-rw-r--r-- | ext/repo_rpmdb.c | 21 | ||||
-rw-r--r-- | ext/repo_rpmdb.h | 4 | ||||
-rw-r--r-- | ext/repo_zyppdb.c | 4 |
9 files changed, 65 insertions, 35 deletions
diff --git a/ext/repo_arch.c b/ext/repo_arch.c index 5151803..6caa487 100644 --- a/ext/repo_arch.c +++ b/ext/repo_arch.c @@ -342,7 +342,7 @@ repo_add_arch_pkg(Repo *repo, const char *fn, int flags) void *pkgidhandle = 0; data = repo_add_repodata(repo, flags); - if ((fd = open(fn, O_RDONLY, 0)) < 0) + if ((fd = open(flags & REPO_USE_ROOTDIR ? pool_prepend_rootdir_tmp(pool, fn) : fn, O_RDONLY, 0)) < 0) { pool_error(pool, -1, "%s: %s", fn, strerror(errno)); return 0; @@ -816,6 +816,8 @@ repo_add_arch_local(Repo *repo, const char *dir, int flags) data = repo_add_repodata(repo, flags); + if (flags & REPO_USE_ROOTDIR) + dir = pool_prepend_rootdir(pool, dir); dp = opendir(dir); if (dp) { @@ -849,6 +851,8 @@ repo_add_arch_local(Repo *repo, const char *dir, int flags) } if (!(flags & REPO_NO_INTERNALIZE)) repodata_internalize(data); + if (flags & REPO_USE_ROOTDIR) + solv_free(dir); return 0; } diff --git a/ext/repo_deb.c b/ext/repo_deb.c index 635a987..2e1977b 100644 --- a/ext/repo_deb.c +++ b/ext/repo_deb.c @@ -414,12 +414,12 @@ repo_add_debpackages(Repo *repo, FILE *fp, int flags) } int -repo_add_debdb(Repo *repo, const char *rootdir, int flags) +repo_add_debdb(Repo *repo, int flags) { FILE *fp; const char *path = "/var/lib/dpkg/status"; - if (rootdir) - path = pool_tmpjoin(repo->pool, rootdir, path, 0); + if (flags & REPO_USE_ROOTDIR) + path = pool_prepend_rootdir_tmp(repo->pool, path); if ((fp = fopen(path, "r")) == 0) return pool_error(repo->pool, -1, "%s: %s", path, strerror(errno)); repo_add_debpackages(repo, fp, flags); @@ -443,7 +443,7 @@ repo_add_deb(Repo *repo, const char *deb, int flags) struct stat stb; data = repo_add_repodata(repo, flags); - if ((fp = fopen(deb, "r")) == 0) + if ((fp = fopen(flags & REPO_USE_ROOTDIR ? pool_prepend_rootdir_tmp(pool, deb) : deb, "r")) == 0) { pool_error(pool, -1, "%s: %s", deb, strerror(errno)); return 0; diff --git a/ext/repo_deb.h b/ext/repo_deb.h index 3ca3fdf..7057da6 100644 --- a/ext/repo_deb.h +++ b/ext/repo_deb.h @@ -6,7 +6,7 @@ */ extern int repo_add_debpackages(Repo *repo, FILE *fp, int flags); -extern int repo_add_debdb(Repo *repo, const char *rootdir, int flags); +extern int repo_add_debdb(Repo *repo, int flags); extern Id repo_add_deb(Repo *repo, const char *deb, int flags); #define DEBS_ADD_WITH_PKGID (1 << 8) diff --git a/ext/repo_products.c b/ext/repo_products.c index c15051a..598b2ab 100644 --- a/ext/repo_products.c +++ b/ext/repo_products.c @@ -14,6 +14,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> +#include <errno.h> #include <limits.h> #include <fcntl.h> #include <ctype.h> @@ -435,6 +436,8 @@ repo_add_code11_products(Repo *repo, const char *dirpath, int flags) pd.sbtab[sw->to] = sw->from; } + if (flags & REPO_USE_ROOTDIR) + dirpath = pool_prepend_rootdir(repo->pool, dirpath); dir = opendir(dirpath); if (dir) { @@ -470,6 +473,8 @@ repo_add_code11_products(Repo *repo, const char *dirpath, int flags) } solv_free(pd.content); join_freemem(&pd.jd); + if (flags & REPO_USE_ROOTDIR) + solv_free((char *)dirpath); if (!(flags & REPO_NO_INTERNALIZE)) repodata_internalize(data); @@ -492,15 +497,14 @@ repo_add_code11_products(Repo *repo, const char *dirpath, int flags) /* Oh joy! Three parsers for the price of one! */ int -repo_add_products(Repo *repo, const char *proddir, const char *root, int flags) +repo_add_products(Repo *repo, const char *proddir, int flags) { - char *fullpath; + const char *fullpath; DIR *dir; - int ret; if (proddir) { - dir = opendir(proddir); + dir = opendir(flags & REPO_USE_ROOTDIR ? pool_prepend_rootdir_tmp(repo->pool, proddir) : proddir); if (dir) { /* assume code11 stype products */ @@ -510,32 +514,37 @@ repo_add_products(Repo *repo, const char *proddir, const char *root, int flags) } /* code11 didn't work, try old code10 zyppdb */ - fullpath = solv_dupjoin(root ? root : 0, "/var/lib/zypp/db/products", 0); + fullpath = "/var/lib/zypp/db/products"; + if (flags & REPO_USE_ROOTDIR) + fullpath = pool_prepend_rootdir_tmp(repo->pool, fullpath); dir = opendir(fullpath); if (dir) { closedir(dir); /* assume code10 style products */ - ret = repo_add_zyppdb_products(repo, fullpath, flags); - solv_free(fullpath); - return ret; + return repo_add_zyppdb_products(repo, "/var/lib/zypp/db/products", flags); } - solv_free(fullpath); /* code10/11 didn't work, try -release files parsing */ - fullpath = solv_dupjoin(root ? root : 0, "/etc", 0); + fullpath = "/etc"; + if (flags & REPO_USE_ROOTDIR) + fullpath = pool_prepend_rootdir_tmp(repo->pool, fullpath); dir = opendir(fullpath); if (dir) { closedir(dir); - ret = repo_add_releasefile_products(repo, fullpath, flags); - solv_free(fullpath); - return ret; + return repo_add_releasefile_products(repo, "/etc", flags); } - /* no luck. print an error message in case the root argument is wrong */ - perror(fullpath); - solv_free(fullpath); + /* no luck. check if the rootdir exists */ + fullpath = pool_get_rootdir(repo->pool); + if (fullpath && *fullpath) + { + dir = opendir(fullpath); + if (!dir) + return pool_error(repo->pool, -1, "%s: %s", fullpath, strerror(errno)); + closedir(dir); + } /* the least we can do... */ if (!(flags & REPO_NO_INTERNALIZE) && (flags & REPO_REUSE_REPODATA) != 0) diff --git a/ext/repo_products.h b/ext/repo_products.h index 748b813..f7e3b0a 100644 --- a/ext/repo_products.h +++ b/ext/repo_products.h @@ -6,4 +6,4 @@ */ extern int repo_add_code11_products(Repo *repo, const char *dirpath, int flags); -extern int repo_add_products(Repo *repo, const char *proddir, const char *root, int flags); +extern int repo_add_products(Repo *repo, const char *proddir, int flags); diff --git a/ext/repo_releasefile_products.c b/ext/repo_releasefile_products.c index e7cbc49..5c8ec33 100644 --- a/ext/repo_releasefile_products.c +++ b/ext/repo_releasefile_products.c @@ -125,9 +125,17 @@ repo_add_releasefile_products(Repo *repo, const char *dirpath, int flags) char *fullpath; struct parsedata pd; + if (!dirpath) + dirpath = "/etc"; + if (flags & REPO_USE_ROOTDIR) + dirpath = pool_prepend_rootdir(repo->pool, dirpath); dir = opendir(dirpath); if (!dir) - return 0; + { + if (flags & REPO_USE_ROOTDIR) + solv_free((char *)dirpath); + return 0; + } memset(&pd, 0, sizeof(pd)); pd.repo = repo; @@ -151,6 +159,8 @@ repo_add_releasefile_products(Repo *repo, const char *dirpath, int flags) } closedir(dir); join_freemem(&pd.jd); + if (flags & REPO_USE_ROOTDIR) + solv_free((char *)dirpath); if (!(flags & REPO_NO_INTERNALIZE) && (flags & REPO_REUSE_REPODATA) != 0) repodata_internalize(repo_last_repodata(repo)); diff --git a/ext/repo_rpmdb.c b/ext/repo_rpmdb.c index 59cd153..e0765a6 100644 --- a/ext/repo_rpmdb.c +++ b/ext/repo_rpmdb.c @@ -1345,7 +1345,7 @@ count_headers(const char *rootdir, DB_ENV *dbenv) DBT dbkey; DBT dbdata; - snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm/Name", rootdir); + snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm/Name", rootdir ? rootdir : ""); if (stat(dbpath, &statbuf)) return 0; memset(&dbkey, 0, sizeof(dbkey)); @@ -1378,7 +1378,7 @@ count_headers(const char *rootdir, DB_ENV *dbenv) */ int -repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir, int flags) +repo_add_rpmdb(Repo *repo, Repo *ref, int flags) { Pool *pool = repo->pool; unsigned char buf[16]; @@ -1406,26 +1406,26 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir, int flags) Repodata *data; int count = 0, done = 0; unsigned int now; + const char *rootdir = 0; now = solv_timems(0); memset(&dbkey, 0, sizeof(dbkey)); memset(&dbdata, 0, sizeof(dbdata)); - if (!rootdir) - rootdir = ""; - data = repo_add_repodata(repo, flags); if (ref && !(ref->nsolvables && ref->rpmdbid)) ref = 0; + if (flags & REPO_USE_ROOTDIR) + rootdir = pool_get_rootdir(pool); if (!(dbenv = opendbenv(rootdir))) { return pool_error(pool, -1, "repo_add_rpmdb: opendbenv failed"); } /* XXX: should get ro lock of Packages database! */ - snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm/Packages", rootdir); + snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm/Packages", rootdir ? rootdir : ""); if (stat(dbpath, &packagesstat)) { return pool_error(pool, -1, "repo_add_rpmdb: %s: %s", dbpath, strerror(errno)); @@ -1818,7 +1818,7 @@ repo_add_rpm(Repo *repo, const char *rpm, int flags) else if ((flags & RPM_ADD_WITH_SHA1SUM) != 0) chksumtype = REPOKEY_TYPE_SHA1; - if ((fp = fopen(rpm, "r")) == 0) + if ((fp = fopen(flags & REPO_USE_ROOTDIR ? pool_prepend_rootdir_tmp(pool, rpm) : rpm, "r")) == 0) { pool_error(pool, -1, "%s: %s", rpm, strerror(errno)); return 0; @@ -3182,7 +3182,7 @@ pubkey2solvable(Solvable *s, Repodata *data, char *pubkey) } int -repo_add_rpmdb_pubkeys(Repo *repo, const char *rootdir, int flags) +repo_add_rpmdb_pubkeys(Repo *repo, int flags) { Pool *pool = repo->pool; struct rpm_by_state state; @@ -3192,8 +3192,11 @@ repo_add_rpmdb_pubkeys(Repo *repo, const char *rootdir, int flags) unsigned int u32; Repodata *data; Solvable *s; + const char *rootdir = 0; data = repo_add_repodata(repo, flags); + if (flags & REPO_USE_ROOTDIR) + rootdir = pool_get_rootdir(pool); memset(&state, 0, sizeof(state)); if (!(state.dbenv = opendbenv(rootdir))) @@ -3238,7 +3241,7 @@ repo_add_pubkey(Repo *repo, const char *key, int flags) data = repo_add_repodata(repo, flags); buf = 0; bufl = 0; - if ((fp = fopen(key, "r")) == 0) + if ((fp = fopen(flags & REPO_USE_ROOTDIR ? pool_prepend_rootdir_tmp(pool, key) : key, "r")) == 0) { pool_error(pool, -1, "%s: %s", key, strerror(errno)); return 0; diff --git a/ext/repo_rpmdb.h b/ext/repo_rpmdb.h index 5bd436d..1e12de7 100644 --- a/ext/repo_rpmdb.h +++ b/ext/repo_rpmdb.h @@ -10,9 +10,9 @@ struct headerToken_s; -extern int repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir, int flags); +extern int repo_add_rpmdb(Repo *repo, Repo *ref, int flags); extern Id repo_add_rpm(Repo *repo, const char *rpm, int flags); -extern int repo_add_rpmdb_pubkeys(Repo *repo, const char *rootdir, int flags); +extern int repo_add_rpmdb_pubkeys(Repo *repo, int flags); extern Id repo_add_pubkey(Repo *repo, const char *key, int flags); #define RPMDB_REPORT_PROGRESS (1 << 8) diff --git a/ext/repo_zyppdb.c b/ext/repo_zyppdb.c index 4bbc7e9..19eabd9 100644 --- a/ext/repo_zyppdb.c +++ b/ext/repo_zyppdb.c @@ -332,6 +332,8 @@ repo_add_zyppdb_products(Repo *repo, const char *dirpath, int flags) pd.sbtab[sw->to] = sw->from; } + if (flags & REPO_USE_ROOTDIR) + dirpath = pool_prepend_rootdir(repo->pool, dirpath); dir = opendir(dirpath); if (dir) { @@ -353,6 +355,8 @@ repo_add_zyppdb_products(Repo *repo, const char *dirpath, int flags) free(pd.content); join_freemem(&pd.jd); + if (flags & REPO_USE_ROOTDIR) + solv_free((char *)dirpath); if (!(flags & REPO_NO_INTERNALIZE)) repodata_internalize(data); return 0; |