aboutsummaryrefslogtreecommitdiffstats
path: root/URPM.xs
diff options
context:
space:
mode:
authorPer Øyvind Karlsen <peroyvind@mandriva.org>2011-01-09 19:37:29 +0000
committerPer Øyvind Karlsen <peroyvind@mandriva.org>2011-01-09 19:37:29 +0000
commit579fd24b49ef44e178f8454a42109c2117fee632 (patch)
tree97b90f7170876452c4bb8ea9985023134dc19fa5 /URPM.xs
parente6aaf4fd7971f354b9e10bc700ac0ddd9eaacdea (diff)
downloadperl-URPM-579fd24b49ef44e178f8454a42109c2117fee632.tar
perl-URPM-579fd24b49ef44e178f8454a42109c2117fee632.tar.gz
perl-URPM-579fd24b49ef44e178f8454a42109c2117fee632.tar.bz2
perl-URPM-579fd24b49ef44e178f8454a42109c2117fee632.tar.xz
perl-URPM-579fd24b49ef44e178f8454a42109c2117fee632.zip
ensure that a db environment with config & required directories exists for chroots before opening the rpmdb
Diffstat (limited to 'URPM.xs')
-rw-r--r--URPM.xs26
1 files changed, 26 insertions, 0 deletions
diff --git a/URPM.xs b/URPM.xs
index bc1e0ea..b96c38d 100644
--- a/URPM.xs
+++ b/URPM.xs
@@ -2805,6 +2805,9 @@ Db_open(prefix=NULL, write_perm=0)
int write_perm
PREINIT:
URPM__DB db;
+ const char *dbpath = NULL;
+ const char *tmp = NULL;
+ struct stat st;
CODE:
read_config_files(0);
db = malloc(sizeof(struct s_Transaction));
@@ -2822,6 +2825,29 @@ Db_open(prefix=NULL, write_perm=0)
} else {
rpmtsSetRootDir(db->ts, prefix && prefix[0] ? prefix : NULL);
}
+ /* XXX: be sure that we have db environment in place before using it */
+ if(rpmtsRootDir(db->ts)) {
+ dbpath = rpmGenPath(rpmtsRootDir(db->ts), "%{_dbpath}", "log");
+ rpmioMkpath(dbpath, 0755, -1, -1);
+ stpcpy((char*)dbpath+strlen(dbpath)-3, "tmp");
+ rpmioMkpath(dbpath, 0755, -1, -1);
+ dbpath = _free(dbpath);
+ dbpath = rpmGenPath(rpmtsRootDir(db->ts), "%{_dbpath}", "DB_CONFIG");
+ if(Stat(dbpath, &st) < 0) {
+ tmp = dbpath + strlen(rpmtsRootDir(db->ts))-1;
+ if(Stat(tmp, &st) >= 0) {
+ FD_t chrootDbConf = Fopen(dbpath, "w");
+ FD_t sysDbConf = Fopen(tmp, "r");
+ char buf[BUFSIZ];
+ size_t r;
+
+ while((r = Fread(buf, 1, sizeof(buf), sysDbConf)) > 0)
+ Fwrite(buf, 1, r, chrootDbConf);
+ Fclose(chrootDbConf);
+ Fclose(sysDbConf);
+ }
+ }
+ }
if (rpmtsOpenDB(db->ts, write_perm ? O_RDWR | O_CREAT : O_RDONLY) == 0) {
RETVAL = db;
} else {