fix: incomplete cleanup if --rebuilddb fails (#4115).
authorjbj <devnull@localhost>
Tue, 20 Jul 1999 18:51:57 +0000 (18:51 +0000)
committerjbj <devnull@localhost>
Tue, 20 Jul 1999 18:51:57 +0000 (18:51 +0000)
CVS patchset: 3190
CVS date: 1999/07/20 18:51:57

CHANGES
lib/rpmdb.c
po/rpm.pot

diff --git a/CHANGES b/CHANGES
index 19900d9..d31b20d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,7 @@
        - fix: %if parsing skipped 3 chars too many.
        - permit multiline macro expansions with comments and %if.
        - add pl translation and man pages (PLD team - from Tomasz Kloczko).
+       - fix: incomplete cleanup if --rebuilddb fails (#4115).
 
 3.0.1 -> 3.0.2
        - eliminate armv4 entries from rpmrc (Andrew E. Mileski).
index eb76204..0ad39a1 100644 (file)
 #include "misc.h"
 #include "rpmdb.h"
 
+const char *rpmdb_filenames[] = {
+    "packages.rpm",
+    "nameindex.rpm",
+    "fileindex.rpm",
+    "groupindex.rpm",
+    "requiredby.rpm",
+    "providesindex.rpm",
+    "conflictsindex.rpm",
+    "triggerindex.rpm",
+    NULL
+};
+
 /* XXX the signal handling in here is not thread safe */
 
 /* the requiredbyIndex isn't stricly necessary. In a perfect world, we could
@@ -213,6 +225,10 @@ int openDatabase(const char * prefix, const char * dbpath, rpmdb *rpmdbp, int mo
 
     /* We used to store the fileindexes as complete paths, rather then
        plain basenames. Let's see which version we are... */
+    /*
+     * XXX FIXME: db.fileindex can be NULL under pathological (e.g. mixed
+     * XXX db1/db2 linkage) conditions.
+     */
     if (!justcheck && !dbiGetFirstKey(db.fileIndex, &akey)) {
        if (strchr(akey, '/')) {
            rpmError(RPMERR_OLDDB, _("old format database is present; "
@@ -671,6 +687,7 @@ int rpmdbUpdateRecord(rpmdb db, int offset, Header newHeader) {
 
 void rpmdbRemoveDatabase(const char * rootdir, const char * dbpath) { 
     int i;
+    const char **rpmdbfnp;
     char * filename;
 
     i = strlen(dbpath);
@@ -684,30 +701,19 @@ void rpmdbRemoveDatabase(const char * rootdir, const char * dbpath) {
     
     filename = alloca(strlen(rootdir) + strlen(dbpath) + 40);
 
-    sprintf(filename, "%s/%s/packages.rpm", rootdir, dbpath);
-    unlink(filename);
-
-    sprintf(filename, "%s/%s/nameindex.rpm", rootdir, dbpath);
-    unlink(filename);
-
-    sprintf(filename, "%s/%s/fileindex.rpm", rootdir, dbpath);
-    unlink(filename);
-
-    sprintf(filename, "%s/%s/groupindex.rpm", rootdir, dbpath);
-    unlink(filename);
-
-    sprintf(filename, "%s/%s/requiredby.rpm", rootdir, dbpath);
-    unlink(filename);
+    for (rpmdbfnp = rpmdb_filenames; *rpmdbfnp; rpmdbfnp++) {
+       sprintf(filename, "%s/%s/%s", rootdir, dbpath, *rpmdbfnp);
+       unlink(filename);
+    }
 
-    sprintf(filename, "%s/%s/providesindex.rpm", rootdir, dbpath);
-    unlink(filename);
+    sprintf(filename, "%s/%s", rootdir, dbpath);
+    rmdir(filename);
 
-    sprintf(filename, "%s/%s/conflictsindex.rpm", rootdir, dbpath);
-    unlink(filename);
 }
 
 int rpmdbMoveDatabase(const char * rootdir, const char * olddbpath, const char * newdbpath) {
     int i;
+    const char **rpmdbfnp;
     char * ofilename, * nfilename;
     int rc = 0;
  
@@ -732,37 +738,11 @@ int rpmdbMoveDatabase(const char * rootdir, const char * olddbpath, const char *
     ofilename = alloca(strlen(rootdir) + strlen(olddbpath) + 40);
     nfilename = alloca(strlen(rootdir) + strlen(newdbpath) + 40);
 
-    sprintf(ofilename, "%s/%s/packages.rpm", rootdir, olddbpath);
-    sprintf(nfilename, "%s/%s/packages.rpm", rootdir, newdbpath);
-    if (rename(ofilename, nfilename)) rc = 1;
-
-    sprintf(ofilename, "%s/%s/nameindex.rpm", rootdir, olddbpath);
-    sprintf(nfilename, "%s/%s/nameindex.rpm", rootdir, newdbpath);
-    if (rename(ofilename, nfilename)) rc = 1;
-
-    sprintf(ofilename, "%s/%s/fileindex.rpm", rootdir, olddbpath);
-    sprintf(nfilename, "%s/%s/fileindex.rpm", rootdir, newdbpath);
-    if (rename(ofilename, nfilename)) rc = 1;
-
-    sprintf(ofilename, "%s/%s/groupindex.rpm", rootdir, olddbpath);
-    sprintf(nfilename, "%s/%s/groupindex.rpm", rootdir, newdbpath);
-    if (rename(ofilename, nfilename)) rc = 1;
-
-    sprintf(ofilename, "%s/%s/requiredby.rpm", rootdir, olddbpath);
-    sprintf(nfilename, "%s/%s/requiredby.rpm", rootdir, newdbpath);
-    if (rename(ofilename, nfilename)) rc = 1;
-
-    sprintf(ofilename, "%s/%s/providesindex.rpm", rootdir, olddbpath);
-    sprintf(nfilename, "%s/%s/providesindex.rpm", rootdir, newdbpath);
-    if (rename(ofilename, nfilename)) rc = 1;
-
-    sprintf(ofilename, "%s/%s/conflictsindex.rpm", rootdir, olddbpath);
-    sprintf(nfilename, "%s/%s/conflictsindex.rpm", rootdir, newdbpath);
-    if (rename(ofilename, nfilename)) rc = 1;
-
-    sprintf(ofilename, "%s/%s/triggerindex.rpm", rootdir, olddbpath);
-    sprintf(nfilename, "%s/%s/triggerindex.rpm", rootdir, newdbpath);
-    if (rename(ofilename, nfilename)) rc = 1;
+    for (rpmdbfnp = rpmdb_filenames; *rpmdbfnp; rpmdbfnp++) {
+       sprintf(ofilename, "%s/%s/%s", rootdir, olddbpath, *rpmdbfnp);
+       sprintf(nfilename, "%s/%s/%s", rootdir, newdbpath, *rpmdbfnp);
+       if (rename(ofilename, nfilename)) rc = 1;
+    }
 
     return rc;
 }
index 9eff7c1..9fcf7c8 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
-"POT-Creation-Date: 1999-07-19 17:14-0400\n"
+"POT-Creation-Date: 1999-07-20 14:49-0400\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -2676,8 +2676,8 @@ msgstr ""
 msgid "rebuilding database in rootdir %s\n"
 msgstr ""
 
-#: ../lib/rebuilddb.c:23 ../lib/rpmdb.c:69 ../lib/rpmdb.c:87
-#: ../lib/rpmdb.c:103
+#: ../lib/rebuilddb.c:23 ../lib/rpmdb.c:81 ../lib/rpmdb.c:99
+#: ../lib/rpmdb.c:115
 msgid "no dbpath has been set"
 msgstr ""
 
@@ -2812,105 +2812,105 @@ msgstr ""
 msgid "OK"
 msgstr ""
 
-#: ../lib/rpmdb.c:164
+#: ../lib/rpmdb.c:176
 #, c-format
 msgid "opening database mode 0x%x in %s\n"
 msgstr ""
 
-#: ../lib/rpmdb.c:174 ../lib/url.c:421
+#: ../lib/rpmdb.c:186 ../lib/url.c:421
 #, c-format
 msgid "failed to open %s\n"
 msgstr ""
 
-#: ../lib/rpmdb.c:187 ../lib/rpmdb.c:194
+#: ../lib/rpmdb.c:199 ../lib/rpmdb.c:206
 #, c-format
 msgid "cannot get %s lock on database"
 msgstr ""
 
-#: ../lib/rpmdb.c:188
+#: ../lib/rpmdb.c:200
 msgid "exclusive"
 msgstr ""
 
-#: ../lib/rpmdb.c:195
+#: ../lib/rpmdb.c:207
 msgid "shared"
 msgstr ""
 
-#: ../lib/rpmdb.c:218
+#: ../lib/rpmdb.c:234
 msgid ""
 "old format database is present; use --rebuilddb to generate a new format "
 "database"
 msgstr ""
 
-#: ../lib/rpmdb.c:377
+#: ../lib/rpmdb.c:393
 #, c-format
 msgid "package %s not listed in %s"
 msgstr ""
 
-#: ../lib/rpmdb.c:388
+#: ../lib/rpmdb.c:404
 #, c-format
 msgid "package %s not found in %s"
 msgstr ""
 
-#: ../lib/rpmdb.c:412 ../lib/uninstall.c:89
+#: ../lib/rpmdb.c:428 ../lib/uninstall.c:89
 #, c-format
 msgid "cannot read header at %d for uninstall"
 msgstr ""
 
-#: ../lib/rpmdb.c:420
+#: ../lib/rpmdb.c:436
 msgid "package has no name"
 msgstr ""
 
-#: ../lib/rpmdb.c:422
+#: ../lib/rpmdb.c:438
 msgid "removing name index\n"
 msgstr ""
 
-#: ../lib/rpmdb.c:427
+#: ../lib/rpmdb.c:443
 msgid "package has no group\n"
 msgstr ""
 
-#: ../lib/rpmdb.c:429
+#: ../lib/rpmdb.c:445
 msgid "removing group index\n"
 msgstr ""
 
-#: ../lib/rpmdb.c:436
+#: ../lib/rpmdb.c:452
 #, c-format
 msgid "removing provides index for %s\n"
 msgstr ""
 
-#: ../lib/rpmdb.c:451
+#: ../lib/rpmdb.c:467
 #, c-format
 msgid "removing requiredby index for %s\n"
 msgstr ""
 
-#: ../lib/rpmdb.c:463
+#: ../lib/rpmdb.c:479
 #, c-format
 msgid "removing trigger index for %s\n"
 msgstr ""
 
-#: ../lib/rpmdb.c:474
+#: ../lib/rpmdb.c:490
 #, c-format
 msgid "removing conflict index for %s\n"
 msgstr ""
 
-#: ../lib/rpmdb.c:491
+#: ../lib/rpmdb.c:507
 #, c-format
 msgid "removing file index for %s\n"
 msgstr ""
 
-#: ../lib/rpmdb.c:500
+#: ../lib/rpmdb.c:516
 msgid "package has no files\n"
 msgstr ""
 
-#: ../lib/rpmdb.c:573
+#: ../lib/rpmdb.c:589
 msgid "cannot allocate space for database"
 msgstr ""
 
-#: ../lib/rpmdb.c:644
+#: ../lib/rpmdb.c:660
 #, c-format
 msgid "cannot read header at %d for update"
 msgstr ""
 
-#: ../lib/rpmdb.c:653
+#: ../lib/rpmdb.c:669
 msgid "header changed size!"
 msgstr ""