/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/hashcache.py

  • Committer: mbp at sourcefrog
  • Date: 2006-07-09 06:28:38 UTC
  • mto: This revision was merged to the branch mainline in revision 1856.
  • Revision ID: mbp@sourcefrog.net-20060709062838-e0482875c25a202f
Use larger time window on hashcache to be safe with fractional times

Show diffs side-by-side

added added

removed removed

Lines of Context:
164
164
            cache_sha1, cache_fp = None, None
165
165
 
166
166
        if cache_fp == file_fp:
 
167
            ## mutter("hashcache hit for %s %r -> %s", path, file_fp, cache_sha1)
 
168
            ## mutter("now = %s", time.time())
167
169
            self.hit_count += 1
168
170
            return cache_sha1
169
171
        
170
172
        self.miss_count += 1
171
173
 
172
 
 
173
174
        mode = file_fp[FP_MODE_COLUMN]
174
175
        if stat.S_ISREG(mode):
175
176
            digest = sha_file(file(abspath, 'rb', buffering=65000))
178
179
        else:
179
180
            raise BzrError("file %r: unknown file stat mode: %o"%(abspath,mode))
180
181
 
181
 
        now = int(time.time())
182
 
        if file_fp[FP_MTIME_COLUMN] >= now or file_fp[FP_CTIME_COLUMN] >= now:
 
182
        # window of 3 seconds to allow for 2s resolution on windows,
 
183
        # unsynchronized file servers, etc.
 
184
        cutoff = int(time.time()) - 3
 
185
        if file_fp[FP_MTIME_COLUMN] >= cutoff \
 
186
                or file_fp[FP_CTIME_COLUMN] >= cutoff:
183
187
            # changed too recently; can't be cached.  we can
184
188
            # return the result and it could possibly be cached
185
189
            # next time.
191
195
            # need to let sufficient time elapse before we may cache this entry
192
196
            # again.  If we didn't do this, then, for example, a very quick 1
193
197
            # byte replacement in the file might go undetected.
194
 
            self.danger_count += 1 
 
198
            ## mutter('%r modified too recently; not caching', path)
 
199
            self.danger_count += 1
195
200
            if cache_fp:
196
201
                self.removed_count += 1
197
202
                self.needs_write = True
198
203
                del self._cache[path]
199
204
        else:
 
205
            ## mutter('%r added to cache: now=%f, mtime=%d, ctime=%d',
 
206
            ##        path, time.time(), file_fp[FP_MTIME_COLUMN],
 
207
            ##        file_fp[FP_CTIME_COLUMN])
200
208
            self.update_count += 1
201
209
            self.needs_write = True
202
210
            self._cache[path] = (digest, file_fp)