comparison mercurial/transaction.py @ 43:42177b56b949

Attempt to recover journal automatically
author mpm@selenic.com
date Tue, 10 May 2005 00:32:05 -0800
parents 91f1fa847158
children 589f507bb259
comparison
equal deleted inserted replaced
42:91f1fa847158 43:42177b56b949
20 self.map = {} 20 self.map = {}
21 self.journal = journal 21 self.journal = journal
22 22
23 # abort here if the journal already exists 23 # abort here if the journal already exists
24 if os.path.exists(self.journal): 24 if os.path.exists(self.journal):
25 raise "Journal already exists!" 25 print "journal already exists, recovering"
26 self.recover()
27
26 self.file = open(self.journal, "w") 28 self.file = open(self.journal, "w")
27 29
28 def __del__(self): 30 def __del__(self):
29 if self.entries: self.abort() 31 if self.entries: self.abort()
30 try: os.unlink(self.journal) 32 try: os.unlink(self.journal)
57 59
58 def recover(self): 60 def recover(self):
59 for l in open(self.journal).readlines(): 61 for l in open(self.journal).readlines():
60 f, o = l.split('\0') 62 f, o = l.split('\0')
61 self.opener(f, "a").truncate(int(o)) 63 self.opener(f, "a").truncate(int(o))
64 os.unlink(self.journal)
62 65