Mercurial > public > mercurial-scm > hg-stable
diff mercurial/transaction.py @ 13400:14f3795a5ed7
explicitly close files
Add missing calls to close() to many places where files are
opened. Relying on reference counting to catch them soon-ish is not
portable and fails in environments with a proper GC, such as PyPy.
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Fri, 24 Dec 2010 15:23:01 +0100 |
parents | aade8f133d11 |
children | 19ad316e5be3 |
line wrap: on
line diff
--- a/mercurial/transaction.py Fri Feb 11 22:24:10 2011 +0800 +++ b/mercurial/transaction.py Fri Dec 24 15:23:01 2010 +0100 @@ -27,13 +27,17 @@ for f, o, ignore in entries: if o or not unlink: try: - opener(f, 'a').truncate(o) + fp = opener(f, 'a') + fp.truncate(o) + fp.close() except IOError: report(_("failed to truncate %s\n") % f) raise else: try: - fn = opener(f).name + fp = opener(f) + fn = fp.name + fp.close() os.unlink(fn) except (IOError, OSError), inst: if inst.errno != errno.ENOENT: @@ -169,7 +173,10 @@ def rollback(opener, file, report): entries = [] - for l in open(file).readlines(): + fp = open(file) + lines = fp.readlines() + fp.close() + for l in lines: f, o = l.split('\0') entries.append((f, int(o), None))