~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hashcache.py

[merge] aaron, various fixes

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
33
34
 
34
35
from bzrlib.osutils import sha_file
35
36
from bzrlib.trace import mutter, warning
36
37
from bzrlib.atomicfile import AtomicFile
37
38
 
38
39
 
39
 
 
 
40
FP_MODE_COLUMN = 5
40
41
 
41
42
def _fingerprint(abspath):
42
43
    try:
51
52
    # we discard any high precision because it's not reliable; perhaps we
52
53
    # could do better on some systems?
53
54
    return (fs.st_size, long(fs.st_mtime),
54
 
            long(fs.st_ctime), fs.st_ino, fs.st_dev)
 
55
            long(fs.st_ctime), fs.st_ino, fs.st_dev, fs.st_mode)
55
56
 
56
57
 
57
58
class HashCache(object):
100
101
        self.update_count = 0
101
102
        self._cache = {}
102
103
 
103
 
 
104
104
    def cache_file_name(self):
 
105
        # FIXME: duplicate path logic here, this should be 
 
106
        # something like 'branch.controlfile'.
105
107
        return os.sep.join([self.basedir, '.bzr', 'stat-cache'])
106
108
 
107
 
 
108
 
 
109
 
 
110
109
    def clear(self):
111
110
        """Discard all cached information.
112
111
 
164
163
            return cache_sha1
165
164
        
166
165
        self.miss_count += 1
167
 
        digest = sha_file(file(abspath, 'rb', buffering=65000))
 
166
 
 
167
 
 
168
        mode = file_fp[FP_MODE_COLUMN]
 
169
        if stat.S_ISREG(mode):
 
170
            digest = sha_file(file(abspath, 'rb', buffering=65000))
 
171
        elif stat.S_ISLNK(mode):
 
172
            link_target = os.readlink(abspath)
 
173
            digest = sha.new(os.readlink(abspath)).hexdigest()
 
174
        else:
 
175
            raise BzrError("file %r: unknown file stat mode: %o"%(abspath,mode))
168
176
 
169
177
        now = int(time.time())
170
178
        if file_fp[1] >= now or file_fp[2] >= now:
180
188
            self.update_count += 1
181
189
            self.needs_write = True
182
190
            self._cache[path] = (digest, file_fp)
183
 
        
184
191
        return digest
185
192
        
186
 
 
187
 
 
188
 
 
189
193
    def write(self):
190
194
        """Write contents of cache to file."""
191
195
        outf = AtomicFile(self.cache_file_name(), 'wb')
244
248
 
245
249
            pos += 3
246
250
            fields = l[pos:].split(' ')
247
 
            if len(fields) != 6:
 
251
            if len(fields) != 7:
248
252
                warning("bad line in hashcache: %r" % l)
249
253
                continue
250
254