From 28671731787c0a4b7b3b70f6cee174e72518eb59 Mon Sep 17 00:00:00 2001 From: Xavier Chantry Date: Sun, 19 Jul 2009 19:49:59 +0200 Subject: [PATCH] Do not create .pacsave with -R, if the file is unchanged This fixes FS#15546 Signed-off-by: Xavier Chantry --- lib/libalpm/remove.c | 39 +++++++++++++++++++++------------------ pactest/tests/remove010.py | 2 +- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index d31bf31..35aead6 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -231,17 +231,10 @@ static int can_remove_file(pmtrans_t *trans, const char *path) static void unlink_file(pmpkg_t *info, alpm_list_t *lp, pmtrans_t *trans) { struct stat buf; - int needbackup = 0; char file[PATH_MAX+1]; ALPM_LOG_FUNC; - char *hash = _alpm_needbackup(lp->data, alpm_pkg_get_backup(info)); - if(hash) { - needbackup = 1; - FREE(hash); - } - snprintf(file, PATH_MAX, "%s%s", handle->root, (char *)lp->data); if(trans->type == PM_TRANS_TYPE_REMOVEUPGRADE) { @@ -277,19 +270,29 @@ static void unlink_file(pmpkg_t *info, alpm_list_t *lp, pmtrans_t *trans) _alpm_log(PM_LOG_DEBUG, "%s is in trans->skip_remove, skipping removal\n", file); return; - } else if(needbackup) { - /* if the file is flagged, back it up to .pacsave */ - if(!(trans->flags & PM_TRANS_FLAG_NOSAVE)) { - char newpath[PATH_MAX]; - snprintf(newpath, PATH_MAX, "%s.pacsave", file); - rename(file, newpath); - _alpm_log(PM_LOG_WARNING, _("%s saved as %s\n"), file, newpath); - alpm_logaction("warning: %s saved as %s\n", file, newpath); - return; - } else { - _alpm_log(PM_LOG_DEBUG, "transaction is set to NOSAVE, not backing up '%s'\n", file); + } + + if(trans->flags & PM_TRANS_FLAG_NOSAVE) { + _alpm_log(PM_LOG_DEBUG, "transaction is set to NOSAVE, not backing up '%s'\n", file); + } else { + /* if the file needs backup and has been modified, back it up to .pacsave */ + char *pkghash = _alpm_needbackup(lp->data, alpm_pkg_get_backup(info)); + if(pkghash) { + char *filehash = alpm_compute_md5sum(file); + int cmp = strcmp(filehash,pkghash); + FREE(filehash); + FREE(pkghash); + if(cmp != 0) { + char newpath[PATH_MAX]; + snprintf(newpath, PATH_MAX, "%s.pacsave", file); + rename(file, newpath); + _alpm_log(PM_LOG_WARNING, _("%s saved as %s\n"), file, newpath); + alpm_logaction("warning: %s saved as %s\n", file, newpath); + return; + } } } + _alpm_log(PM_LOG_DEBUG, "unlinking %s\n", file); if(unlink(file) == -1) { diff --git a/pactest/tests/remove010.py b/pactest/tests/remove010.py index f818f5b..0468a3c 100644 --- a/pactest/tests/remove010.py +++ b/pactest/tests/remove010.py @@ -10,4 +10,4 @@ self.addrule("PACMAN_RETCODE=0") self.addrule("!PKG_EXIST=dummy") self.addrule("!FILE_EXIST=etc/dummy.conf") -self.addrule("FILE_PACSAVE=etc/dummy.conf") +self.addrule("!FILE_PACSAVE=etc/dummy.conf") -- 1.6.3.3