~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hashcache.py

  • Committer: Martin Pool
  • Date: 2005-07-08 02:13:10 UTC
  • Revision ID: mbp@sourcefrog.net-20050708021310-9b783f93430d2983
- add HashCache.write and a simple test for it

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
 
19
19
 
 
20
CACHE_HEADER = "### bzr statcache v5"    
 
21
 
 
22
 
20
23
def _fingerprint(abspath):
21
24
    import os, stat
22
25
 
125
128
 
126
129
            return digest
127
130
 
 
131
 
 
132
 
 
133
    def write(self, cachefn):
 
134
        """Write contents of cache to file."""
 
135
        from atomicfile import AtomicFile
 
136
 
 
137
        outf = AtomicFile(cachefn, 'wb')
 
138
        try:
 
139
            outf.write(CACHE_HEADER + '\n')
 
140
 
 
141
            for path in self.cache_sha1:
 
142
                assert '//' not in path, path
 
143
                outf.write(path.encode('utf-8'))
 
144
                outf.write('// ')
 
145
                print >>outf, self.cache_sha1[path],
 
146
                for fld in self.validator[path]:
 
147
                    print >>outf, fld,
 
148
                print >>outf
 
149
 
 
150
            outf.commit()
 
151
        finally:
 
152
            if not outf.closed:
 
153
                outf.abort()
 
154