Mercurial > public > mercurial-scm > hg-stable
changeset 52597:94fa2543d710
remotefilelog: replace a few trivial file reads with the `util` function
The one in `shallowutil` is especially important, because the caller may try to
delete the file. That generally doesn't work on Windows when the file is open.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 16 Dec 2024 21:18:17 -0500 |
parents | 2380fa1158bd |
children | 34eb9c877c2e |
files | hgext/remotefilelog/debugcommands.py hgext/remotefilelog/shallowutil.py |
diffstat | 2 files changed, 8 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/remotefilelog/debugcommands.py Mon Dec 16 21:16:30 2024 -0500 +++ b/hgext/remotefilelog/debugcommands.py Mon Dec 16 21:18:17 2024 -0500 @@ -23,6 +23,7 @@ lock as lockmod, pycompat, revlog, + util, ) from mercurial.utils import hashutil from . import ( @@ -227,11 +228,7 @@ def parsefileblob(path, decompress): - f = open(path, "rb") - try: - raw = f.read() - finally: - f.close() + raw = util.readfile(path) if decompress: raw = _decompressblob(raw)
--- a/hgext/remotefilelog/shallowutil.py Mon Dec 16 21:16:30 2024 -0500 +++ b/hgext/remotefilelog/shallowutil.py Mon Dec 16 21:18:17 2024 -0500 @@ -321,18 +321,14 @@ def readfile(path): - f = open(path, 'rb') - try: - result = f.read() + result = util.readfile(path) - # we should never have empty files - if not result: - os.remove(path) - raise IOError(b"empty file: %s" % path) + # we should never have empty files + if not result: + os.remove(path) + raise IOError(b"empty file: %s" % path) - return result - finally: - f.close() + return result def unlinkfile(filepath):