~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hashcache.py

  • Committer: Martin Pool
  • Date: 2005-09-05 09:11:03 UTC
  • Revision ID: mbp@sourcefrog.net-20050905091103-1e51e146be0f08b4
- add test for deserialization from a canned XML inventory

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
# TODO: Perhaps return more details on the file to avoid statting it
24
24
# again: nonexistent, file type, size, etc
25
25
 
26
 
# TODO: Perhaps use a Python pickle instead of a text file; might be faster.
27
 
 
28
26
 
29
27
 
30
28
CACHE_HEADER = "### bzr hashcache v5\n"
33
31
 
34
32
from bzrlib.osutils import sha_file
35
33
from bzrlib.trace import mutter, warning
36
 
from bzrlib.atomicfile import AtomicFile
37
 
 
38
34
 
39
35
 
40
36
 
139
135
                del self._cache[path]
140
136
 
141
137
 
 
138
 
142
139
    def get_sha1(self, path):
143
140
        """Return the sha1 of a file.
144
141
        """
188
185
 
189
186
    def write(self):
190
187
        """Write contents of cache to file."""
 
188
        from atomicfile import AtomicFile
 
189
 
191
190
        outf = AtomicFile(self.cache_file_name(), 'wb')
192
191
        try:
193
192
            print >>outf, CACHE_HEADER,
223
222
            inf = file(fn, 'rb', buffering=65000)
224
223
        except IOError, e:
225
224
            mutter("failed to open %s: %s" % (fn, e))
226
 
            # better write it now so it is valid
227
 
            self.needs_write = True
228
225
            return
229
226
 
230
227
 
232
229
        if hdr != CACHE_HEADER:
233
230
            mutter('cache header marker not found at top of %s; discarding cache'
234
231
                   % fn)
235
 
            self.needs_write = True
236
232
            return
237
233
 
238
234
        for l in inf: