summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJordan Galby <67924449+Jordan474@users.noreply.github.com>2022-05-19 17:50:24 +0200
committerGitHub <noreply@github.com>2022-05-19 08:50:24 -0700
commitc2fd98ccd24d7ceafdf51a682b010816df230c39 (patch)
tree5a99c1f2573357df71d9727d2286b133ef95eb41 /lib
parenta0fe6ab2edd2f881181d1361f5d55f6c1e5c16ff (diff)
downloadspack-c2fd98ccd24d7ceafdf51a682b010816df230c39.tar.gz
spack-c2fd98ccd24d7ceafdf51a682b010816df230c39.tar.bz2
spack-c2fd98ccd24d7ceafdf51a682b010816df230c39.tar.xz
spack-c2fd98ccd24d7ceafdf51a682b010816df230c39.zip
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/llnl/util/filesystem.py7
-rw-r--r--lib/spack/spack/test/installer.py2
-rw-r--r--lib/spack/spack/util/file_permissions.py2
3 files changed, 7 insertions, 4 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py
index 5c9b225c72..85c452f465 100644
--- a/lib/spack/llnl/util/filesystem.py
+++ b/lib/spack/llnl/util/filesystem.py
@@ -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
- os.chown(path, -1, gid)
+ if follow_symlinks:
+ os.chown(path, -1, gid)
+ else:
+ os.lchown(path, -1, gid)
@system_path_filter(arg_slice=slice(1))
diff --git a/lib/spack/spack/test/installer.py b/lib/spack/spack/test/installer.py
index cd500b1bb8..dd4f5e79bf 100644
--- a/lib/spack/spack/test/installer.py
+++ b/lib/spack/spack/test/installer.py
@@ -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)
diff --git a/lib/spack/spack/util/file_permissions.py b/lib/spack/spack/util/file_permissions.py
index d32d8494e9..3ed1032392 100644
--- a/lib/spack/spack/util/file_permissions.py
+++ b/lib/spack/spack/util/file_permissions.py
@@ -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):