@@ -467,6 +467,38 @@ def _archive_file(
467467 properties ,
468468 )
469469
470+ def _get_local_file (
471+ self , buildrunner_config : BuildRunnerConfig , file_alias : str
472+ ) -> str :
473+ """
474+ Lookup file alias from global config or as a local file.
475+ :param buildrunner_config: buildrunner global configuration
476+ :param file_alias: the file alias
477+ :return: the local file to use (if available)
478+ :raises BuildRunnerConfigurationError: the file alias is not found and is not a valid local file
479+ """
480+ f_local = buildrunner_config .get_local_files_from_alias (file_alias )
481+ if not f_local :
482+ f_local = os .path .realpath (
483+ os .path .join (self .step_runner .build_runner .build_dir , file_alias )
484+ )
485+ if (
486+ f_local != self .step_runner .build_runner .build_dir
487+ and not f_local .startswith (
488+ self .step_runner .build_runner .build_dir + os .path .sep
489+ )
490+ ):
491+ raise BuildRunnerConfigurationError (
492+ f'Mount path of "{ file_alias } " attempts to step out of '
493+ f'source directory "{ self .step_runner .build_runner .build_dir } "'
494+ )
495+
496+ if not os .path .exists (f_local ):
497+ raise BuildRunnerConfigurationError (
498+ f"Cannot find valid alias for files entry '{ file_alias } ' nor path at '{ f_local } '"
499+ )
500+ return f_local
501+
470502 # pylint: disable=too-many-statements,too-many-branches,too-many-locals
471503 def _start_service_container (self , name , service : Service ):
472504 """
@@ -603,11 +635,7 @@ def _start_service_container(self, name, service: Service):
603635 if service .files :
604636 for f_alias , f_path in service .files .items ():
605637 # lookup file from alias
606- f_local = buildrunner_config .get_local_files_from_alias (f_alias )
607- if not f_local or not os .path .exists (f_local ):
608- raise BuildRunnerConfigurationError (
609- f"Cannot find valid local file for alias '{ f_alias } '"
610- )
638+ f_local = self ._get_local_file (buildrunner_config , f_alias )
611639
612640 if f_path [- 3 :] not in [":ro" , ":rw" ]:
613641 f_path = f_path + ":ro"
@@ -980,29 +1008,7 @@ def run(self, context: dict): # pylint: disable=too-many-statements,too-many-br
9801008 # see if we need to inject any files
9811009 if self .step .files :
9821010 for f_alias , f_path in self .step .files .items ():
983- # lookup file from alias
984- f_local = buildrunner_config .get_local_files_from_alias (
985- f_alias ,
986- )
987- if not f_local :
988- f_local = os .path .realpath (
989- os .path .join (self .step_runner .build_runner .build_dir , f_alias )
990- )
991- if (
992- f_local != self .step_runner .build_runner .build_dir
993- and not f_local .startswith (
994- self .step_runner .build_runner .build_dir + os .path .sep
995- )
996- ):
997- raise BuildRunnerConfigurationError (
998- f'Mount path of "{ f_alias } " attempts to step out of '
999- f'source directory "{ self .step_runner .build_runner .build_dir } "'
1000- )
1001-
1002- if not os .path .exists (f_local ):
1003- raise BuildRunnerConfigurationError (
1004- f"Cannot find valid alias for files entry '{ f_alias } ' nor path at '{ f_local } '"
1005- )
1011+ f_local = self ._get_local_file (buildrunner_config , f_alias )
10061012
10071013 if f_path [- 3 :] not in [":ro" , ":rw" ]:
10081014 f_path = f_path + ":ro"
0 commit comments