~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hashcache.py

  • Committer: Alexander Belchenko
  • Date: 2007-01-30 12:45:50 UTC
  • mto: This revision was merged to the branch mainline in revision 2259.
  • Revision ID: bialix@ukr.net-20070130124550-gggzj7fx8forp9gy
bzr-win32-bdist-postinstall.py: good win98 support

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
128
128
                self.needs_write = True
129
129
                del self._cache[path]
130
130
 
131
 
    def get_sha1(self, path):
 
131
    def get_sha1(self, path, stat_value=None):
132
132
        """Return the sha1 of a file.
133
133
        """
134
134
        abspath = pathjoin(self.root, path)
135
135
        self.stat_count += 1
136
 
        file_fp = self._fingerprint(abspath)
 
136
        file_fp = self._fingerprint(abspath, stat_value)
137
137
        
138
138
        if not file_fp:
139
139
            # not a regular file or not existing
203
203
        """Write contents of cache to file."""
204
204
        outf = AtomicFile(self.cache_file_name(), 'wb', new_mode=self._mode)
205
205
        try:
206
 
            print >>outf, CACHE_HEADER,
 
206
            outf.write(CACHE_HEADER)
207
207
 
208
208
            for path, c  in self._cache.iteritems():
209
209
                assert '//' not in path, path
210
 
                outf.write(path.encode('utf-8'))
211
 
                outf.write('// ')
212
 
                print >>outf, c[0],     # hex sha1
213
 
                for fld in c[1]:
214
 
                    print >>outf, "%d" % fld,
215
 
                print >>outf
 
210
                line_info = [path.encode('utf-8'), '// ', c[0], ' ']
 
211
                line_info.append(' '.join([str(fld) for fld in c[1]]))
 
212
                line_info.append('\n')
 
213
                outf.write(''.join(line_info))
216
214
            outf.commit()
217
215
            self.needs_write = False
218
216
            ## mutter("write hash cache: %s hits=%d misses=%d stat=%d recent=%d updates=%d",
220
218
            ##        self.stat_count,
221
219
            ##        self.danger_count, self.update_count)
222
220
        finally:
223
 
            if not outf.closed:
224
 
                outf.abort()
 
221
            outf.close()
225
222
 
226
223
    def read(self):
227
224
        """Reinstate cache from file.
280
277
        """
281
278
        return int(time.time()) - 3
282
279
           
283
 
    def _fingerprint(self, abspath):
284
 
        try:
285
 
            fs = os.lstat(abspath)
286
 
        except OSError:
287
 
            # might be missing, etc
288
 
            return None
289
 
        if stat.S_ISDIR(fs.st_mode):
 
280
    def _fingerprint(self, abspath, stat_value=None):
 
281
        if stat_value is None:
 
282
            try:
 
283
                stat_value = os.lstat(abspath)
 
284
            except OSError:
 
285
                # might be missing, etc
 
286
                return None
 
287
        if stat.S_ISDIR(stat_value.st_mode):
290
288
            return None
291
289
        # we discard any high precision because it's not reliable; perhaps we
292
290
        # could do better on some systems?
293
 
        return (fs.st_size, long(fs.st_mtime),
294
 
                long(fs.st_ctime), fs.st_ino, fs.st_dev, fs.st_mode)
 
291
        return (stat_value.st_size, long(stat_value.st_mtime),
 
292
                long(stat_value.st_ctime), stat_value.st_ino, 
 
293
                stat_value.st_dev, stat_value.st_mode)