From: Stephan Kulow Date: Fri, 22 Feb 2008 10:07:53 +0000 (+0000) Subject: finish root support X-Git-Tag: BASE-SuSE-Code-12_1-Branch~872 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fac40bac9f8c4bd45d1884512afdbc1e0fbfbb0e;p=platform%2Fupstream%2Flibsolv.git finish root support --- diff --git a/tools/repo_rpmdb.c b/tools/repo_rpmdb.c index 662fcc4..9b33f3c 100644 --- a/tools/repo_rpmdb.c +++ b/tools/repo_rpmdb.c @@ -718,6 +718,7 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir) unsigned int refmask, h; int asolv; Repodata *repodata; + char dbpath[PATH_MAX]; if (repo->start != repo->end) abort(); /* FIXME: rpmdbid */ @@ -736,9 +737,10 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir) if (!ref) { - if (db->open(db, 0, "/var/lib/rpm/Packages", 0, DB_HASH, DB_RDONLY, 0664)) + snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm/Packages", rootdir); + if (db->open(db, 0, dbpath, 0, DB_HASH, DB_RDONLY, 0664)) { - perror("db->open /var/lib/rpm/Packages"); + perror("db->open var/lib/rpm/Packages"); exit(1); } if (db->get_byteswapped(db, &byteswapped)) @@ -828,9 +830,10 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir) } else { - if (db->open(db, 0, "/var/lib/rpm/Name", 0, DB_HASH, DB_RDONLY, 0664)) + snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm/Name", rootdir); + if (db->open(db, 0, dbpath, 0, DB_HASH, DB_RDONLY, 0664)) { - perror("db->open /var/lib/rpm/Name"); + perror("db->open var/lib/rpm/Name"); exit(1); } if (db->get_byteswapped(db, &byteswapped)) @@ -955,9 +958,10 @@ repo_add_rpmdb(Repo *repo, Repo *ref, const char *rootdir) perror("db_create"); exit(1); } - if (db->open(db, 0, "/var/lib/rpm/Packages", 0, DB_HASH, DB_RDONLY, 0664)) + snprintf(dbpath, PATH_MAX, "%s/var/lib/rpm/Packages", rootdir); + if (db->open(db, 0, dbpath, 0, DB_HASH, DB_RDONLY, 0664)) { - perror("db->open /var/lib/rpm/Packages"); + perror("db->open var/lib/rpm/Packages"); exit(1); } if (db->get_byteswapped(db, &byteswapped)) diff --git a/tools/rpmdb2solv.c b/tools/rpmdb2solv.c index 50f65de..44a537f 100644 --- a/tools/rpmdb2solv.c +++ b/tools/rpmdb2solv.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "pool.h" #include "repo.h" @@ -29,22 +30,28 @@ main(int argc, char **argv) Pool *pool = pool_create(); Repo *repo, *ref = 0; FILE *fp; + Pool *refpool; + int g; + const char *root = "/"; - if (argc != 1) - { - Pool *refpool = pool; - if ((fp = fopen(argv[1], "r")) == NULL) - { - perror(argv[1]); - exit(0); - } - ref = repo_create(refpool, "ref"); - repo_add_solv(ref, fp); - fclose(fp); - } - + while ((g = getopt (argc, argv, "-r:")) >= 0) + switch (g) + { + case 'r': root = optarg; break; + case 1: + refpool = pool; + if ((fp = fopen(argv[1], "r")) == NULL) + { + perror(argv[1]); + exit(0); + } + ref = repo_create(refpool, "ref"); + repo_add_solv(ref, fp); + fclose(fp); + } + repo = repo_create(pool, "installed"); - repo_add_rpmdb(repo, ref, "/"); + repo_add_rpmdb(repo, ref, root); if (ref) { if (ref->pool != pool)