Mercurial > public > mercurial-scm > hg
diff mercurial/posix.py @ 38166:cc9aa88792fe
py3: wrap tempfile.NamedTemporaryFile() to return bytes fp.name
Unlike its name, tempfile.NamedTemporaryFile is not a class, so I renamed
the pycompat version to look like a plain function.
Since temp.name uses in the infinitepush extension aren't bytes-safe, this
patch leaves them unmodified. Another weird thing is tempfile.mktemp(),
which does not accept bytes suffix nor prefix. Sigh.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 26 May 2018 12:38:07 +0900 |
parents | aac4be30e250 |
children | a4aa77b84efd |
line wrap: on
line diff
--- a/mercurial/posix.py Sat May 26 12:20:36 2018 +0900 +++ b/mercurial/posix.py Sat May 26 12:38:07 2018 +0900 @@ -249,16 +249,15 @@ else: checkdir = path cachedir = None - fscheckdir = pycompat.fsdecode(checkdir) - name = tempfile.mktemp(dir=fscheckdir, + name = tempfile.mktemp(dir=pycompat.fsdecode(checkdir), prefix=r'checklink-') name = pycompat.fsencode(name) try: fd = None if cachedir is None: - fd = tempfile.NamedTemporaryFile(dir=fscheckdir, - prefix=r'hg-checklink-') - target = pycompat.fsencode(os.path.basename(fd.name)) + fd = pycompat.namedtempfile(dir=checkdir, + prefix='hg-checklink-') + target = os.path.basename(fd.name) else: # create a fixed file to link to; doesn't matter if it # already exists.