Applying c9fb97cc8 (permissions on symlink fix) to v2

pull/10846/head
Toshio Kuratomi 10 years ago committed by James Cammarata
parent 0303d9ce49
commit 582259f98b

@ -31,7 +31,7 @@
ANSIBLE_VERSION = "<<ANSIBLE_VERSION>>" ANSIBLE_VERSION = "<<ANSIBLE_VERSION>>"
MODULE_ARGS = "" MODULE_ARGS = "<<INCLUDE_ANSIBLE_MODULE_ARGS>>"
MODULE_COMPLEX_ARGS = "<<INCLUDE_ANSIBLE_MODULE_COMPLEX_ARGS>>" MODULE_COMPLEX_ARGS = "<<INCLUDE_ANSIBLE_MODULE_COMPLEX_ARGS>>"
BOOLEANS_TRUE = ['yes', 'on', '1', 'true', 1] BOOLEANS_TRUE = ['yes', 'on', '1', 'true', 1]
@ -657,14 +657,25 @@ class AnsibleModule(object):
# FIXME: comparison against string above will cause this to be executed # FIXME: comparison against string above will cause this to be executed
# every time # every time
try: try:
if 'lchmod' in dir(os): if hasattr(os, 'lchmod'):
os.lchmod(path, mode) os.lchmod(path, mode)
else: else:
if not os.path.islink(path):
os.chmod(path, mode) os.chmod(path, mode)
else:
# Attempt to set the perms of the symlink but be
# careful not to change the perms of the underlying
# file while trying
underlying_stat = os.stat(path)
os.chmod(path, mode)
new_underlying_stat = os.stat(path)
if underlying_stat.st_mode != new_underlying_stat.st_mode:
os.chmod(path, stat.S_IMODE(underlying_stat.st_mode))
q_stat = os.stat(path)
except OSError, e: except OSError, e:
if os.path.islink(path) and e.errno == errno.EPERM: # Can't set mode on symbolic links if os.path.islink(path) and e.errno == errno.EPERM: # Can't set mode on symbolic links
pass pass
elif e.errno == errno.ENOENT: # Can't set mode on broken symbolic links elif e.errno in (errno.ENOENT, errno.ELOOP): # Can't set mode on broken symbolic links
pass pass
else: else:
raise e raise e

Loading…
Cancel
Save