mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Test that os.utime and os.chmod actually exist before using them.
This commit is contained in:
parent
6e31aad983
commit
834eff6a4c
1 changed files with 7 additions and 4 deletions
|
@ -1513,14 +1513,17 @@ class TarFile(object):
|
||||||
def chmod(self, tarinfo, targetpath):
|
def chmod(self, tarinfo, targetpath):
|
||||||
"""Set file permissions of targetpath according to tarinfo.
|
"""Set file permissions of targetpath according to tarinfo.
|
||||||
"""
|
"""
|
||||||
try:
|
if hasattr(os, 'chmod'):
|
||||||
os.chmod(targetpath, tarinfo.mode)
|
try:
|
||||||
except EnvironmentError, e:
|
os.chmod(targetpath, tarinfo.mode)
|
||||||
raise ExtractError, "could not change mode"
|
except EnvironmentError, e:
|
||||||
|
raise ExtractError, "could not change mode"
|
||||||
|
|
||||||
def utime(self, tarinfo, targetpath):
|
def utime(self, tarinfo, targetpath):
|
||||||
"""Set modification time of targetpath according to tarinfo.
|
"""Set modification time of targetpath according to tarinfo.
|
||||||
"""
|
"""
|
||||||
|
if not hasattr(os, 'utime'):
|
||||||
|
return
|
||||||
if sys.platform == "win32" and tarinfo.isdir():
|
if sys.platform == "win32" and tarinfo.isdir():
|
||||||
# According to msdn.microsoft.com, it is an error (EACCES)
|
# According to msdn.microsoft.com, it is an error (EACCES)
|
||||||
# to use utime() on directories.
|
# to use utime() on directories.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue