Patchwork [06,of,10,py3] posix: tiptoe around tempfile module more delicately

login
register
mail settings
Submitter Augie Fackler
Date March 19, 2017, 6:26 p.m.
Message ID <b9f5a75f7ca098d588fe.1489947979@imladris.local>
Download mbox | patch
Permalink /patch/19456/
State Accepted
Headers show

Comments

Augie Fackler - March 19, 2017, 6:26 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1489900007 14400
#      Sun Mar 19 01:06:47 2017 -0400
# Node ID b9f5a75f7ca098d588feea0737fdb0ac1162cb41
# Parent  5ac56851f3529c159555738967289b22fc3f622e
posix: tiptoe around tempfile module more delicately

Some of the values inside the tempfile calls here are str on Python 3,
so we've got to pass str in. Use fsdecode to work around the issue.

Patch

diff --git a/mercurial/posix.py b/mercurial/posix.py
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -230,13 +230,16 @@  def checklink(path):
         else:
             checkdir = path
             cachedir = None
-        name = tempfile.mktemp(dir=checkdir, prefix='checklink-')
+        fscheckdir = pycompat.fsdecode(checkdir)
+        name = tempfile.mktemp(dir=fscheckdir,
+                               prefix=r'checklink-')
+        name = pycompat.fsencode(name)
         try:
             fd = None
             if cachedir is None:
-                fd = tempfile.NamedTemporaryFile(dir=checkdir,
-                                                 prefix='hg-checklink-')
-                target = os.path.basename(fd.name)
+                fd = tempfile.NamedTemporaryFile(dir=fscheckdir,
+                                                 prefix=r'hg-checklink-')
+                target = pycompat.fsencode(os.path.basename(fd.name))
             else:
                 # create a fixed file to link to; doesn't matter if it
                 # already exists.