minstall: never try to set chmod on symlinks

It's only supported by few platforms when the linked file exists, while it
would cause an error otherwise.

In any case just implement this via an helper set_chmod function that will
handle the case where follow_symlinks is not supported by the platform
and will just not set any mod for the link itself (as it would otherwise
apply to the linked file).

Fixes #3914
pull/4030/head
Marco Trevisan (Treviño) 6 years ago
parent 9f87d5d955
commit 2d010727ed
  1. 11
      mesonbuild/minstall.py

@ -79,13 +79,20 @@ def append_to_log(lf, line):
lf.write('\n')
lf.flush()
def set_chmod(path, mode, dir_fd=None, follow_symlinks=True):
try:
os.chmod(path, mode, dir_fd=dir_fd, follow_symlinks=follow_symlinks)
except (NotImplementedError, OSError, SystemError) as e:
if not os.path.islink(path):
os.chmod(path, mode, dir_fd=dir_fd)
def sanitize_permissions(path, umask):
if umask is None:
return
new_perms = 0o777 if is_executable(path) else 0o666
new_perms &= ~umask
try:
os.chmod(path, new_perms)
set_chmod(path, new_perms, follow_symlinks=False)
except PermissionError as e:
msg = '{!r}: Unable to set permissions {!r}: {}, ignoring...'
print(msg.format(path, new_perms, e.strerror))
@ -116,7 +123,7 @@ def set_mode(path, mode, default_umask):
# NOTE: On Windows you can set read/write perms; the rest are ignored
if mode.perms_s is not None:
try:
os.chmod(path, mode.perms)
set_chmod(path, mode.perms, follow_symlinks=False)
except PermissionError as e:
msg = '{!r}: Unable to set permissions {!r}: {}, ignoring...'
print(msg.format(path, mode.perms_s, e.strerror))

Loading…
Cancel
Save