changeset 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 28a72f620cde
children ecf7795479d5
files mercurial/transaction.py
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/transaction.py	Tue Apr 14 18:16:04 2009 +0200
+++ b/mercurial/transaction.py	Thu Apr 16 15:41:25 2009 +0200
@@ -34,8 +34,6 @@
         if self.journal:
             if self.entries: self.abort()
             self.file.close()
-            try: os.unlink(self.journal)
-            except: pass
 
     def add(self, file, offset, data=None):
         if file in self.map: return
@@ -82,15 +80,23 @@
 
         self.report(_("transaction abort!\n"))
 
+        failed = False
         for f, o, ignore in self.entries:
             try:
                 self.opener(f, "a").truncate(o)
             except:
+                failed = True
                 self.report(_("failed to truncate %s\n") % f)
 
         self.entries = []
 
-        self.report(_("rollback completed\n"))
+        if not failed:
+            self.file.close()
+            os.unlink(self.journal)
+            self.journal = None
+            self.report(_("rollback completed\n"))
+        else:
+            self.report(_("rollback failed - please run hg recover\n"))
 
 def rollback(opener, file):
     files = {}