summaryrefslogtreecommitdiff
path: root/lib/install.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/install.c')
-rw-r--r--lib/install.c75
1 files changed, 32 insertions, 43 deletions
diff --git a/lib/install.c b/lib/install.c
index 09b986ee0..db1c29f4e 100644
--- a/lib/install.c
+++ b/lib/install.c
@@ -233,53 +233,42 @@ static void trimChangelog(Header h)
}
/** */
-static int markReplacedFiles(rpmdb db, struct sharedFileInfo * replList)
+static int markReplacedFiles(rpmdb db, const struct sharedFileInfo * replList)
{
- struct sharedFileInfo * fileInfo;
- Header secHeader = NULL, sh;
- char * secStates = NULL;
- int secOffset = 0;
- int type, count;
-
- for (fileInfo = replList; fileInfo->otherPkg; fileInfo++) {
- if (secOffset != fileInfo->otherPkg) {
- rpmdbMatchIterator mi;
-
- if (secHeader != NULL) {
- /* ignore errors here - just do the best we can */
-
- rpmdbRemove(db, secOffset, 1);
- rpmdbAdd(db, secHeader);
- headerFree(secHeader);
- }
-
- secOffset = fileInfo->otherPkg;
-
- mi = rpmdbInitIterator(db, RPMDBI_PACKAGES, &secOffset, sizeof(secOffset));
- sh = rpmdbNextIterator(mi);
- if (sh == NULL)
- secOffset = 0;
- else
- secHeader = headerCopy(sh); /* so we can modify it */
- rpmdbFreeIterator(mi);
-
- headerGetEntry(secHeader, RPMTAG_FILESTATES, &type,
- (void **) &secStates, &count);
+ const struct sharedFileInfo * fileInfo;
+ rpmdbMatchIterator mi;
+ Header h;
+ unsigned int * offsets;
+ int num;
+
+ for (num = 0, fileInfo = replList; fileInfo->otherPkg; fileInfo++)
+ num++;
+ offsets = alloca(num * sizeof(*offsets));
+ for (num = 0, fileInfo = replList; fileInfo->otherPkg; fileInfo++)
+ offsets[num++] = fileInfo->otherPkg;
+
+ mi = rpmdbInitIterator(db, RPMDBI_PACKAGES, NULL, 0);
+ rpmdbAppendIteratorMatches(mi, offsets, num);
+
+ fileInfo = replList;
+ while ((h = rpmdbNextIterator(mi)) != NULL) {
+ char * secStates;
+ int modified;
+ int count;
+
+ headerGetEntry(h, RPMTAG_FILESTATES, NULL, (void **)&secStates, &count);
+
+ modified = 0;
+ while ( fileInfo->otherPkg &&
+ fileInfo->otherPkg == rpmdbGetIteratorOffset(mi)) {
+ secStates[fileInfo->otherFileNum] = RPMFILE_STATE_REPLACED;
+ modified = 1;
+ fileInfo++;
}
- /* by now, secHeader is the right header to modify, secStates is
- the right states list to modify */
-
- secStates[fileInfo->otherFileNum] = RPMFILE_STATE_REPLACED;
- }
-
- if (secHeader != NULL) {
- /* ignore errors here - just do the best we can */
-
- rpmdbRemove(db, secOffset, 1);
- rpmdbAdd(db, secHeader);
- headerFree(secHeader);
+ rpmdbSetIteratorModified(mi, modified);
}
+ rpmdbFreeIterator(mi);
return 0;
}