Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.py @ 2076:d007df6daf8e
Create an atomic opener that does not automatically rename on close
The revlog.checkinlinesize() uses an atomic opener to replace the
index file after converting it from inline to traditional .i and .d
files. If this operation is interrupted, the atomic file class can
overwrite a valid file with a partially written one.
This patch introduces an atomic opener that does not automatically
replace the destination file with the tempfile. This way
an interrupted checkinlinesize() call turns into a noop.
author | mason@suse.com |
---|---|
date | Tue, 04 Apr 2006 16:38:44 -0400 |
parents | 343aeefb553b |
children | 4d0700ae0991 |
comparison
equal
deleted
inserted
replaced
2075:343aeefb553b | 2076:d007df6daf8e |
---|---|
692 fp.seek(start) | 692 fp.seek(start) |
693 d = fp.read(length) | 693 d = fp.read(length) |
694 df.write(d) | 694 df.write(d) |
695 fp.close() | 695 fp.close() |
696 df.close() | 696 df.close() |
697 fp = self.opener(self.indexfile, 'w', atomic=True) | 697 fp = self.opener(self.indexfile, 'w', atomictemp=True) |
698 self.version &= ~(REVLOGNGINLINEDATA) | 698 self.version &= ~(REVLOGNGINLINEDATA) |
699 if self.count(): | 699 if self.count(): |
700 x = self.index[0] | 700 x = self.index[0] |
701 e = struct.pack(self.indexformat, *x)[4:] | 701 e = struct.pack(self.indexformat, *x)[4:] |
702 l = struct.pack(versionformat, self.version) | 702 l = struct.pack(versionformat, self.version) |
706 for i in xrange(1, self.count()): | 706 for i in xrange(1, self.count()): |
707 x = self.index[i] | 707 x = self.index[i] |
708 e = struct.pack(self.indexformat, *x) | 708 e = struct.pack(self.indexformat, *x) |
709 fp.write(e) | 709 fp.write(e) |
710 | 710 |
711 fp.close() | 711 # if we don't call rename, the temp file will never replace the |
712 # real index | |
713 fp.rename() | |
712 self.chunkcache = None | 714 self.chunkcache = None |
713 | 715 |
714 def addrevision(self, text, transaction, link, p1=None, p2=None, d=None): | 716 def addrevision(self, text, transaction, link, p1=None, p2=None, d=None): |
715 """add a revision to the log | 717 """add a revision to the log |
716 | 718 |