|
Panu Matilainen |
46c6a5 |
changeset: 6235:0d4b8cfd8dc9
|
|
Panu Matilainen |
46c6a5 |
tag: tip
|
|
Panu Matilainen |
46c6a5 |
user: Panu Matilainen <pmatilai@redhat.com>
|
|
Panu Matilainen |
46c6a5 |
date: Thu Aug 09 15:15:24 2007 +0300
|
|
Panu Matilainen |
46c6a5 |
files: lib/rpmfi.c lib/rpmfi.h lib/transaction.c
|
|
Panu Matilainen |
46c6a5 |
description:
|
|
Panu Matilainen |
46c6a5 |
Avoid unnecessary .rpmnew and .rpmsave files (rhbz#128622)
|
|
Panu Matilainen |
46c6a5 |
Don't create .rpmnew and .rpmsave files when file/symlink on disk differs
|
|
Panu Matilainen |
46c6a5 |
just by timestamp. Patch by Tomas Mraz.
|
|
Panu Matilainen |
46c6a5 |
|
|
Panu Matilainen |
46c6a5 |
|
|
Panu Matilainen |
46c6a5 |
diff -r debbc872bbb3 -r 0d4b8cfd8dc9 lib/rpmfi.c
|
|
Panu Matilainen |
46c6a5 |
--- a/lib/rpmfi.c Thu Aug 09 14:18:11 2007 +0300
|
|
Panu Matilainen |
46c6a5 |
+++ b/lib/rpmfi.c Thu Aug 09 15:15:24 2007 +0300
|
|
Panu Matilainen |
46c6a5 |
@@ -22,6 +22,7 @@
|
|
Panu Matilainen |
46c6a5 |
#include "rpmte.h"
|
|
Panu Matilainen |
46c6a5 |
#include "rpmts.h"
|
|
Panu Matilainen |
46c6a5 |
|
|
Panu Matilainen |
46c6a5 |
+#include "legacy.h" /* XXX domd5 */
|
|
Panu Matilainen |
46c6a5 |
#include "misc.h" /* XXX stripTrailingChar */
|
|
Panu Matilainen |
46c6a5 |
#include "rpmmacro.h" /* XXX rpmCleanPath */
|
|
Panu Matilainen |
46c6a5 |
#include "legacy.h"
|
|
Panu Matilainen |
46c6a5 |
@@ -625,6 +626,49 @@ fileAction rpmfiDecideFate(const rpmfi o
|
|
Panu Matilainen |
46c6a5 |
* merge the difference ala CVS, but...
|
|
Panu Matilainen |
46c6a5 |
*/
|
|
Panu Matilainen |
46c6a5 |
return save;
|
|
Panu Matilainen |
46c6a5 |
+}
|
|
Panu Matilainen |
46c6a5 |
+/*@=boundsread@*/
|
|
Panu Matilainen |
46c6a5 |
+
|
|
Panu Matilainen |
46c6a5 |
+/*@-boundsread@*/
|
|
Panu Matilainen |
46c6a5 |
+int rpmfiConfigConflict(const rpmfi fi)
|
|
Panu Matilainen |
46c6a5 |
+{
|
|
Panu Matilainen |
46c6a5 |
+ const char * fn = rpmfiFN(fi);
|
|
Panu Matilainen |
46c6a5 |
+ int flags = rpmfiFFlags(fi);
|
|
Panu Matilainen |
46c6a5 |
+ char buffer[1024];
|
|
Panu Matilainen |
46c6a5 |
+ fileTypes newWhat, diskWhat;
|
|
Panu Matilainen |
46c6a5 |
+ struct stat sb;
|
|
Panu Matilainen |
46c6a5 |
+
|
|
Panu Matilainen |
46c6a5 |
+ if (!(flags & RPMFILE_CONFIG) || lstat(fn, &sb)) {
|
|
Panu Matilainen |
46c6a5 |
+ return 0;
|
|
Panu Matilainen |
46c6a5 |
+ }
|
|
Panu Matilainen |
46c6a5 |
+
|
|
Panu Matilainen |
46c6a5 |
+ diskWhat = whatis((int_16)sb.st_mode);
|
|
Panu Matilainen |
46c6a5 |
+ newWhat = whatis(rpmfiFMode(fi));
|
|
Panu Matilainen |
46c6a5 |
+
|
|
Panu Matilainen |
46c6a5 |
+ if (newWhat != LINK && newWhat != REG)
|
|
Panu Matilainen |
46c6a5 |
+ return 1;
|
|
Panu Matilainen |
46c6a5 |
+
|
|
Panu Matilainen |
46c6a5 |
+ if (diskWhat != newWhat)
|
|
Panu Matilainen |
46c6a5 |
+ return 1;
|
|
Panu Matilainen |
46c6a5 |
+
|
|
Panu Matilainen |
46c6a5 |
+ memset(buffer, 0, sizeof(buffer));
|
|
Panu Matilainen |
46c6a5 |
+ if (newWhat == REG) {
|
|
Panu Matilainen |
46c6a5 |
+ const unsigned char * nmd5;
|
|
Panu Matilainen |
46c6a5 |
+ if (domd5(fn, (unsigned char *)buffer, 0, NULL))
|
|
Panu Matilainen |
46c6a5 |
+ return 0; /* assume file has been removed */
|
|
Panu Matilainen |
46c6a5 |
+ nmd5 = rpmfiMD5(fi);
|
|
Panu Matilainen |
46c6a5 |
+ if (nmd5 && !memcmp(nmd5, buffer, 16))
|
|
Panu Matilainen |
46c6a5 |
+ return 0; /* unmodified config file */
|
|
Panu Matilainen |
46c6a5 |
+ } else /* newWhat == LINK */ {
|
|
Panu Matilainen |
46c6a5 |
+ const char * nFLink;
|
|
Panu Matilainen |
46c6a5 |
+ if (readlink(fn, buffer, sizeof(buffer) - 1) == -1)
|
|
Panu Matilainen |
46c6a5 |
+ return 0; /* assume file has been removed */
|
|
Panu Matilainen |
46c6a5 |
+ nFLink = rpmfiFLink(fi);
|
|
Panu Matilainen |
46c6a5 |
+ if (nFLink && !strcmp(nFLink, buffer))
|
|
Panu Matilainen |
46c6a5 |
+ return 0; /* unmodified config file */
|
|
Panu Matilainen |
46c6a5 |
+ }
|
|
Panu Matilainen |
46c6a5 |
+
|
|
Panu Matilainen |
46c6a5 |
+ return 1;
|
|
Panu Matilainen |
46c6a5 |
}
|
|
Panu Matilainen |
46c6a5 |
/*@=boundsread@*/
|
|
Panu Matilainen |
46c6a5 |
|
|
Panu Matilainen |
46c6a5 |
diff -r debbc872bbb3 -r 0d4b8cfd8dc9 lib/rpmfi.h
|
|
Panu Matilainen |
46c6a5 |
--- a/lib/rpmfi.h Thu Aug 09 14:18:11 2007 +0300
|
|
Panu Matilainen |
46c6a5 |
+++ b/lib/rpmfi.h Thu Aug 09 15:15:24 2007 +0300
|
|
Panu Matilainen |
46c6a5 |
@@ -620,6 +620,14 @@ fileAction rpmfiDecideFate(const rpmfi o
|
|
Panu Matilainen |
46c6a5 |
/*@modifies nfi, fileSystem, internalState @*/;
|
|
Panu Matilainen |
46c6a5 |
|
|
Panu Matilainen |
46c6a5 |
/**
|
|
Panu Matilainen |
46c6a5 |
+ * Return whether file is conflicting config
|
|
Panu Matilainen |
46c6a5 |
+ * @param fi file info
|
|
Panu Matilainen |
46c6a5 |
+ * @return 1 if config file and file on disk conflicts
|
|
Panu Matilainen |
46c6a5 |
+ */
|
|
Panu Matilainen |
46c6a5 |
+int rpmfiConfigConflict(const rpmfi fi)
|
|
Panu Matilainen |
46c6a5 |
+ /*@*/;
|
|
Panu Matilainen |
46c6a5 |
+
|
|
Panu Matilainen |
46c6a5 |
+/**
|
|
Panu Matilainen |
46c6a5 |
* Return formatted string representation of package disposition.
|
|
Panu Matilainen |
46c6a5 |
* @param fi file info set
|
|
Panu Matilainen |
46c6a5 |
* @return formatted string
|
|
Panu Matilainen |
46c6a5 |
diff -r debbc872bbb3 -r 0d4b8cfd8dc9 lib/transaction.c
|
|
Panu Matilainen |
46c6a5 |
--- a/lib/transaction.c Thu Aug 09 14:18:11 2007 +0300
|
|
Panu Matilainen |
46c6a5 |
+++ b/lib/transaction.c Thu Aug 09 15:15:24 2007 +0300
|
|
Panu Matilainen |
46c6a5 |
@@ -547,7 +547,7 @@ static void handleOverlappedFiles(const
|
|
Panu Matilainen |
46c6a5 |
/*@-boundswrite@*/
|
|
Panu Matilainen |
46c6a5 |
switch (rpmteType(p)) {
|
|
Panu Matilainen |
46c6a5 |
case TR_ADDED:
|
|
Panu Matilainen |
46c6a5 |
- { struct stat sb;
|
|
Panu Matilainen |
46c6a5 |
+ {
|
|
Panu Matilainen |
46c6a5 |
int reportConflicts =
|
|
Panu Matilainen |
46c6a5 |
!(rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACENEWFILES);
|
|
Panu Matilainen |
46c6a5 |
int done = 0;
|
|
Panu Matilainen |
46c6a5 |
@@ -556,7 +556,7 @@ static void handleOverlappedFiles(const
|
|
Panu Matilainen |
46c6a5 |
/* XXX is this test still necessary? */
|
|
Panu Matilainen |
46c6a5 |
if (fi->actions[i] != FA_UNKNOWN)
|
|
Panu Matilainen |
46c6a5 |
/*@switchbreak@*/ break;
|
|
Panu Matilainen |
46c6a5 |
- if ((FFlags & RPMFILE_CONFIG) && !lstat(fn, &sb)) {
|
|
Panu Matilainen |
46c6a5 |
+ if (rpmfiConfigConflict(fi)) {
|
|
Panu Matilainen |
46c6a5 |
/* Here is a non-overlapped pre-existing config file. */
|
|
Panu Matilainen |
46c6a5 |
fi->actions[i] = (FFlags & RPMFILE_NOREPLACE)
|
|
Panu Matilainen |
46c6a5 |
? FA_ALTNAME : FA_BACKUP;
|
|
Panu Matilainen |
46c6a5 |
@@ -613,7 +613,7 @@ assert(otherFi != NULL);
|
|
Panu Matilainen |
46c6a5 |
/* Try to get the disk accounting correct even if a conflict. */
|
|
Panu Matilainen |
46c6a5 |
fixupSize = rpmfiFSize(otherFi);
|
|
Panu Matilainen |
46c6a5 |
|
|
Panu Matilainen |
46c6a5 |
- if ((FFlags & RPMFILE_CONFIG) && !lstat(fn, &sb)) {
|
|
Panu Matilainen |
46c6a5 |
+ if (rpmfiConfigConflict(fi)) {
|
|
Panu Matilainen |
46c6a5 |
/* Here is an overlapped pre-existing config file. */
|
|
Panu Matilainen |
46c6a5 |
fi->actions[i] = (FFlags & RPMFILE_NOREPLACE)
|
|
Panu Matilainen |
46c6a5 |
? FA_ALTNAME : FA_SKIP;
|
|
Panu Matilainen |
46c6a5 |
|