Generate an eerror message in dblink.mergeme when a file has to be renamed in v2.2_rc43
authorZac Medico <zmedico@gentoo.org>
Sat, 3 Oct 2009 22:27:11 +0000 (22:27 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 3 Oct 2009 22:27:11 +0000 (22:27 -0000)
order to merge a directory to the same path.

svn path=/main/trunk/; revision=14485

pym/portage/dbapi/vartree.py

index 1bf05f14ee82531b33c50298978aef7c27f5d029..c46bcdfecf5e598501d6353449242056b48b8a52 100644 (file)
@@ -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:")