Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(39051)

Unified Diff: Lib/tarfile.py

Issue 19974: tarfile doesn't overwrite symlink by directory
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Lib/test/test_tarfile.py » ('j') | Lib/test/test_tarfile.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/tarfile.py Wed Feb 19 23:06:41 2014 -0500
+++ b/Lib/tarfile.py Thu Feb 20 19:12:55 2014 +0800
@@ -47,6 +47,7 @@
import struct
import copy
import re
+import errno
Martin Panter 2018/12/16 02:37:21 What is this needed for?
try:
import grp, pwd
@@ -2085,6 +2086,16 @@
else:
self._dbg(1, tarinfo.name)
+ if os.path.exists(targetpath) and \
Martin Panter 2018/12/16 02:37:21 What about “lexists” for handling broken links? Se
+ (not os.path.isdir(targetpath) or os.path.islink(targetpath)):
+ os.remove(targetpath)
+ else:
+ # File should be able to overwrite empty directory
+ try:
+ os.rmdir(targetpath)
+ except OSError:
+ pass
+
if tarinfo.isreg():
self.makefile(tarinfo, targetpath)
elif tarinfo.isdir():
@@ -2175,7 +2186,10 @@
try:
# For systems that support symbolic and hard links.
if tarinfo.issym():
- os.symlink(tarinfo.linkname, targetpath)
+ if os.name == 'nt' and os.path.isdir(tarinfo.linkname):
+ os.symlink(tarinfo.linkname, targetpath, target_is_directory=True)
+ else:
+ os.symlink(tarinfo.linkname, targetpath)
else:
# See extract().
if os.path.exists(tarinfo._link_target):
« no previous file with comments | « no previous file | Lib/test/test_tarfile.py » ('j') | Lib/test/test_tarfile.py » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+