[PATCH 1 of 3] transaction: only delete journal on successful abort/commit

Henrik Stuart hg at hstuart.dk
Wed Apr 15 15:34:30 CDT 2009


# HG changeset patch
# User Henrik Stuart <henrik.stuart at edlund.dk>
# Date 1239819084 -7200
# Node ID 0bf9ae909f466141fbf74c7e7c6650c45d48c039
# Parent  28a72f620cdef2883d1332a5edcc14b05224fd7b
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.

diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -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"))
 
+        abort_successful = True
         for f, o, ignore in self.entries:
             try:
                 self.opener(f, "a").truncate(o)
             except:
+                abort_successful = False
                 self.report(_("failed to truncate %s\n") % f)
 
         self.entries = []
 
-        self.report(_("rollback completed\n"))
+        if abort_successful:
+            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 = {}


More information about the Mercurial-devel mailing list