Copy function to get cache path.

This commit is contained in:
Chris Hunt 2019-09-15 16:47:00 -04:00
parent 1f412aca1e
commit 80f092d22a
2 changed files with 15 additions and 0 deletions

View File

@ -547,6 +547,15 @@ class SafeFileCache(FileCache):
assert directory is not None, "Cache directory must not be None."
super(SafeFileCache, self).__init__(directory, use_dir_lock)
def _get_cache_path(self, name):
# type: (str) -> str
# From cachecontrol.caches.file_cache.FileCache._fn, brought into our
# class for backwards-compatibility and to avoid using a non-public
# method.
hashed = FileCache.encode(name)
parts = list(hashed[:5]) + [hashed]
return os.path.join(self.directory, *parts)
def get(self, key):
# type: (str) -> Optional[bytes]
with suppressed_cache_errors():

View File

@ -10,6 +10,7 @@ from tempfile import mkdtemp
import pytest
from mock import Mock, patch
from pip._vendor.cachecontrol.caches import FileCache
import pip
from pip._internal.download import (
@ -549,6 +550,11 @@ class TestSafeFileCache:
cache = SafeFileCache(cache_tmpdir)
cache.delete("foo")
def test_cache_hashes_are_same(self, cache_tmpdir):
cache = SafeFileCache(cache_tmpdir)
key = "test key"
assert cache._get_cache_path(key) == FileCache._fn(cache, key)
class TestPipSession: