~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/cache.py

  • Committer: Martin Pool
  • Date: 2005-05-10 06:00:59 UTC
  • Revision ID: mbp@sourcefrog.net-20050510060059-bae67a465325f650
- Use AtomicFile to update statcache.
- New closed property on AtomicFile

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from binascii import b2a_qp, a2b_qp
19
19
 
20
20
from trace import mutter
 
21
from errors import BzrError
21
22
 
22
23
 
23
24
"""File stat cache to speed up tree comparisons.
69
70
 
70
71
 
71
72
def write_cache(branch, entry_iter):
72
 
    outf = branch.controlfile('work-cache.tmp', 'wt')
73
 
    for entry in entry_iter:
74
 
        outf.write(entry[0] + ' ' + entry[1] + ' ')
75
 
        outf.write(b2a_qp(entry[2], True))
76
 
        outf.write(' %d %d %d %d %d\n' % entry[3:])
77
 
        
78
 
    outf.close()
79
 
    os.rename(branch.controlfilename('work-cache.tmp'),
80
 
              branch.controlfilename('work-cache'))
 
73
    from atomicfile import AtomicFile
 
74
    
 
75
    outf = AtomicFile(branch.controlfilename('work-cache.tmp'), 'wt')
 
76
    try:
 
77
        for entry in entry_iter:
 
78
            outf.write(entry[0] + ' ' + entry[1] + ' ')
 
79
            outf.write(b2a_qp(entry[2], True))
 
80
            outf.write(' %d %d %d %d %d\n' % entry[3:])
81
81
 
 
82
        outf.commit()
 
83
    finally:
 
84
        if not outf.closed:
 
85
            outf.abort()
82
86
        
83
87
        
84
88
def load_cache(branch):