Patchwork [4,of,4] py3: convert os.readlink() path to native strings

login
register
mail settings
Submitter Matt Harbison
Date Sept. 27, 2018, 3:12 a.m.
Message ID <d7aa84fbb3da463c6819.1538017976@Envy>
Download mbox | patch
Permalink /patch/35131/
State Accepted
Headers show

Comments

Matt Harbison - Sept. 27, 2018, 3:12 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1537924572 14400
#      Tue Sep 25 21:16:12 2018 -0400
# Node ID d7aa84fbb3da463c68190aa746cbc6af40c6b8bc
# Parent  549bc25529a2d8d1c67736110c90491cc1eafc76
py3: convert os.readlink() path to native strings

Windows insisted that it needs to be str.  I skipped the stuff that's obviously
posix only, and left `tests/f` and `run-tests.py` alone for now.
Yuya Nishihara - Sept. 27, 2018, 11:07 a.m.
On Wed, 26 Sep 2018 23:12:56 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1537924572 14400
> #      Tue Sep 25 21:16:12 2018 -0400
> # Node ID d7aa84fbb3da463c68190aa746cbc6af40c6b8bc
> # Parent  549bc25529a2d8d1c67736110c90491cc1eafc76
> py3: convert os.readlink() path to native strings

Queued the first three, thanks.

> Windows insisted that it needs to be str.  I skipped the stuff that's obviously
> posix only, and left `tests/f` and `run-tests.py` alone for now.
> 
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -1841,7 +1841,7 @@ def makelock(info, pathname):
>  
>  def readlock(pathname):
>      try:
> -        return os.readlink(pathname)
> +        return os.readlink(pycompat.fsdecode(pathname))

This makes readlock() return a unicode string on Python 3 because the type
of the return value *depends on* the input argument. And we indeed want a
bytes string.

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1841,7 +1841,7 @@  def makelock(info, pathname):
 
 def readlock(pathname):
     try:
-        return os.readlink(pathname)
+        return os.readlink(pycompat.fsdecode(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 os.readlink(pycompat.fsdecode(self.join(path)))
 
     def removedirs(self, path=None):
         """Remove a leaf directory and all empty intermediate ones