@@ -3690,15 +3690,21 @@ def build_and_install_one(ecdict, init_env):
36903690
36913691 if os .path .exists (app .installdir ) and build_option ('read_only_installdir' ) and (
36923692 build_option ('rebuild' ) or build_option ('force' )):
3693+ enabled_write_permissions = True
36933694 # re-enable write permissions so we can install additional modules
36943695 adjust_permissions (app .installdir , stat .S_IWUSR , add = True , recursive = True )
3696+ else :
3697+ enabled_write_permissions = False
36953698
36963699 result = app .run_all_steps (run_test_cases = run_test_cases )
36973700
36983701 if not dry_run :
36993702 # also add any extension easyblocks used during the build for reproducibility
37003703 if app .ext_instances :
37013704 copy_easyblocks_for_reprod (app .ext_instances , reprod_dir )
3705+ # If not already done remove the granted write permissions if we did so
3706+ if enabled_write_permissions and os .lstat (app .installdir )[stat .ST_MODE ] & stat .S_IWUSR :
3707+ adjust_permissions (app .installdir , stat .S_IWUSR , add = False , recursive = True )
37023708
37033709 except EasyBuildError as err :
37043710 first_n = 300
@@ -3715,28 +3721,37 @@ def build_and_install_one(ecdict, init_env):
37153721
37163722 # successful (non-dry-run) build
37173723 if result and not dry_run :
3724+ def ensure_writable_log_dir (log_dir ):
3725+ """Make sure we can write into the log dir"""
3726+ if build_option ('read_only_installdir' ):
3727+ # temporarily re-enable write permissions for copying log/easyconfig to install dir
3728+ if os .path .exists (log_dir ):
3729+ adjust_permissions (log_dir , stat .S_IWUSR , add = True , recursive = True )
3730+ else :
3731+ parent_dir = os .path .dirname (log_dir )
3732+ if os .path .exists (parent_dir ):
3733+ adjust_permissions (parent_dir , stat .S_IWUSR , add = True , recursive = False )
3734+ mkdir (log_dir , parents = True )
3735+ adjust_permissions (parent_dir , stat .S_IWUSR , add = False , recursive = False )
3736+ else :
3737+ mkdir (log_dir , parents = True )
3738+ adjust_permissions (log_dir , stat .S_IWUSR , add = True , recursive = True )
37183739
37193740 if app .cfg ['stop' ]:
37203741 ended = 'STOPPED'
37213742 if app .builddir is not None :
37223743 new_log_dir = os .path .join (app .builddir , config .log_path (ec = app .cfg ))
37233744 else :
37243745 new_log_dir = os .path .dirname (app .logfile )
3746+ ensure_writable_log_dir (new_log_dir )
37253747
37263748 # if we're only running the sanity check, we should not copy anything new to the installation directory
37273749 elif build_option ('sanity_check_only' ):
37283750 _log .info ("Only running sanity check, so skipping build stats, easyconfigs archive, reprod files..." )
37293751
37303752 else :
37313753 new_log_dir = os .path .join (app .installdir , config .log_path (ec = app .cfg ))
3732- if build_option ('read_only_installdir' ):
3733- # temporarily re-enable write permissions for copying log/easyconfig to install dir
3734- if os .path .exists (new_log_dir ):
3735- adjust_permissions (new_log_dir , stat .S_IWUSR , add = True , recursive = True )
3736- else :
3737- adjust_permissions (app .installdir , stat .S_IWUSR , add = True , recursive = False )
3738- mkdir (new_log_dir , parents = True )
3739- adjust_permissions (app .installdir , stat .S_IWUSR , add = False , recursive = False )
3754+ ensure_writable_log_dir (new_log_dir )
37403755
37413756 # collect build stats
37423757 _log .info ("Collecting build stats..." )
0 commit comments