Python tarfile module overwrites existing files during extraction - how to disable it?
Question
Is there a way prevent tarfile.extractall
(API) from overwriting existing files? By "prevent" I mean ideally raising an exception when an overwrite is about to happen. The current behavior is to silently overwrite the files.
Solution
You could check result of tarfile.getnames
against the existing files and raise your error.
OTHER TIPS
Have you tried setting tarfile.errorlevel
to 2? That will cause non-fatal errors to be raised. I'm assuming an overwrite falls in that category.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow