diff -urN rpm-4.4.9.org/rpmdb/rpmdb.c rpm-4.4.9/rpmdb/rpmdb.c --- rpm-4.4.9.org/rpmdb/rpmdb.c 2007-11-18 15:11:35.653546000 +0100 +++ rpm-4.4.9/rpmdb/rpmdb.c 2007-11-18 15:14:35.666077651 +0100 @@ -3899,11 +3899,6 @@ int * dbiTags = NULL; int dbiTagsMax = 0; - /*@-branchstate@*/ - if (prefix == NULL) prefix = "/"; - /*@=branchstate@*/ - prefix = rpmGetPath(prefix, NULL); /* strip trailing '/' */ - _dbapi = rpmExpandNumeric("%{_dbapi}"); _dbapi_rebuild = rpmExpandNumeric("%{_dbapi_rebuild}"); @@ -3920,6 +3915,16 @@ rc = 1; goto exit; } + /* Add --root prefix iff --dbpath is not a URL. */ + switch (urlPath(tfn, NULL)) { + default: + prefix = xstrdup(""); + break; + case URL_IS_UNKNOWN: + prefix = rpmGetPath((prefix ? prefix : "/"), NULL); + break; + } + dbpath = rootdbpath = rpmGetPath(prefix, tfn, NULL); if (!(prefix[0] == '/' && prefix[1] == '\0')) dbpath += strlen(prefix); @@ -3945,7 +3950,7 @@ } newdbpath = newrootdbpath = rpmGetPath(prefix, tfn, NULL); if (!(prefix[0] == '/' && prefix[1] == '\0')) - newdbpath += strlen(prefix) - 1; + newdbpath += strlen(prefix); tfn = _free(tfn); rpmMessage(RPMMESS_DEBUG, _("rebuilding database %s into %s\n"),