~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hashcache.py

  • Committer: Robert Collins
  • Date: 2005-09-29 02:01:49 UTC
  • Revision ID: robertc@robertcollins.net-20050929020149-1ff16722c6a01b2c
reenable remotebranch tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
CACHE_HEADER = "### bzr hashcache v5\n"
31
31
 
32
32
import os, stat, time
33
 
import sha
34
33
 
35
34
from bzrlib.osutils import sha_file
36
35
from bzrlib.trace import mutter, warning
37
36
from bzrlib.atomicfile import AtomicFile
38
37
 
39
38
 
40
 
FP_MODE_COLUMN = 5
 
39
 
41
40
 
42
41
def _fingerprint(abspath):
43
42
    try:
52
51
    # we discard any high precision because it's not reliable; perhaps we
53
52
    # could do better on some systems?
54
53
    return (fs.st_size, long(fs.st_mtime),
55
 
            long(fs.st_ctime), fs.st_ino, fs.st_dev, fs.st_mode)
 
54
            long(fs.st_ctime), fs.st_ino, fs.st_dev)
56
55
 
57
56
 
58
57
class HashCache(object):
165
164
            return cache_sha1
166
165
        
167
166
        self.miss_count += 1
168
 
 
169
 
 
170
 
        mode = file_fp[FP_MODE_COLUMN]
171
 
        if stat.S_ISREG(mode):
172
 
            digest = sha_file(file(abspath, 'rb', buffering=65000))
173
 
        elif stat.S_ISLNK(mode):
174
 
            link_target = os.readlink(abspath)
175
 
            digest = sha.new(os.readlink(abspath)).hexdigest()
176
 
        else:
177
 
            raise BzrError("file %r: unknown file stat mode: %o"%(abspath,mode))
 
167
        digest = sha_file(file(abspath, 'rb', buffering=65000))
178
168
 
179
169
        now = int(time.time())
180
170
        if file_fp[1] >= now or file_fp[2] >= now:
190
180
            self.update_count += 1
191
181
            self.needs_write = True
192
182
            self._cache[path] = (digest, file_fp)
 
183
        
193
184
        return digest
194
185
        
 
186
 
 
187
 
 
188
 
195
189
    def write(self):
196
190
        """Write contents of cache to file."""
197
191
        outf = AtomicFile(self.cache_file_name(), 'wb')
250
244
 
251
245
            pos += 3
252
246
            fields = l[pos:].split(' ')
253
 
            if len(fields) != 7:
 
247
            if len(fields) != 6:
254
248
                warning("bad line in hashcache: %r" % l)
255
249
                continue
256
250