Mercurial > hg
comparison mercurial/util.py @ 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 | 6d3cc2a982f3 |
children | 45aef5ddcdbe 20cf545b4725 |
comparison
equal
deleted
inserted
replaced
2236:d7f866789d7e | 2237:4a069064a39b |
---|---|
683 | 683 |
684 def mktempcopy(name): | 684 def mktempcopy(name): |
685 d, fn = os.path.split(name) | 685 d, fn = os.path.split(name) |
686 fd, temp = tempfile.mkstemp(prefix='.%s-' % fn, dir=d) | 686 fd, temp = tempfile.mkstemp(prefix='.%s-' % fn, dir=d) |
687 os.close(fd) | 687 os.close(fd) |
688 fp = posixfile(temp, "wb") | 688 ofp = posixfile(temp, "wb") |
689 try: | 689 try: |
690 try: | 690 try: |
691 s = posixfile(name, "rb").read() | 691 ifp = posixfile(name, "rb") |
692 except IOError, inst: | 692 except IOError, inst: |
693 if not getattr(inst, 'filename', None): | 693 if not getattr(inst, 'filename', None): |
694 inst.filename = name | 694 inst.filename = name |
695 raise | 695 raise |
696 fp.write(s) | 696 for chunk in filechunkiter(ifp): |
697 ofp.write(chunk) | |
698 ifp.close() | |
699 ofp.close() | |
697 except: | 700 except: |
698 try: os.unlink(temp) | 701 try: os.unlink(temp) |
699 except: pass | 702 except: pass |
700 raise | 703 raise |
701 fp.close() | |
702 st = os.lstat(name) | 704 st = os.lstat(name) |
703 os.chmod(temp, st.st_mode) | 705 os.chmod(temp, st.st_mode) |
704 return temp | 706 return temp |
705 | 707 |
706 class atomictempfile(posixfile): | 708 class atomictempfile(posixfile): |