summaryrefslogtreecommitdiff
path: root/lib/spack/llnl/util
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/spack/llnl/util
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/spack/llnl/util')
-rw-r--r--lib/spack/llnl/util/filesystem.py7
1 files changed, 5 insertions, 2 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))