Part of bzrlib.hashcache View In Hierarchy
Known subclasses: bzrlib.tests.test_hashcache.FakeHashCache
Cache for looking up file SHA-1.
Files are considered to match the cached value if the fingerprint of the file has not changed. This includes its mtime, ctime, device number, inode number, and size. This should catch modifications or replacement of the file by a new one.
This may not catch modifications that do not change the file's size and that occur within the resolution window of the timestamps. To handle this we specifically do not cache files which have changed since the start of the present second, since they could undetectably change again.
This scheme may fail if the machine's clock steps backwards. Don't do that.
This does not canonicalize the paths passed in; that should be done by the caller.
Method | __init__ | Create a hash cache in base dir, and set the file mode to mode. |
Method | cache_file_name | Undocumented |
Method | clear | Discard all cached information. |
Method | scan | Scan all files and remove entries where the cache entry is obsolete. |
Method | get_sha1 | Return the sha1 of a file. |
Method | write | Write contents of cache to file. |
Method | read | Reinstate cache from file. |
Method | _really_sha1_file | Calculate the SHA1 of a file by reading the full text |
Method | _cutoff_time | Return cutoff time. |
Method | _fingerprint | Undocumented |
Parameters | content_filter_stack_provider | a function that takes a path (relative to the top of the tree) and a file-id as parameters and returns a stack of ContentFilters. If None, no content filtering is performed. |
Obsolete entries are those where the file has been modified or deleted since the entry was inserted.
Overwrites existing cache.
If the cache file has the wrong version marker, this just clears the cache.
Files modified more recently than this time are at risk of being undetectably modified and so can't be cached.