comparison mercurial/posix.py @ 38199: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
comparison
equal deleted inserted replaced
38198:2ce60954b1b7 38199:cc9aa88792fe
247 if os.path.isdir(cachedir): 247 if os.path.isdir(cachedir):
248 checkdir = cachedir 248 checkdir = cachedir
249 else: 249 else:
250 checkdir = path 250 checkdir = path
251 cachedir = None 251 cachedir = None
252 fscheckdir = pycompat.fsdecode(checkdir) 252 name = tempfile.mktemp(dir=pycompat.fsdecode(checkdir),
253 name = tempfile.mktemp(dir=fscheckdir,
254 prefix=r'checklink-') 253 prefix=r'checklink-')
255 name = pycompat.fsencode(name) 254 name = pycompat.fsencode(name)
256 try: 255 try:
257 fd = None 256 fd = None
258 if cachedir is None: 257 if cachedir is None:
259 fd = tempfile.NamedTemporaryFile(dir=fscheckdir, 258 fd = pycompat.namedtempfile(dir=checkdir,
260 prefix=r'hg-checklink-') 259 prefix='hg-checklink-')
261 target = pycompat.fsencode(os.path.basename(fd.name)) 260 target = os.path.basename(fd.name)
262 else: 261 else:
263 # create a fixed file to link to; doesn't matter if it 262 # create a fixed file to link to; doesn't matter if it
264 # already exists. 263 # already exists.
265 target = 'checklink-target' 264 target = 'checklink-target'
266 try: 265 try: