Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 39910:4017968f0a1d
util: use a context manager in readlock()
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Fri, 28 Sep 2018 22:18:45 -0400 |
parents | 5fe0b880200e |
children | e2697acd9381 |
comparison
equal
deleted
inserted
replaced
39909:5fe0b880200e | 39910:4017968f0a1d |
---|---|
1846 except OSError as why: | 1846 except OSError as why: |
1847 if why.errno not in (errno.EINVAL, errno.ENOSYS): | 1847 if why.errno not in (errno.EINVAL, errno.ENOSYS): |
1848 raise | 1848 raise |
1849 except AttributeError: # no symlink in os | 1849 except AttributeError: # no symlink in os |
1850 pass | 1850 pass |
1851 fp = posixfile(pathname, 'rb') | 1851 with posixfile(pathname, 'rb') as fp: |
1852 r = fp.read() | 1852 return fp.read() |
1853 fp.close() | |
1854 return r | |
1855 | 1853 |
1856 def fstat(fp): | 1854 def fstat(fp): |
1857 '''stat file object that may not have fileno method.''' | 1855 '''stat file object that may not have fileno method.''' |
1858 try: | 1856 try: |
1859 return os.fstat(fp.fileno()) | 1857 return os.fstat(fp.fileno()) |