From 4fe20ccd59a93451eb651aa70f6ad7ca7b4e784e Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Sun, 26 Nov 2006 16:38:30 +0000 Subject: [PATCH] Merged from trunk 5132:5135 Never overwrite an untouched config file and trigger config protection instead (in case the new config has an unwanted change). In cases where an installed package in the same slot owns a protected file that will be merged, bump the mtime on the installed file in order to ensure that it isn't unmerged. Thanks to Ciaran McCreesh for his suggestion on bug #8423, comment #40. Update the dblink.isprotected() docstring. For bug #8423, make etc-update preserve timestamps when possible. svn path=/main/branches/prefix/; revision=5138 --- bin/etc-update | 2 -- pym/portage.py | 48 +++++++++--------------------------------------- 2 files changed, 9 insertions(+), 41 deletions(-) diff --git a/bin/etc-update b/bin/etc-update index bae1064c0..8911a2033 100755 --- a/bin/etc-update +++ b/bin/etc-update @@ -336,7 +336,6 @@ Please select from the menu above (-1 to ignore this update): " 1) echo "Replacing ${ofile} with ${file}" mv ${mv_opts} ${file} ${ofile} [ -n "${OVERWRITE_ALL}" ] && my_input=-1 - [ -e "${file}" ] || touch ${ofile} continue ;; 2) echo "Deleting ${file}" @@ -388,7 +387,6 @@ Please select from the menu above (-1 to exit, losing this merge): " 1) echo "Replacing ${ofile} with ${mfile}" chmod --reference=${ofile} ${mfile} mv ${mv_opts} ${mfile} ${ofile} - [ -e "${mfile}" ] || touch ${ofile} rm ${rm_opts} ${file} return 255 ;; diff --git a/pym/portage.py b/pym/portage.py index 883658d3f..4f980a18b 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -6434,10 +6434,9 @@ class dblink: return False def isprotected(self, filename): - """Files are protected by CONFIG_PROTECT only if they are not identical - to the file that was originally installed (otherwise, the unmerge phase - can remove them). This allows the merge phase to replace files that - will eventually be unmerged anyway.""" + """In cases where an installed package in the same slot owns a + protected file that will be merged, bump the mtime on the installed + file in order to ensure that it isn't unmerged.""" if not self._config_protect.isprotected(filename): return False if self._installed_instance is None: @@ -6445,48 +6444,19 @@ class dblink: mydata = self._installed_instance.getcontents().get(filename, None) if mydata is None: return True - # Duplicate unmerge logic. Protect the file if it's not identical - # to the one that was originally merged. + + # Bump the mtime in order to ensure that the old config file doesn't + # get unmerged. The user will have an opportunity to merge the new + # config with the old one. try: - lstatobj = os.lstat(filename) + os.utime(filename, None) except OSError, e: if e.errno != errno.ENOENT: raise del e # The file has disappeared, so it's not protected. return False - try: - statobj = os.stat(filename) - except OSError, e: - if e.errno != errno.ENOENT: - raise - del e - statobj = None - lmtime = str(lstatobj[stat.ST_MTIME]) - mytype = mydata[0] - if mytype not in ("dir","fif","dev") and \ - lmtime != mydata[1]: - return True - if "dir" == mytype: - return statobj is None or not stat.S_ISDIR(statobj.st_mode) - elif "sym" == mytype: - return not stat.S_ISLNK(lstatobj.st_mode) - elif "obj" == mytype: - if statobj is None or not stat.S_ISREG(statobj.st_mode): - return True - try: - mymd5 = portage_checksum.perform_md5(filename, calc_prelink=1) - except portage_exception.FileNotFound: - # The file has disappeared, so it's not protected. - return False - return mymd5 != mydata[2].lower() - elif "fif" == mytype: - return not stat.S_ISFIFO(lstatobj[stat.ST_MODE]) - elif "dev" == mytype: - return True - # This should be unreachable. - raise AssertionError("Unrecognized type '%s' in file '%s'" % (mytype, - os.path.join(self._installed_instance.dbdir, "CONTENTS"))) + return True def treewalk(self, srcroot, destroot, inforoot, myebuild, cleanup=0, mydbapi=None, prev_mtimes=None): -- 2.26.2