[PATCH] transaction: only delete journal on successful abort/commit [revised]

Henrik Stuart hg at hstuart.dk
Thu Apr 16 08:43:09 CDT 2009


# HG changeset patch
# User Henrik Stuart <henrik.stuart at edlund.dk>
# Date 1239889285 -7200
# Node ID 9f14b66830a81a60ca980feb1d0d625d09b88a1a
# 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"))
 
+        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 = {}


More information about the Mercurial-devel mailing list