From 6b22da60ce1f96b9c4bdd76aa80896c8579619b6 Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Mon, 4 Apr 2011 19:35:05 +0200 Subject: [PATCH] cleanup real file part of mergeme() --- pym/portage/dbapi/vartree.py | 99 +++++++++++++++++------------------------ 1 files changed, 41 insertions(+), 58 deletions(-) diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 08263d6..a3e816f 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -3729,63 +3729,48 @@ class dblink(object): elif stat.S_ISREG(mymode): # we are merging a regular file mymd5 = perform_md5(mysrc, calc_prelink=calc_prelink) - # calculate config file protection stuff - mydestdir = os.path.dirname(mydest) - moveme = 1 - zing = "!!!" mymtime = None + moveme = 1 + zing = ">>>" + # now, config file management may come into play protected = self.isprotected(mydest) - if mydmode != None: - # destination file exists - - if stat.S_ISDIR(mydmode): - # install of destination is blocked by an existing directory with the same name - newdest = self._new_backup_path(mydest) - msg = [] - msg.append("") - msg.append(_("Installation of a regular file is blocked by a directory:")) - msg.append(" '%s'" % mydest) - msg.append(_("This file will be merged with a different name:")) - msg.append(" '%s'" % newdest) - msg.append("") - self._eerror("preinst", msg) - mydest = newdest - - elif stat.S_ISREG(mydmode) or (stat.S_ISLNK(mydmode) and os.path.exists(mydest) and stat.S_ISREG(os.stat(mydest)[stat.ST_MODE])): - # install of destination is blocked by an existing regular file, - # or by a symlink to an existing regular file; - # now, config file management may come into play. - # we only need to tweak mydest if cfg file management is in play. - if protected: - # we have a protection path; enable config file management. - cfgprot = 0 - destmd5 = perform_md5(mydest, calc_prelink=calc_prelink) - if mymd5 == destmd5: - #file already in place; simply update mtimes of destination - moveme = 1 - else: - if mymd5 == cfgfiledict.get(myrealdest, [None])[0]: - """ An identical update has previously been - merged. Skip it unless the user has chosen - --noconfmem.""" - moveme = cfgfiledict["IGNORE"] - cfgprot = cfgfiledict["IGNORE"] - if not moveme: - zing = "---" - mymtime = mystat[stat.ST_MTIME] - else: - moveme = 1 - cfgprot = 1 - if moveme: - # Merging a new file, so update confmem. - cfgfiledict[myrealdest] = [mymd5] - elif destmd5 == cfgfiledict.get(myrealdest, [None])[0]: - """A previously remembered update has been - accepted, so it is removed from confmem.""" - del cfgfiledict[myrealdest] - - if cfgprot: - mydest = new_protect_filename(mydest, newmd5=mymd5) + if mydmode == None: + # destination doesn't exist yet + pass + elif stat.S_ISDIR(mydmode): + # destination is blocked by an existing directory + newdest = self._new_backup_path(mydest) + zing = "!!!" + msg = [] + msg.append("") + msg.append(_("Installation of a regular file is blocked by a directory:")) + msg.append(" '%s'" % mydest) + msg.append(_("This file will be merged with a different name:")) + msg.append(" '%s'" % newdest) + msg.append("") + self._eerror("preinst", msg) + mydest = newdest + elif protected and (stat.S_ISREG(mydmode) or (stat.S_ISLNK(mydmode) and os.path.exists(mydest) and stat.S_ISREG(os.stat(mydest)[stat.ST_MODE]))): + # protected destination is blocked by an existing regular file, or + # by a symlink to an existing regular file + if mymd5 == cfgfiledict.get(myrealdest, [None])[0] and not cfgfiledict["IGNORE"]: + # skip file since an identical update has previously + # been merged and the user has not chosen --noconfmem + moveme = 0 + zing = "---" + mymtime = mystat[stat.ST_MTIME] + # a previously remembered update has been accepted, + # so it is removed from confmem + del cfgfiledict[myrealdest] + elif mymd5 == perform_md5(mydest, calc_prelink=1): + # destination file is identical but this doesn't mean + # that it was previously merged that way. (Otherwise + # above if would have succeeded) + pass + else: + # conflict with destination + mydest = new_protect_filename(mydest, newmd5=mymd5) + cfgfiledict[myrealdest] = [mymd5] # whether config protection or not, we merge the new file the # same way. Unless moveme=0 (blocking directory) @@ -3807,10 +3792,8 @@ class dblink(object): return 1 if hardlink_candidates is not None: hardlink_candidates.append(mydest) - zing = ">>>" - if mymtime != None: - outfile.write("obj "+myrealdest+" "+mymd5+" "+str(mymtime)+"\n") + outfile.write("obj "+myrealdest+" "+mymd5+" "+str(mymtime)+"\n") showMessage("%s %s\n" % (zing,mydest)) else: # we are merging a fifo or device node -- 1.7.5.rc1