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.
views:
36answers:
2
+2
A:
You could check result of tarfile.getnames
against the existing files and raise your error.
SilentGhost
2010-10-12 17:52:44
A:
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.
Karl Bielefeldt
2010-10-12 17:55:55
docs mention only `extract`, does it also work for `extractall`?
SilentGhost
2010-10-12 17:57:32
just tested it, it doesn't work for `extractall`
SilentGhost
2010-10-12 18:01:19
Good question. After testing, it looks like it either doesn't support `extractall`, or an overwrite isn't considered an error. Looks like SilentGhost's solution is your best bet.
Karl Bielefeldt
2010-10-12 18:07:26