Show More
@@ -694,7 +694,7 b' class revlog(object):' | |||
|
694 | 694 | df.write(d) |
|
695 | 695 | fp.close() |
|
696 | 696 | df.close() |
|
697 | fp = self.opener(self.indexfile, 'w', atomic=True) | |
|
697 | fp = self.opener(self.indexfile, 'w', atomictemp=True) | |
|
698 | 698 | self.version &= ~(REVLOGNGINLINEDATA) |
|
699 | 699 | if self.count(): |
|
700 | 700 | x = self.index[0] |
@@ -708,7 +708,9 b' class revlog(object):' | |||
|
708 | 708 | e = struct.pack(self.indexformat, *x) |
|
709 | 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 | 714 | self.chunkcache = None |
|
713 | 715 | |
|
714 | 716 | def addrevision(self, text, transaction, link, p1=None, p2=None, d=None): |
@@ -431,20 +431,33 b' def opener(base, audit=True):' | |||
|
431 | 431 | os.chmod(temp, st.st_mode) |
|
432 | 432 | return temp |
|
433 | 433 | |
|
434 | class atomicfile(file): | |
|
435 |
"""the file will only be copied |
|
|
436 |
def __init__(self, name, mode |
|
|
434 | class atomictempfile(file): | |
|
435 | """the file will only be copied when rename is called""" | |
|
436 | def __init__(self, name, mode): | |
|
437 | 437 | self.__name = name |
|
438 | 438 | self.temp = mktempcopy(name) |
|
439 | 439 | file.__init__(self, self.temp, mode) |
|
440 |
def |
|
|
440 | def rename(self): | |
|
441 | 441 | if not self.closed: |
|
442 | 442 | file.close(self) |
|
443 | 443 | rename(self.temp, self.__name) |
|
444 | 444 | def __del__(self): |
|
445 |
self.close |
|
|
445 | if not self.closed: | |
|
446 | try: | |
|
447 | os.unlink(self.temp) | |
|
448 | except: pass | |
|
449 | file.close(self) | |
|
446 | 450 | |
|
447 | def o(path, mode="r", text=False, atomic=False): | |
|
451 | class atomicfile(atomictempfile): | |
|
452 | """the file will only be copied on close""" | |
|
453 | def __init__(self, name, mode): | |
|
454 | atomictempfile.__init__(self, name, mode) | |
|
455 | def close(self): | |
|
456 | self.rename() | |
|
457 | def __del__(self): | |
|
458 | self.rename() | |
|
459 | ||
|
460 | def o(path, mode="r", text=False, atomic=False, atomictemp=False): | |
|
448 | 461 | if audit_p: |
|
449 | 462 | audit_path(path) |
|
450 | 463 | f = os.path.join(p, path) |
@@ -462,6 +475,8 b' def opener(base, audit=True):' | |||
|
462 | 475 | else: |
|
463 | 476 | if atomic: |
|
464 | 477 | return atomicfile(f, mode) |
|
478 | elif atomictemp: | |
|
479 | return atomictempfile(f, mode) | |
|
465 | 480 | if nlink > 1: |
|
466 | 481 | rename(mktempcopy(f), f) |
|
467 | 482 | return file(f, mode) |
General Comments 0
You need to be logged in to leave comments.
Login now