Fix spack install chgrp on symlinks (#30743)

Fixes missing chgrp on symlinks in package installations, and errors on
symlinks referencing non-existent or non-writable locations.

Note: `os.chown(.., follow_symlinks=False)` is python3 only, but
`os.lchown` exists in both versions.
This commit is contained in:
Jordan Galby 2022-05-19 17:50:24 +02:00 committed by GitHub
parent a0fe6ab2ed
commit c2fd98ccd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -367,7 +367,7 @@ def group_ids(uid=None):
@system_path_filter(arg_slice=slice(1))
def chgrp(path, group):
def chgrp(path, group, follow_symlinks=True):
"""Implement the bash chgrp function on a single path"""
if is_windows:
raise OSError("Function 'chgrp' is not supported on Windows")
@ -376,7 +376,10 @@ def chgrp(path, group):
gid = grp.getgrnam(group).gr_gid
else:
gid = group
if follow_symlinks:
os.chown(path, -1, gid)
else:
os.lchown(path, -1, gid)
@system_path_filter(arg_slice=slice(1))

View File

@ -820,7 +820,7 @@ def test_setup_install_dir_grp(install_mockery, monkeypatch, capfd):
def _get_group(spec):
return mock_group
def _chgrp(path, group):
def _chgrp(path, group, follow_symlinks=True):
tty.msg(mock_chgrp_msg.format(path, group))
monkeypatch.setattr(prefs, 'get_package_group', _get_group)

View File

@ -44,7 +44,7 @@ def set_permissions(path, perms, group=None):
fs.chmod_x(path, perms)
if group:
fs.chgrp(path, group)
fs.chgrp(path, group, follow_symlinks=False)
class InvalidPermissionsError(SpackError):