Skip to content

Commit 0292c37

Browse files
author
ocaisa
authored
Merge pull request #3147 from boegel/fix_dir_perms
ensure subdirectories in software install directory have correct search (exec) permission
2 parents bf663f7 + fcac457 commit 0292c37

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

easybuild/framework/easyblock.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2776,19 +2776,31 @@ def permissions_step(self):
27762776

27772777
# add read permissions for everybody on all files, taking into account group (if any)
27782778
perms = stat.S_IRUSR | stat.S_IRGRP
2779+
# directory permissions: readable (r) & searchable (x)
2780+
dir_perms = stat.S_IXUSR | stat.S_IXGRP
27792781
self.log.debug("Ensuring read permissions for user/group on install dir (recursively)")
2782+
27802783
if self.group is None:
27812784
perms |= stat.S_IROTH
2785+
dir_perms |= stat.S_IXOTH
27822786
self.log.debug("Also ensuring read permissions for others on install dir (no group specified)")
27832787

27842788
umask = build_option('umask')
27852789
if umask is not None:
27862790
# umask is specified as a string, so interpret it first as integer in octal, then take complement (~)
27872791
perms &= ~int(umask, 8)
2792+
dir_perms &= ~int(umask, 8)
27882793
self.log.debug("Taking umask '%s' into account when ensuring read permissions to install dir", umask)
27892794

2795+
self.log.debug("Adding file read permissions in %s using '%s'", self.installdir, oct(perms))
27902796
adjust_permissions(self.installdir, perms, add=True, recursive=True, relative=True, ignore_errors=True)
2791-
self.log.info("Successfully added read permissions '%s' recursively on install dir", oct(perms))
2797+
2798+
# also ensure directories have exec permissions (so they can be opened)
2799+
self.log.debug("Adding directory search permissions in %s using '%s'", self.installdir, oct(dir_perms))
2800+
adjust_permissions(self.installdir, dir_perms, add=True, recursive=True, relative=True, onlydirs=True,
2801+
ignore_errors=True)
2802+
2803+
self.log.info("Successfully added read permissions recursively on install dir %s", self.installdir)
27922804

27932805
def test_cases_step(self):
27942806
"""

test/framework/toy_build.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,14 @@ def test_toy_download_sources(self):
443443
def test_toy_permissions(self):
444444
"""Test toy build with custom umask settings."""
445445
toy_ec_file = os.path.join(os.path.dirname(__file__), 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0.eb')
446+
test_ec_txt = read_file(toy_ec_file)
447+
448+
# remove exec perms on bin subdirectory for others, to check whether correct dir permissions are set
449+
test_ec_txt += "\npostinstallcmds += ['chmod o-x %(installdir)s/bin']"
450+
451+
test_ec = os.path.join(self.test_prefix, 'test.eb')
452+
write_file(test_ec, test_ec_txt)
453+
446454
args = [
447455
'--sourcepath=%s' % self.test_sourcepath,
448456
'--buildpath=%s' % self.test_buildpath,
@@ -456,7 +464,7 @@ def test_toy_permissions(self):
456464
orig_umask = os.umask(0o022)
457465

458466
# test specifying a non-existing group
459-
allargs = [toy_ec_file] + args + ['--group=thisgroupdoesnotexist']
467+
allargs = [test_ec] + args + ['--group=thisgroupdoesnotexist']
460468
outtxt, err = self.eb_main(allargs, logfile=self.dummylogfn, do_build=True, return_error=True)
461469
err_regex = re.compile("Failed to get group ID .* group does not exist")
462470
self.assertTrue(err_regex.search(outtxt), "Pattern '%s' found in '%s'" % (err_regex.pattern, outtxt))
@@ -479,10 +487,10 @@ def test_toy_permissions(self):
479487
shutil.rmtree(self.test_installpath)
480488

481489
if cfg_group is None and ec_group is None:
482-
allargs = [toy_ec_file]
490+
allargs = [test_ec]
483491
elif ec_group is not None:
484-
shutil.copy2(toy_ec_file, self.test_buildpath)
485-
tmp_ec_file = os.path.join(self.test_buildpath, os.path.basename(toy_ec_file))
492+
shutil.copy2(test_ec, self.test_buildpath)
493+
tmp_ec_file = os.path.join(self.test_buildpath, os.path.basename(test_ec))
486494
write_file(tmp_ec_file, "\ngroup = '%s'" % ec_group, append=True)
487495
allargs = [tmp_ec_file]
488496
allargs.extend(args)
@@ -527,7 +535,7 @@ def test_toy_permissions(self):
527535
perms = os.stat(fullpath).st_mode & 0o777
528536
tup = (fullpath, oct(correct_perms), oct(perms), umask, cfg_group, ec_group)
529537
msg = "Path %s has %s permissions: %s (umask: %s, group: %s - %s)" % tup
530-
self.assertEqual(perms, correct_perms, msg)
538+
self.assertEqual(oct(perms), oct(correct_perms), msg)
531539
if group is not None:
532540
path_gid = os.stat(fullpath).st_gid
533541
self.assertEqual(path_gid, grp.getgrnam(group).gr_gid)

0 commit comments

Comments
 (0)