diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2012-08-21 14:38:22 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2012-08-21 14:38:22 +0300 |
commit | 9f9ed70e2d85b0e8f5e2d9cf9969046034d9ad31 (patch) | |
tree | 77b3ca777f6ec68375a5b06e3f8ce27a3ab2702e /lib | |
parent | 4c0834f7255cf6480c497cc0f0eb144c8fcf405d (diff) | |
download | rpm-9f9ed70e2d85b0e8f5e2d9cf9969046034d9ad31.tar.gz rpm-9f9ed70e2d85b0e8f5e2d9cf9969046034d9ad31.tar.bz2 rpm-9f9ed70e2d85b0e8f5e2d9cf9969046034d9ad31.zip |
Polish the regular config file comparison a bit
- Only return early in the cases where backup will NOT be needed.
Pay more attention to what kind of files we're comparing in each
case, add a little breathing room and extra comments.
- This probably doesn't change anything as-is, but hopefully makes
the logic a bit easier to follow and prepares us for the next steps.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rpmfi.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/rpmfi.c b/lib/rpmfi.c index 52fd08cd5..b069cdd3c 100644 --- a/lib/rpmfi.c +++ b/lib/rpmfi.c @@ -636,13 +636,19 @@ rpmFileAction rpmfiDecideFateIndex(rpmfi ofi, int oix, rpmfi nfi, int nix, int oalgo, nalgo; size_t odiglen, ndiglen; const unsigned char * odigest, * ndigest; + + /* See if the file on disk is identical to the one in old pkg */ 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) == 0) return FA_CREATE; /* unmodified config file, replace. */ + } + + /* See if the file on disk is identical to the one in new pkg */ + ndigest = rpmfiFDigestIndex(nfi, nix, &nalgo, &ndiglen); + if (diskWhat == REG && newWhat == REG) { /* hash algo changed in new, recalculate digest */ if (oalgo != nalgo) if (rpmDoDigest(nalgo, fn, 0, (unsigned char *)buffer, NULL)) @@ -650,11 +656,14 @@ rpmFileAction rpmfiDecideFateIndex(rpmfi ofi, int oix, rpmfi nfi, int nix, if (ndigest && memcmp(ndigest, buffer, ndiglen) == 0) return FA_CREATE; /* file identical in new, replace. */ } - /* Can't compare different hash types, backup to avoid data loss */ - if (oalgo != nalgo || odiglen != ndiglen) - return save; - if (odigest && ndigest && memcmp(odigest, ndigest, odiglen) == 0) - return FA_SKIP; /* identical file, don't bother. */ + + /* If file can be determined identical in old and new pkg, let it be */ + if (newWhat == REG && oalgo == nalgo && odiglen == ndiglen) { + if (odigest && ndigest && memcmp(odigest, ndigest, odiglen) == 0) + return FA_SKIP; /* identical file, dont bother */ + } + + /* ...but otherwise a backup will be needed */ } else /* dbWhat == LINK */ { const char * oFLink, * nFLink; oFLink = rpmfiFLinkIndex(ofi, oix); |