diff options
author | jbj <devnull@localhost> | 2000-01-17 18:12:32 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2000-01-17 18:12:32 +0000 |
commit | 9416c8bfd12321109f8e1ac4f824bcb05115474c (patch) | |
tree | 62974a93d60952ae091030ab5b81d1b55b165477 /lib | |
parent | ddaf37928146cd692ddd2125547073ab974fb9f9 (diff) | |
download | librpm-tizen-9416c8bfd12321109f8e1ac4f824bcb05115474c.tar.gz librpm-tizen-9416c8bfd12321109f8e1ac4f824bcb05115474c.tar.bz2 librpm-tizen-9416c8bfd12321109f8e1ac4f824bcb05115474c.zip |
add %_rebuilddbpath macro to permit rebuilding db in new location.
CVS patchset: 3522
CVS date: 2000/01/17 18:12:32
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rebuilddb.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/lib/rebuilddb.c b/lib/rebuilddb.c index fc88cc964..d5409f495 100644 --- a/lib/rebuilddb.c +++ b/lib/rebuilddb.c @@ -9,26 +9,43 @@ int rpmdbRebuild(const char * rootdir) { rpmdb olddb, newdb; const char * dbpath = NULL; + const char * rootdbpath = NULL; const char * newdbpath = NULL; const char * newrootdbpath = NULL; + const char * tfn; int recnum; Header h; + int nocleanup = 1; int failed = 0; int rc = 0; - char tfn[64]; - rpmMessage(RPMMESS_DEBUG, _("rebuilding database in rootdir %s\n"), rootdir); - - dbpath = rpmGetPath("%{_dbpath}", NULL); - if (!(dbpath && dbpath[0] != '%')) { + tfn = rpmGetPath("%{_dbpath}", NULL); + if (!(tfn && tfn[0] != '%')) { rpmMessage(RPMMESS_DEBUG, _("no dbpath has been set")); rc = 1; goto exit; } - - sprintf(tfn, "rebuilddb.%d", (int) getpid()); - newrootdbpath = rpmGetPath(rootdir, dbpath, tfn, NULL); + rootdbpath = rpmGetPath(rootdir, tfn, NULL); + dbpath = rootdbpath + strlen(rootdir); + xfree(tfn); + + tfn = rpmGetPath("%{_rebuilddbpath}", NULL); + if (!(tfn && tfn[0] != '%' && strcmp(tfn, dbpath))) { + char pidbuf[20]; + char *t; + sprintf(pidbuf, "rebuilddb.%d", (int) getpid()); + t = xmalloc(strlen(dbpath) + strlen(pidbuf) + 1); + stpcpy(stpcpy(t, dbpath), pidbuf); + if (tfn) xfree(tfn); + tfn = t; + nocleanup = 0; + } + newrootdbpath = rpmGetPath(rootdir, tfn, NULL); newdbpath = newrootdbpath + strlen(rootdir); + xfree(tfn); + + rpmMessage(RPMMESS_DEBUG, _("rebuilding database %s into %s\n"), + rootdbpath, newrootdbpath); if (!access(newrootdbpath, F_OK)) { rpmError(RPMERR_MKDIR, _("temporary database %s already exists"), @@ -95,7 +112,7 @@ int rpmdbRebuild(const char * rootdir) rpmdbRemoveDatabase(rootdir, newdbpath); rc = 1; goto exit; - } else { + } else if (!nocleanup) { if (rpmdbMoveDatabase(rootdir, newdbpath, dbpath)) { rpmMessage(RPMMESS_ERROR, _("failed to replace old database with new " "database!\n")); @@ -111,7 +128,7 @@ int rpmdbRebuild(const char * rootdir) rc = 0; exit: - if (dbpath) xfree(dbpath); + if (rootdbpath) xfree(rootdbpath); if (newrootdbpath) xfree(newrootdbpath); return rc; |