[PATCH 2 of 3] hgweb: replace file I/O with util.readfile
Bryan O'Sullivan
bos at serpentine.com
Tue Jan 12 18:21:02 CST 2016
# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1452643932 28800
# Tue Jan 12 16:12:12 2016 -0800
# Node ID bdda0258d3884e81b9b80ca71669934d237be54c
# Parent dc4b31f3489f5c7d574c8bf2e1f0d96a0564fd50
hgweb: replace file I/O with util.readfile
diff --git a/mercurial/hgweb/common.py b/mercurial/hgweb/common.py
--- a/mercurial/hgweb/common.py
+++ b/mercurial/hgweb/common.py
@@ -146,12 +146,8 @@ def staticfile(directory, fname, req):
if os.path.exists(path):
break
try:
- os.stat(path)
ct = mimetypes.guess_type(path)[0] or "text/plain"
- fp = open(path, 'rb')
- data = fp.read()
- fp.close()
- req.respond(HTTP_OK, ct, body=data)
+ req.respond(HTTP_OK, ct, body=util.readfile(path))
except TypeError:
raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename')
except OSError as err:
More information about the Mercurial-devel
mailing list