Mercurial > hg
comparison mercurial/transaction.py @ 8071:9f14b66830a8
transaction: only delete journal on successful abort/commit
This solves that the journal file was always deleted when the transaction
was deleted, no matter whether the abort (rollback) succeeded or not.
Thus, never supporting a hg recover. The journal file is now only deleted
on close (commit) or a successful abort.
author | Henrik Stuart <henrik.stuart@edlund.dk> |
---|---|
date | Thu, 16 Apr 2009 15:41:25 +0200 |
parents | 866d2715aff5 |
children | 46293a0c7e9f |
comparison
equal
deleted
inserted
replaced
8070:28a72f620cde | 8071:9f14b66830a8 |
---|---|
32 | 32 |
33 def __del__(self): | 33 def __del__(self): |
34 if self.journal: | 34 if self.journal: |
35 if self.entries: self.abort() | 35 if self.entries: self.abort() |
36 self.file.close() | 36 self.file.close() |
37 try: os.unlink(self.journal) | |
38 except: pass | |
39 | 37 |
40 def add(self, file, offset, data=None): | 38 def add(self, file, offset, data=None): |
41 if file in self.map: return | 39 if file in self.map: return |
42 self.entries.append((file, offset, data)) | 40 self.entries.append((file, offset, data)) |
43 self.map[file] = len(self.entries) - 1 | 41 self.map[file] = len(self.entries) - 1 |
80 def abort(self): | 78 def abort(self): |
81 if not self.entries: return | 79 if not self.entries: return |
82 | 80 |
83 self.report(_("transaction abort!\n")) | 81 self.report(_("transaction abort!\n")) |
84 | 82 |
83 failed = False | |
85 for f, o, ignore in self.entries: | 84 for f, o, ignore in self.entries: |
86 try: | 85 try: |
87 self.opener(f, "a").truncate(o) | 86 self.opener(f, "a").truncate(o) |
88 except: | 87 except: |
88 failed = True | |
89 self.report(_("failed to truncate %s\n") % f) | 89 self.report(_("failed to truncate %s\n") % f) |
90 | 90 |
91 self.entries = [] | 91 self.entries = [] |
92 | 92 |
93 self.report(_("rollback completed\n")) | 93 if not failed: |
94 self.file.close() | |
95 os.unlink(self.journal) | |
96 self.journal = None | |
97 self.report(_("rollback completed\n")) | |
98 else: | |
99 self.report(_("rollback failed - please run hg recover\n")) | |
94 | 100 |
95 def rollback(opener, file): | 101 def rollback(opener, file): |
96 files = {} | 102 files = {} |
97 for l in open(file).readlines(): | 103 for l in open(file).readlines(): |
98 f, o = l.split('\0') | 104 f, o = l.split('\0') |