[英]Why does tarfile.extractall ignore errors by default?
Python's tarfile module ignores errors during extraction by default , unless errorlevel
is set to either 1
or 2
(or debug
to 1
if only error messages need to be printed). 默认情况下 ,Python的tarfile模块会在提取期间忽略错误,除非将
errorlevel
设置为1
或2
(如果只需要打印错误消息,则debug
为1
)。
Try doing a mkdir /tmp/foo && sudo chown root /tmp/foo && chmod aw /tmp/foo
and using tarfile
to extract a .tar.gz file over /tmp/foo
-- you will see that your Python code threw no exceptions at all. 尝试做一个
mkdir /tmp/foo && sudo chown root /tmp/foo && chmod aw /tmp/foo
并使用tarfile
在/tmp/foo
上提取.tar.gz文件 - 你会发现你的Python代码没有丢弃例外。 The files would not have been extracted over /tmp/foo
which still is an empty directory. 这些文件不会被提取过
/tmp/foo
仍然是一个空目录。
Why this behavior? 为什么会这样? Who/what benefits from this default behavior?
谁/什么从这个默认行为中受益? In other words, just who/what would want to ignore, say, permissions errors when decompressing a tarfile?
换句话说,在解压缩tarfile时,只有谁/什么会想要忽略权限错误?
FWIW, this nasty behavior is will be changed in Python 2.7 and 3.2. FWIW,这个令人讨厌的行为将在Python 2.7和3.2中改变。 http://svn.python.org/view?view=rev&revision=76780 Apparently the reason for ignoring the errors before was to be more like GNU tar, which ignores errors.
http://svn.python.org/view?view=rev&revision=76780显然忽略之前错误的原因更像是GNU tar,它忽略了错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.