# HG changeset patch # User Matt Harbison # Date 1734401897 18000 # Node ID 94fa2543d710ce86fafef211e93831703023d1c5 # Parent 2380fa1158bd4789e4e008839b04656038eeb7d5 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. diff -r 2380fa1158bd -r 94fa2543d710 hgext/remotefilelog/debugcommands.py --- 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) diff -r 2380fa1158bd -r 94fa2543d710 hgext/remotefilelog/shallowutil.py --- 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):