Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/common.py @ 52576:08612516d436
hgweb: replace a trivial file read with the `util` function
Not sure why there's an `os.stat()` here- I'd expect any errors that it might
hit to also be hit by attempting to open the file in read mode. It goes all the
way back to a9343f9d7365 in 2006, and mentions making things more secure, so
I'll leave it be for now.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Tue, 17 Dec 2024 01:10:28 -0500 |
parents | c9baa3541b20 |
children |
comparison
equal
deleted
inserted
replaced
52575:f106d0e629e5 | 52576:08612516d436 |
---|---|
217 mimetypes.guess_type(pycompat.fsdecode(fpath))[0] or r"text/plain" | 217 mimetypes.guess_type(pycompat.fsdecode(fpath))[0] or r"text/plain" |
218 ) | 218 ) |
219 path = os.path.join(directory, fpath) | 219 path = os.path.join(directory, fpath) |
220 try: | 220 try: |
221 os.stat(path) | 221 os.stat(path) |
222 with open(path, 'rb') as fh: | 222 data = util.readfile(path) |
223 data = fh.read() | |
224 except TypeError: | 223 except TypeError: |
225 raise ErrorResponse(HTTP_SERVER_ERROR, b'illegal filename') | 224 raise ErrorResponse(HTTP_SERVER_ERROR, b'illegal filename') |
226 except OSError as err: | 225 except OSError as err: |
227 if err.errno == errno.ENOENT: | 226 if err.errno == errno.ENOENT: |
228 raise ErrorResponse(HTTP_NOT_FOUND) | 227 raise ErrorResponse(HTTP_NOT_FOUND) |