A bit of sanity checking in rpmtsRebuildDB()
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 3 Dec 2010 13:31:01 +0000 (15:31 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 10 Dec 2010 15:05:22 +0000 (17:05 +0200)
- Don't permit rebuilddb on populated transaction as rebuild can
  and usually does change header instance numbering.
(cherry picked from commit 626e78429ff6dd77de77abb9073c3defacdd5726)

lib/rpmts.c

index 228ceb8..cfe4ac4 100644 (file)
@@ -125,14 +125,21 @@ int rpmtsSetDBMode(rpmts ts, int dbmode)
 
 int rpmtsRebuildDB(rpmts ts)
 {
-    int rc;
-    rpmlock lock = rpmtsAcquireLock(ts);
-    if (!lock) return -1;
-    if (!(ts->vsflags & RPMVSF_NOHDRCHK))
-       rc = rpmdbRebuild(ts->rootDir, ts, headerCheck);
-    else
-       rc = rpmdbRebuild(ts->rootDir, NULL, NULL);
-    rpmlockFree(lock);
+    int rc = -1;
+    rpmlock lock = NULL;
+
+    /* Cannot do this on a populated transaction set */
+    if (rpmtsNElements(ts) > 0)
+       return -1;
+
+    lock = rpmtsAcquireLock(ts);
+    if (lock) {
+       if (!(ts->vsflags & RPMVSF_NOHDRCHK))
+           rc = rpmdbRebuild(ts->rootDir, ts, headerCheck);
+       else
+           rc = rpmdbRebuild(ts->rootDir, NULL, NULL);
+       rpmlockFree(lock);
+    }
     return rc;
 }