summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/spack/llnl/util/filesystem.py11
-rw-r--r--lib/spack/spack/test/sbang.py6
2 files changed, 13 insertions, 4 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py
index fa1188c133..aece52f843 100644
--- a/lib/spack/llnl/util/filesystem.py
+++ b/lib/spack/llnl/util/filesystem.py
@@ -505,8 +505,15 @@ def group_ids(uid=None):
if uid is None:
uid = getuid()
- user = pwd.getpwuid(uid).pw_name
- return [g.gr_gid for g in grp.getgrall() if user in g.gr_mem]
+
+ pwd_entry = pwd.getpwuid(uid)
+ user = pwd_entry.pw_name
+
+ # user's primary group id may not be listed in grp (i.e. /etc/group)
+ # you have to check pwd for that, so start the list with that
+ gids = [pwd_entry.pw_gid]
+
+ return sorted(set(gids + [g.gr_gid for g in grp.getgrall() if user in g.gr_mem]))
@system_path_filter(arg_slice=slice(1))
diff --git a/lib/spack/spack/test/sbang.py b/lib/spack/spack/test/sbang.py
index 18a408a549..876f3f4d0f 100644
--- a/lib/spack/spack/test/sbang.py
+++ b/lib/spack/spack/test/sbang.py
@@ -7,7 +7,6 @@
Test that Spack's shebang filtering works correctly.
"""
import filecmp
-import getpass
import os
import shutil
import stat
@@ -273,6 +272,9 @@ def configure_group_perms():
# and grp does not act on remote groups.
# To ensure we find a group we can operate on, we get take the first group
# listed which has the current user as a member.
+ gid = fs.group_ids(os.getuid())[0]
+ group_name = grp.getgrgid(gid).gr_name
+
conf = syaml.load_config(
"""\
all:
@@ -281,7 +283,7 @@ all:
write: group
group: {0}
""".format(
- [g.gr_name for g in grp.getgrall() if getpass.getuser() in g.gr_mem][0]
+ group_name
)
)
spack.config.set("packages", conf, scope="user")