posix: tiptoe around tempfile module more delicately
authorAugie Fackler <augie@google.com>
Sun, 19 Mar 2017 01:06:47 -0400
changeset 31506 53575feed7c0
parent 31505 d96d010be4fa
child 31507 4d1dd9cf0dca
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.
mercurial/posix.py
--- a/mercurial/posix.py	Sun Mar 19 01:05:48 2017 -0400
+++ b/mercurial/posix.py	Sun Mar 19 01:06:47 2017 -0400
@@ -230,13 +230,16 @@
         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.