Dont create redundant %config backups when on-disk content is same as new
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 20 Aug 2012 09:42:36 +0000 (12:42 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 20 Aug 2012 09:42:36 +0000 (12:42 +0300)
- When on-disk %config file contents match the contents of the new
  package (such as config in old package was buggy, fixed in new
  and admin worked around in the meantime) there's no point creating
  a backup that's identical to what you already have. Note that
  we create the new config anyway instead of skipping as timestamp
  might have changed.
- Adjust test-cases to the new saner behavior.

lib/rpmfi.c
tests/rpmconfig.at

index 7ccee9f..f61b825 100644 (file)
@@ -637,13 +637,19 @@ rpmFileAction rpmfiDecideFateIndex(rpmfi ofi, int oix, rpmfi nfi, int nix,
        size_t odiglen, ndiglen;
        const unsigned char * odigest, * ndigest;
        odigest = rpmfiFDigestIndex(ofi, oix, &oalgo, &odiglen);
+       ndigest = rpmfiFDigestIndex(nfi, nix, &nalgo, &ndiglen);
        if (diskWhat == REG) {
            if (rpmDoDigest(oalgo, fn, 0, (unsigned char *)buffer, NULL))
                return FA_CREATE;       /* assume file has been removed */
            if (odigest && !memcmp(odigest, buffer, odiglen))
                return FA_CREATE;       /* unmodified config file, replace. */
+           /* hash algo changed in new, recalculate digest */
+           if (oalgo != nalgo)
+               if (rpmDoDigest(nalgo, fn, 0, (unsigned char *)buffer, NULL))
+                   return FA_CREATE;   /* assume file has been removed */
+           if (ndigest && !memcmp(ndigest, buffer, ndiglen))
+               return FA_CREATE;       /* file identical in new, replace. */
        }
-       ndigest = rpmfiFDigestIndex(nfi, nix, &nalgo, &ndiglen);
        /* Can't compare different hash types, backup to avoid data loss */
        if (oalgo != nalgo || odiglen != ndiglen)
            return save;
index 12728a5..bc04050 100644 (file)
@@ -132,8 +132,7 @@ otherstuff
 AT_CLEANUP
 
 # ------------------------------
-# Modified config file matches the content from new package. Creating a 
-# backup makes no sense in this case, but that's what currently happens.
+# Modified config file matches the content from new package.
 AT_SETUP([upgrade changing, modified config 2])
 AT_KEYWORDS([install])
 AT_CHECK([
@@ -162,8 +161,7 @@ cat "${cf}"
 foo-2.0
 foo-2.0
 ],
-[warning: /etc/my.conf saved as /etc/my.conf.rpmsave]
-)
+[])
 AT_CLEANUP
 
 # config(noreplace) variants of the same cases.
@@ -303,8 +301,7 @@ foo-2.0
 AT_CLEANUP
 
 # ------------------------------
-# Modified config file matches the content from new package. Creating a 
-# backup makes no sense in this case, but that's what currently happens.
+# Modified config file matches the content from new package.
 AT_SETUP([upgrade changing, modified config(noreplace) 2])
 AT_KEYWORDS([install])
 AT_CHECK([
@@ -334,8 +331,7 @@ cat "${cf}"
 foo-2.0
 foo-2.0
 ],
-[warning: /etc/my.conf created as /etc/my.conf.rpmnew]
-)
+[])
 AT_CLEANUP
 
 # Shared config file variants of the same cases
@@ -498,8 +494,7 @@ otherstuff
 AT_CLEANUP
 
 # ------------------------------
-# Modified config file matches the content from new package. Creating a 
-# backup makes no sense in this case, but that's what currently happens.
+# Modified config file matches the content from new package.
 AT_SETUP([upgrade changing, modified shared config 2])
 AT_KEYWORDS([install])
 AT_CHECK([
@@ -535,8 +530,7 @@ cat "${cf}"
 foo-2.0
 foo-2.0
 ],
-[warning: /etc/my.conf saved as /etc/my.conf.rpmsave]
-)
+[])
 AT_CLEANUP
 
 # Shared config(noreplace) variants of the more interesting cases
@@ -585,8 +579,7 @@ foo-2.0
 AT_CLEANUP
 
 # ------------------------------
-# Modified config file matches the content from new package. Creating a 
-# backup makes no sense in this case, but that's what currently happens.
+# Modified config file matches the content from new package.
 AT_SETUP([upgrade changing, modified shared config(noreplace) 2])
 AT_KEYWORDS([install])
 AT_CHECK([
@@ -623,6 +616,5 @@ cat "${cf}"
 foo-2.0
 foo-2.0
 ],
-[warning: /etc/my.conf created as /etc/my.conf.rpmnew]
-)
+[])
 AT_CLEANUP