summaryrefslogtreecommitdiffstats
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
authorLars Gustäbel <lars@gustaebel.de>2008-02-05 11:51:40 (GMT)
committerLars Gustäbel <lars@gustaebel.de>2008-02-05 11:51:40 (GMT)
commit0192e43d64aded9476b2ae90427a801f3f36c11c (patch)
treeffeb846b65f2473aedc6aeb04417b5d819ca076d /Lib/tarfile.py
parentdc6d9e1f5e966a4427c1d9096ec7787082cfff0d (diff)
downloadcpython-0192e43d64aded9476b2ae90427a801f3f36c11c.zip
cpython-0192e43d64aded9476b2ae90427a801f3f36c11c.tar.gz
cpython-0192e43d64aded9476b2ae90427a801f3f36c11c.tar.bz2
Issue #2004: Use mode 0700 for temporary directories and default
permissions for missing directories. (will backport to 2.5)
Diffstat (limited to 'Lib/tarfile.py')
-rw-r--r--Lib/tarfile.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 7143f0b..92fdb7b 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -2021,15 +2021,11 @@ class TarFile(object):
for tarinfo in members:
if tarinfo.isdir():
- # Extract directory with a safe mode, so that
- # all files below can be extracted as well.
- try:
- os.makedirs(os.path.join(path, tarinfo.name), 0700)
- except EnvironmentError:
- pass
+ # Extract directories with a safe mode.
directories.append(tarinfo)
- else:
- self.extract(tarinfo, path)
+ tarinfo = copy.copy(tarinfo)
+ tarinfo.mode = 0700
+ self.extract(tarinfo, path)
# Reverse sort directories.
directories.sort(lambda a, b: cmp(a.name, b.name))
@@ -2134,6 +2130,8 @@ class TarFile(object):
# Create all upper directories.
upperdirs = os.path.dirname(targetpath)
if upperdirs and not os.path.exists(upperdirs):
+ # Create directories that are not part of the archive with
+ # default permissions.
os.makedirs(upperdirs)
if tarinfo.islnk() or tarinfo.issym():
@@ -2170,7 +2168,9 @@ class TarFile(object):
"""Make a directory called targetpath.
"""
try:
- os.mkdir(targetpath)
+ # Use a safe mode for the directory, the real mode is set
+ # later in _extract_member().
+ os.mkdir(targetpath, 0700)
except EnvironmentError, e:
if e.errno != errno.EEXIST:
raise