Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
Python_Packaging_Authority
pip
提交
76e1f1b5
P
pip
项目概览
镜像
/
Python_Packaging_Authority
/
pip
12 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
pip
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
76e1f1b5
编写于
8月 08, 2019
作者:
C
Christopher Hunt
提交者:
Chris Jerdonek
8月 08, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify file cache. (#6845)
上级
c9a043bf
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
49 deletion
+31
-49
src/pip/_internal/download.py
src/pip/_internal/download.py
+31
-49
未找到文件。
src/pip/_internal/download.py
浏览文件 @
76e1f1b5
...
...
@@ -10,6 +10,7 @@ import platform
import
re
import
shutil
import
sys
from
contextlib
import
contextmanager
from
pip._vendor
import
requests
,
urllib3
from
pip._vendor.cachecontrol
import
CacheControlAdapter
...
...
@@ -482,70 +483,38 @@ class LocalFSAdapter(BaseAdapter):
pass
@
contextmanager
def
suppressed_cache_errors
():
"""If we can't access the cache then we can just skip caching and process
requests as if caching wasn't enabled.
"""
try
:
yield
except
(
LockError
,
OSError
,
IOError
):
pass
class
SafeFileCache
(
FileCache
):
"""
A file based cache which is safe to use even when the target directory may
not be accessible or writable.
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
SafeFileCache
,
self
).
__init__
(
*
args
,
**
kwargs
)
# Check to ensure that the directory containing our cache directory
# is owned by the user current executing pip. If it does not exist
# we will check the parent directory until we find one that does exist.
# If it is not owned by the user executing pip then we will disable
# the cache and log a warning.
if
not
check_path_owner
(
self
.
directory
):
logger
.
warning
(
"The directory '%s' or its parent directory is not owned by "
"the current user and the cache has been disabled. Please "
"check the permissions and owner of that directory. If "
"executing pip with sudo, you may want sudo's -H flag."
,
self
.
directory
,
)
# Set our directory to None to disable the Cache
self
.
directory
=
None
def
__init__
(
self
,
directory
,
*
args
,
**
kwargs
):
assert
directory
is
not
None
,
"Cache directory must not be None."
super
(
SafeFileCache
,
self
).
__init__
(
directory
,
*
args
,
**
kwargs
)
def
get
(
self
,
*
args
,
**
kwargs
):
# If we don't have a directory, then the cache should be a no-op.
if
self
.
directory
is
None
:
return
try
:
with
suppressed_cache_errors
():
return
super
(
SafeFileCache
,
self
).
get
(
*
args
,
**
kwargs
)
except
(
LockError
,
OSError
,
IOError
):
# We intentionally silence this error, if we can't access the cache
# then we can just skip caching and process the request as if
# caching wasn't enabled.
pass
def
set
(
self
,
*
args
,
**
kwargs
):
# If we don't have a directory, then the cache should be a no-op.
if
self
.
directory
is
None
:
return
try
:
with
suppressed_cache_errors
():
return
super
(
SafeFileCache
,
self
).
set
(
*
args
,
**
kwargs
)
except
(
LockError
,
OSError
,
IOError
):
# We intentionally silence this error, if we can't access the cache
# then we can just skip caching and process the request as if
# caching wasn't enabled.
pass
def
delete
(
self
,
*
args
,
**
kwargs
):
# If we don't have a directory, then the cache should be a no-op.
if
self
.
directory
is
None
:
return
try
:
with
suppressed_cache_errors
():
return
super
(
SafeFileCache
,
self
).
delete
(
*
args
,
**
kwargs
)
except
(
LockError
,
OSError
,
IOError
):
# We intentionally silence this error, if we can't access the cache
# then we can just skip caching and process the request as if
# caching wasn't enabled.
pass
class
InsecureHTTPAdapter
(
HTTPAdapter
):
...
...
@@ -593,6 +562,19 @@ class PipSession(requests.Session):
backoff_factor
=
0.25
,
)
# Check to ensure that the directory containing our cache directory
# is owned by the user current executing pip. If it does not exist
# we will check the parent directory until we find one that does exist.
if
cache
and
not
check_path_owner
(
cache
):
logger
.
warning
(
"The directory '%s' or its parent directory is not owned by "
"the current user and the cache has been disabled. Please "
"check the permissions and owner of that directory. If "
"executing pip with sudo, you may want sudo's -H flag."
,
cache
,
)
cache
=
None
# We want to _only_ cache responses on securely fetched origins. We do
# this because we can't validate the response of an insecurely fetched
# origin, and we don't want someone to be able to poison the cache and
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录