summaryrefslogtreecommitdiff
path: root/lib/rpmdb.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2010-09-13 14:16:44 +0300
committerPanu Matilainen <pmatilai@redhat.com>2010-09-13 14:16:44 +0300
commitb0338657a85ae9e1c77d58b42363d23dde012550 (patch)
treed6f4d98e9ec7e13644b18068e78b14b48812fcac /lib/rpmdb.c
parentb6d8d0e7ed7989ce5e2d4d8133d81adc4072440c (diff)
downloadrpm-b0338657a85ae9e1c77d58b42363d23dde012550.tar.gz
rpm-b0338657a85ae9e1c77d58b42363d23dde012550.tar.bz2
rpm-b0338657a85ae9e1c77d58b42363d23dde012550.zip
Rearrange newRpmdb() a bit for clarity
- Avoid allocating the structure until we know its ok.
Diffstat (limited to 'lib/rpmdb.c')
-rw-r--r--lib/rpmdb.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/rpmdb.c b/lib/rpmdb.c
index 6b09e7043..ca65249ee 100644
--- a/lib/rpmdb.c
+++ b/lib/rpmdb.c
@@ -658,7 +658,16 @@ int rpmdbSync(rpmdb db)
static rpmdb newRpmdb(const char * root, const char * home,
int mode, int perms, int flags)
{
- rpmdb db = xcalloc(sizeof(*db), 1);
+ rpmdb db = NULL;
+ char * db_home = rpmGetPath((home && *home) ? home : "%{_dbpath}", NULL);
+
+ if (!(db_home && db_home[0] != '%')) {
+ rpmlog(RPMLOG_ERR, _("no dbpath has been set\n"));
+ free(db_home);
+ return NULL;
+ }
+
+ db = xcalloc(sizeof(*db), 1);
if (!(perms & 0600)) perms = 0644; /* XXX sanity */
@@ -666,13 +675,7 @@ static rpmdb newRpmdb(const char * root, const char * home,
db->db_perms = (perms >= 0) ? perms : 0644;
db->db_flags = (flags >= 0) ? flags : 0;
- db->db_home = rpmGetPath( (home && *home ? home : "%{_dbpath}"), NULL);
- if (!(db->db_home && db->db_home[0] != '%')) {
- rpmlog(RPMLOG_ERR, _("no dbpath has been set\n"));
- db->db_home = _free(db->db_home);
- db = _free(db);
- return NULL;
- }
+ db->db_home = db_home;
db->db_root = rpmGetPath((root && *root) ? root : "/", NULL);
db->db_fullpath = rpmGenPath(db->db_root, db->db_home, NULL);
/* XXX remove environment after chrooted operations, for now... */