~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hashcache.py

  • Committer: Robert Collins
  • Date: 2005-09-07 10:47:36 UTC
  • mto: (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050907104736-8e592b72108c577d
symlink support updated to work

Show diffs side-by-side

added added

removed removed

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