Mercurial > hg > mercurial-source
comparison 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 |
comparison
equal
deleted
inserted
replaced
13399:eff102facb15 | 13400:14f3795a5ed7 |
---|---|
25 | 25 |
26 def _playback(journal, report, opener, entries, unlink=True): | 26 def _playback(journal, report, opener, entries, unlink=True): |
27 for f, o, ignore in entries: | 27 for f, o, ignore in entries: |
28 if o or not unlink: | 28 if o or not unlink: |
29 try: | 29 try: |
30 opener(f, 'a').truncate(o) | 30 fp = opener(f, 'a') |
31 fp.truncate(o) | |
32 fp.close() | |
31 except IOError: | 33 except IOError: |
32 report(_("failed to truncate %s\n") % f) | 34 report(_("failed to truncate %s\n") % f) |
33 raise | 35 raise |
34 else: | 36 else: |
35 try: | 37 try: |
36 fn = opener(f).name | 38 fp = opener(f) |
39 fn = fp.name | |
40 fp.close() | |
37 os.unlink(fn) | 41 os.unlink(fn) |
38 except (IOError, OSError), inst: | 42 except (IOError, OSError), inst: |
39 if inst.errno != errno.ENOENT: | 43 if inst.errno != errno.ENOENT: |
40 raise | 44 raise |
41 os.unlink(journal) | 45 os.unlink(journal) |
167 | 171 |
168 | 172 |
169 def rollback(opener, file, report): | 173 def rollback(opener, file, report): |
170 entries = [] | 174 entries = [] |
171 | 175 |
172 for l in open(file).readlines(): | 176 fp = open(file) |
177 lines = fp.readlines() | |
178 fp.close() | |
179 for l in lines: | |
173 f, o = l.split('\0') | 180 f, o = l.split('\0') |
174 entries.append((f, int(o), None)) | 181 entries.append((f, int(o), None)) |
175 | 182 |
176 _playback(file, report, opener, entries) | 183 _playback(file, report, opener, entries) |