comparison mercurial/util.py @ 36783:1fbbb8e83392

py3: read/write plain lock file in binary mode A lock file shouldn't contain '\n', so this isn't a BC.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 04 Mar 2018 18:21:16 -0500
parents 86ba6e3eba4e
children 30742c216abb
comparison
equal deleted inserted replaced
36782:86ba6e3eba4e 36783:1fbbb8e83392
1683 if why.errno == errno.EEXIST: 1683 if why.errno == errno.EEXIST:
1684 raise 1684 raise
1685 except AttributeError: # no symlink in os 1685 except AttributeError: # no symlink in os
1686 pass 1686 pass
1687 1687
1688 ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL) 1688 flags = os.O_CREAT | os.O_WRONLY | os.O_EXCL | getattr(os, 'O_BINARY', 0)
1689 ld = os.open(pathname, flags)
1689 os.write(ld, info) 1690 os.write(ld, info)
1690 os.close(ld) 1691 os.close(ld)
1691 1692
1692 def readlock(pathname): 1693 def readlock(pathname):
1693 try: 1694 try:
1695 except OSError as why: 1696 except OSError as why:
1696 if why.errno not in (errno.EINVAL, errno.ENOSYS): 1697 if why.errno not in (errno.EINVAL, errno.ENOSYS):
1697 raise 1698 raise
1698 except AttributeError: # no symlink in os 1699 except AttributeError: # no symlink in os
1699 pass 1700 pass
1700 fp = posixfile(pathname) 1701 fp = posixfile(pathname, 'rb')
1701 r = fp.read() 1702 r = fp.read()
1702 fp.close() 1703 fp.close()
1703 return r 1704 return r
1704 1705
1705 def fstat(fp): 1706 def fstat(fp):