From 78b064f4c9835263c3732312cb43a19b2df93fb7 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 3 Oct 2009 22:27:11 +0000 Subject: [PATCH] Generate an eerror message in dblink.mergeme when a file has to be renamed in order to merge a directory to the same path. svn path=/main/trunk/; revision=14485 --- pym/portage/dbapi/vartree.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 1bf05f14e..c46bcdfec 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -3963,6 +3963,26 @@ class dblink(object): return os.EX_OK + def _new_backup_path(self, p): + """ + The works for any type path, such as a regular file, symlink, + or directory. The parent directory is assumed to exist. + The returned filename is of the form p + '.backup.' + x, where + x guarantees that the returned path does not exist yet. + """ + os = _os_merge + + x = -1 + while True: + x += 1 + backup_p = p + '.backup.' + str(x).rjust(4, '0') + try: + os.lstat(backup_p) + except OSError: + break + + return backup_p + def mergeme(self, srcroot, destroot, outfile, secondhand, stufftomerge, cfgfiledict, thismtime): """ @@ -4120,7 +4140,16 @@ class dblink(object): bsd_chflags.lchflags(mydest, dflags) else: # a non-directory and non-symlink-to-directory. Won't work for us. Move out of the way. - if movefile(mydest, mydest+".backup", + backup_dest = self._new_backup_path(mydest) + msg = [] + msg.append("") + msg.append("Installation of a directory is blocked by a file:") + msg.append(" '%s'" % mydest) + msg.append("This file will be renamed to a different name:") + msg.append(" '%s'" % backup_dest) + msg.append("") + self._eerror("preinst", msg) + if movefile(mydest, backup_dest, mysettings=self.settings, encoding=_encodings['merge']) is None: return 1 @@ -4164,7 +4193,7 @@ class dblink(object): if stat.S_ISDIR(mydmode): # install of destination is blocked by an existing directory with the same name - newdest = new_protect_filename(mydest, newmd5=mymd5) + newdest = self._new_backup_path(mydest) msg = [] msg.append("") msg.append("Installation of a regular file is blocked by a directory:") -- 2.26.2