Mercurial > hg
changeset 2237:4a069064a39b
reduce memory used by util.opener when making a temp copy of a file.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Tue, 09 May 2006 11:12:45 -0700 |
parents | d7f866789d7e |
children | 25af3f17ce95 |
files | mercurial/util.py |
diffstat | 1 files changed, 6 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/util.py Tue May 09 11:08:06 2006 -0700 +++ b/mercurial/util.py Tue May 09 11:12:45 2006 -0700 @@ -685,20 +685,22 @@ d, fn = os.path.split(name) fd, temp = tempfile.mkstemp(prefix='.%s-' % fn, dir=d) os.close(fd) - fp = posixfile(temp, "wb") + ofp = posixfile(temp, "wb") try: try: - s = posixfile(name, "rb").read() + ifp = posixfile(name, "rb") except IOError, inst: if not getattr(inst, 'filename', None): inst.filename = name raise - fp.write(s) + for chunk in filechunkiter(ifp): + ofp.write(chunk) + ifp.close() + ofp.close() except: try: os.unlink(temp) except: pass raise - fp.close() st = os.lstat(name) os.chmod(temp, st.st_mode) return temp