[PATCH 1 of 2 V3] py3: convert os.readlink() path to native strings on Windows

Matt Harbison mharbison72 at gmail.com
Fri Sep 28 22:33:19 EDT 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1537924572 14400
#      Tue Sep 25 21:16:12 2018 -0400
# Node ID 1b472f36e081a9a98e45f84a0cf34f5b6008dd47
# Parent  1834dabb38e08a082cde354e0f0e66310bc98cb3
py3: convert os.readlink() path to native strings on Windows

Windows insisted that it needs to be str.  I skipped the stuff in the posix
module, and left `tests/f` and `run-tests.py` alone for now.

diff --git a/hgext/convert/gnuarch.py b/hgext/convert/gnuarch.py
--- a/hgext/convert/gnuarch.py
+++ b/hgext/convert/gnuarch.py
@@ -223,7 +223,7 @@ class gnuarch_source(common.converter_so
     def _getfile(self, name, rev):
         mode = os.lstat(os.path.join(self.tmppath, name)).st_mode
         if stat.S_ISLNK(mode):
-            data = os.readlink(os.path.join(self.tmppath, name))
+            data = util.readlink(os.path.join(self.tmppath, name))
             if mode:
                 mode = 'l'
             else:
diff --git a/mercurial/posix.py b/mercurial/posix.py
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -43,6 +43,7 @@ except AttributeError:
     def oslink(src, dst):
         raise OSError(errno.EINVAL,
                       'hardlinks not supported: %s to %s' % (src, dst))
+readlink = os.readlink
 unlink = os.unlink
 rename = os.rename
 removedirs = os.removedirs
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -112,6 +112,7 @@ parsepatchoutput = platform.parsepatchou
 pconvert = platform.pconvert
 poll = platform.poll
 posixfile = platform.posixfile
+readlink = platform.readlink
 rename = platform.rename
 removedirs = platform.removedirs
 samedevice = platform.samedevice
@@ -1841,7 +1842,7 @@ def makelock(info, pathname):
 
 def readlock(pathname):
     try:
-        return os.readlink(pathname)
+        return readlink(pathname)
     except OSError as why:
         if why.errno not in (errno.EINVAL, errno.ENOSYS):
             raise
diff --git a/mercurial/vfs.py b/mercurial/vfs.py
--- a/mercurial/vfs.py
+++ b/mercurial/vfs.py
@@ -206,7 +206,7 @@ class abstractvfs(object):
         return util.rename(srcpath, dstpath)
 
     def readlink(self, path):
-        return os.readlink(self.join(path))
+        return util.readlink(self.join(path))
 
     def removedirs(self, path=None):
         """Remove a leaf directory and all empty intermediate ones
diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -519,6 +519,9 @@ def groupname(gid=None):
     If gid is None, return the name of the current group."""
     return None
 
+def readlink(pathname):
+    return pycompat.fsencode(os.readlink(pycompat.fsdecode(pathname)))
+
 def removedirs(name):
     """special version of os.removedirs that does not remove symlinked
     directories or junction points if they actually contain files"""


More information about the Mercurial-devel mailing list