summaryrefslogtreecommitdiff
path: root/lib/rpmfi.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2007-08-09 15:15:24 +0300
committerPanu Matilainen <pmatilai@redhat.com>2007-08-09 15:15:24 +0300
commitebfbc82bb1cd01bb58c5263e2bb5cba478667be2 (patch)
tree2caf7e4f46bac3a434a001e13888ba01e18c963a /lib/rpmfi.c
parent2c8d28ef6aca0007dc7c3b776d10205661647521 (diff)
downloadrpm-ebfbc82bb1cd01bb58c5263e2bb5cba478667be2.tar.gz
rpm-ebfbc82bb1cd01bb58c5263e2bb5cba478667be2.tar.bz2
rpm-ebfbc82bb1cd01bb58c5263e2bb5cba478667be2.zip
Avoid unnecessary .rpmnew and .rpmsave files (rhbz#128622)
Don't create .rpmnew and .rpmsave files when file/symlink on disk differs just by timestamp. Patch by Tomas Mraz.
Diffstat (limited to 'lib/rpmfi.c')
-rw-r--r--lib/rpmfi.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/rpmfi.c b/lib/rpmfi.c
index 64d660dd7..bed84893d 100644
--- a/lib/rpmfi.c
+++ b/lib/rpmfi.c
@@ -22,6 +22,7 @@
#include "rpmte.h"
#include "rpmts.h"
+#include "legacy.h" /* XXX domd5 */
#include "misc.h" /* XXX stripTrailingChar */
#include "rpmmacro.h" /* XXX rpmCleanPath */
#include "legacy.h"
@@ -628,6 +629,49 @@ fileAction rpmfiDecideFate(const rpmfi ofi, rpmfi nfi, int skipMissing)
}
/*@=boundsread@*/
+/*@-boundsread@*/
+int rpmfiConfigConflict(const rpmfi fi)
+{
+ const char * fn = rpmfiFN(fi);
+ int flags = rpmfiFFlags(fi);
+ char buffer[1024];
+ fileTypes newWhat, diskWhat;
+ struct stat sb;
+
+ if (!(flags & RPMFILE_CONFIG) || lstat(fn, &sb)) {
+ return 0;
+ }
+
+ diskWhat = whatis((int_16)sb.st_mode);
+ newWhat = whatis(rpmfiFMode(fi));
+
+ if (newWhat != LINK && newWhat != REG)
+ return 1;
+
+ if (diskWhat != newWhat)
+ return 1;
+
+ memset(buffer, 0, sizeof(buffer));
+ if (newWhat == REG) {
+ const unsigned char * nmd5;
+ if (domd5(fn, (unsigned char *)buffer, 0, NULL))
+ return 0; /* assume file has been removed */
+ nmd5 = rpmfiMD5(fi);
+ if (nmd5 && !memcmp(nmd5, buffer, 16))
+ return 0; /* unmodified config file */
+ } else /* newWhat == LINK */ {
+ const char * nFLink;
+ if (readlink(fn, buffer, sizeof(buffer) - 1) == -1)
+ return 0; /* assume file has been removed */
+ nFLink = rpmfiFLink(fi);
+ if (nFLink && !strcmp(nFLink, buffer))
+ return 0; /* unmodified config file */
+ }
+
+ return 1;
+}
+/*@=boundsread@*/
+
/*@observer@*/
const char * rpmfiTypeString(rpmfi fi)
{