简体   繁体   English

为什么tarfile.extractall默认忽略错误?

[英]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设置为12 (如果只需要打印错误消息,则debug1 )。

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.

相关问题 tarfile.extractall()的Unicode问题(Python 2.7) - Unicode issues with tarfile.extractall() (Python 2.7) 使用 python 解压文件并使用 tarfile.extractall() python 提取某些文件 - Untar files with python and extract certain files with tarfile.extractall() python tarfile.extractall()引发IsADirectoryError,因为存在提取路径 - tarfile.extractall() raises IsADirectoryError because extraction path exists python TarFile.extractall 命令删除目标目录下的文件 - python TarFile.extractall command deletes the files in the target directory 使用tarfile.extractall()解压缩的tar.gz文件夹的其他名称 - Different name of unpacked tar.gz folder using tarfile.extractall() TarFile.extractall() 处理正常,但不创建任何新文件或目录 - TarFile.extractall() processes fine but doesn't create any new files or directories python版本2.4中tarfile模块的“extractall()”的替代方案 - Alternative of “extractall()” of tarfile module in python version 2.4 Tarfile/Zipfile extractall() 更改某些文件的文件名 - Tarfile/Zipfile extractall() changing filename of some files 为什么tarfile模块不允许压缩附加? - Why tarfile module does not allow compressed appending? 使用 python tarfile 备份 postgresql 数据目录。 期望/忽略什么错误 - Backing up a postgresql data dir with python tarfile. What errors to expect / ignore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM