/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: Alexander Belchenko
  • Date: 2007-10-26 21:49:15 UTC
  • mto: (2947.4.2 0.92)
  • mto: This revision was merged to the branch mainline in revision 2971.
  • Revision ID: bialix@ukr.net-20071026214915-5eacqh9k2ps6jagj
windows python-based installer: shortcut for uninstall action

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
83
83
    def __init__(self, root, cache_file_name, mode=None):
84
84
        """Create a hash cache in base dir, and set the file mode to mode."""
85
85
        self.root = safe_unicode(root)
 
86
        self.root_utf8 = self.root.encode('utf8') # where is the filesystem encoding ?
86
87
        self.hit_count = 0
87
88
        self.miss_count = 0
88
89
        self.stat_count = 0
128
129
                self.needs_write = True
129
130
                del self._cache[path]
130
131
 
131
 
    def get_sha1(self, path):
 
132
    def get_sha1(self, path, stat_value=None):
132
133
        """Return the sha1 of a file.
133
134
        """
134
 
        abspath = pathjoin(self.root, path)
 
135
        if path.__class__ is str:
 
136
            abspath = pathjoin(self.root_utf8, path)
 
137
        else:
 
138
            abspath = pathjoin(self.root, path)
135
139
        self.stat_count += 1
136
 
        file_fp = self._fingerprint(abspath)
 
140
        file_fp = self._fingerprint(abspath, stat_value)
137
141
        
138
142
        if not file_fp:
139
143
            # not a regular file or not existing
277
281
        """
278
282
        return int(time.time()) - 3
279
283
           
280
 
    def _fingerprint(self, abspath):
281
 
        try:
282
 
            fs = os.lstat(abspath)
283
 
        except OSError:
284
 
            # might be missing, etc
285
 
            return None
286
 
        if stat.S_ISDIR(fs.st_mode):
 
284
    def _fingerprint(self, abspath, stat_value=None):
 
285
        if stat_value is None:
 
286
            try:
 
287
                stat_value = os.lstat(abspath)
 
288
            except OSError:
 
289
                # might be missing, etc
 
290
                return None
 
291
        if stat.S_ISDIR(stat_value.st_mode):
287
292
            return None
288
293
        # we discard any high precision because it's not reliable; perhaps we
289
294
        # could do better on some systems?
290
 
        return (fs.st_size, long(fs.st_mtime),
291
 
                long(fs.st_ctime), fs.st_ino, fs.st_dev, fs.st_mode)
 
295
        return (stat_value.st_size, long(stat_value.st_mtime),
 
296
                long(stat_value.st_ctime), stat_value.st_ino, 
 
297
                stat_value.st_dev, stat_value.st_mode)