Avoid .rpmnew when the file hasn't changed in package (rhbz#194246)
authorPanu Matilainen <pmatilai@redhat.com>
Tue, 28 Aug 2007 06:04:09 +0000 (09:04 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 28 Aug 2007 06:04:09 +0000 (09:04 +0300)
The current behavior of %config(noreplace) creates a .rpmnewfile iff the type
of the current file has been changed wrto what was originally installed.

The patch changes this behavior so when old and new (in db and in package) is
identical -> not changed, the function returns FA_SKIP -> it won't clobber
anything, it simply skips installation of the file from the package.
This patch handles also the opposite case when old and new packages contain
%config symlink and we have regular file on disk.

Patch from Tomas Mraz.
(transplanted from 5a57ec437cf4ec0605264ed311ff28e0e751302d)

lib/rpmfi.c

index 6c4e10e..95cb052 100644 (file)
@@ -578,7 +578,7 @@ fileAction rpmfiDecideFate(const rpmfi ofi, rpmfi nfi, int skipMissing)
     if (newWhat == XDIR)
        return FA_CREATE;
 
-    if (diskWhat != newWhat)
+    if (diskWhat != newWhat && dbWhat != REG && dbWhat != LINK)
        return save;
     else if (newWhat != dbWhat && diskWhat != dbWhat)
        return save;
@@ -594,6 +594,14 @@ fileAction rpmfiDecideFate(const rpmfi ofi, rpmfi nfi, int skipMissing)
     memset(buffer, 0, sizeof(buffer));
     if (dbWhat == REG) {
        const unsigned char * omd5, * nmd5;
+       omd5 = rpmfiMD5(ofi)
+       if (diskWhat == REG) {
+           if (domd5(fn, (unsigned char *)buffer, 0, NULL))
+               return FA_CREATE;       /* assume file has been removed */
+           if (omd5 && !memcmp(omd5, buffer, 16))
+               return FA_CREATE;       /* unmodified config file, replace. */
+       }
+
        if (domd5(fn, buffer, 0, NULL))
            return FA_CREATE;   /* assume file has been removed */
        omd5 = rpmfiMD5(ofi);
@@ -606,11 +614,13 @@ fileAction rpmfiDecideFate(const rpmfi ofi, rpmfi nfi, int skipMissing)
 /*@=nullpass@*/
     } else /* dbWhat == LINK */ {
        const char * oFLink, * nFLink;
+       oFLink = rpmfiFLink(ofi);
+       if (diskWhat == LINK) {
        if (readlink(fn, buffer, sizeof(buffer) - 1) == -1)
            return FA_CREATE;   /* assume file has been removed */
-       oFLink = rpmfiFLink(ofi);
        if (oFLink && !strcmp(oFLink, buffer))
            return FA_CREATE;   /* unmodified config file, replace. */
+       }
        nFLink = rpmfiFLink(nfi);
 /*@-nullpass@*/
        if (oFLink && nFLink && !strcmp(oFLink, nFLink))