Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 38164:aac4be30e250
py3: wrap tempfile.mkstemp() to use bytes path
This patch just flips the default to use a bytes path on Python 3.
ca1cf9b3cce7 is backed out as the bundlepath should be bytes now.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 26 May 2018 12:14:04 +0900 |
parents | 59f1e33f74a6 |
children | 565074cc9ac6 |
comparison
equal
deleted
inserted
replaced
38163:b39958d6b81b | 38164:aac4be30e250 |
---|---|
29 import re as remod | 29 import re as remod |
30 import shutil | 30 import shutil |
31 import socket | 31 import socket |
32 import stat | 32 import stat |
33 import sys | 33 import sys |
34 import tempfile | |
35 import time | 34 import time |
36 import traceback | 35 import traceback |
37 import warnings | 36 import warnings |
38 import zlib | 37 import zlib |
39 | 38 |
1891 | 1890 |
1892 # testfile may be open, so we need a separate file for checking to | 1891 # testfile may be open, so we need a separate file for checking to |
1893 # work around issue2543 (or testfile may get lost on Samba shares) | 1892 # work around issue2543 (or testfile may get lost on Samba shares) |
1894 f1, f2, fp = None, None, None | 1893 f1, f2, fp = None, None, None |
1895 try: | 1894 try: |
1896 fd, f1 = tempfile.mkstemp(prefix='.%s-' % os.path.basename(testfile), | 1895 fd, f1 = pycompat.mkstemp(prefix='.%s-' % os.path.basename(testfile), |
1897 suffix='1~', dir=os.path.dirname(testfile)) | 1896 suffix='1~', dir=os.path.dirname(testfile)) |
1898 os.close(fd) | 1897 os.close(fd) |
1899 f2 = '%s2~' % f1[:-2] | 1898 f2 = '%s2~' % f1[:-2] |
1900 | 1899 |
1901 oslink(f1, f2) | 1900 oslink(f1, f2) |
1937 can use emptyok=True as an optimization. | 1936 can use emptyok=True as an optimization. |
1938 | 1937 |
1939 Returns the name of the temporary file. | 1938 Returns the name of the temporary file. |
1940 """ | 1939 """ |
1941 d, fn = os.path.split(name) | 1940 d, fn = os.path.split(name) |
1942 fd, temp = tempfile.mkstemp(prefix='.%s-' % fn, suffix='~', dir=d) | 1941 fd, temp = pycompat.mkstemp(prefix='.%s-' % fn, suffix='~', dir=d) |
1943 os.close(fd) | 1942 os.close(fd) |
1944 # Temporary files are created with mode 0600, which is usually not | 1943 # Temporary files are created with mode 0600, which is usually not |
1945 # what we want. If the original file already exists, just copy | 1944 # what we want. If the original file already exists, just copy |
1946 # its mode. Otherwise, manually obey umask. | 1945 # its mode. Otherwise, manually obey umask. |
1947 copymode(name, temp, createmode) | 1946 copymode(name, temp, createmode) |