merge: avoid abssymlink readlink call
authorZac Medico <zmedico@gentoo.org>
Tue, 6 Sep 2011 18:34:57 +0000 (11:34 -0700)
committerZac Medico <zmedico@gentoo.org>
Tue, 6 Sep 2011 18:34:57 +0000 (11:34 -0700)
This will avoid the "OSError: [Errno 2] No such file or directory" that
is triggered inside abssymlink if the merge encoding is not ascii or
utf_8, as shown in bug #382021.

pym/portage/__init__.py
pym/portage/dbapi/vartree.py

index 901ea2c9678f1bb101030b45a7790c5e582d9772..d73ea6d5e944c1659a659d61d4b42f05184e8ee9 100644 (file)
@@ -391,9 +391,12 @@ def getcwd():
                return "/"
 getcwd()
 
-def abssymlink(symlink):
+def abssymlink(symlink, target=None):
        "This reads symlinks, resolving the relative symlinks, and returning the absolute."
-       mylink=os.readlink(symlink)
+       if target is None:
+               mylink = target
+       else:
+               mylink = os.readlink(symlink)
        if mylink[0] != '/':
                mydir=os.path.dirname(symlink)
                mylink=mydir+"/"+mylink
index bafe13885d30e7c14b09801dd1dd442133f12638..4d0a6dd4cb3ebbe931446afa1b6da1ef5a148257 100644 (file)
@@ -4013,7 +4013,12 @@ class dblink(object):
                                        os.unlink(mysrc)
                                        os.symlink(myto, mysrc)
 
-                               myabsto = abssymlink(mysrc)
+                               # Pass in the symlink target in order to bypass the
+                               # os.readlink() call inside abssymlink(), since that
+                               # call is unsafe if the merge encoding is not ascii
+                               # or utf_8 (see bug #382021).
+                               myabsto = abssymlink(mysrc, target=myto)
+
                                if myabsto.startswith(srcroot):
                                        myabsto = myabsto[len(srcroot):]
                                myabsto = myabsto.lstrip(sep)