@@ -5,7 +5,7 @@ use crate::{
55use cwl:: {
66 inputs:: CommandInputParameter ,
77 outputs:: CommandOutputParameter ,
8- requirements:: Requirement ,
8+ requirements:: { Requirement , WorkDirItem } ,
99 types:: { CWLType , DefaultValue , Directory , Entry , File , PathItem } ,
1010 CWLDocument ,
1111} ;
@@ -81,29 +81,49 @@ fn stage_requirements(requirements: &Option<Vec<Requirement>>, tool_path: &Path,
8181 for requirement in requirements {
8282 if let Requirement :: InitialWorkDirRequirement ( iwdr) = requirement {
8383 for listing in & iwdr. listing {
84- let into_path = path. join ( & listing. entryname ) ; //stage as listing's entry name
85- let path_str = & into_path. to_string_lossy ( ) ;
86- match & listing. entry {
87- Entry :: Source ( src) => {
88- if fs:: exists ( src) . unwrap_or ( false ) {
89- copy_file ( src, & into_path) . map_err ( |e| format ! ( "Failed to copy file from {} to {}: {}" , src, path_str, e) ) ?;
90- } else {
91- create_and_write_file ( & into_path, src) . map_err ( |e| format ! ( "Failed to create file {:?}: {}" , into_path, e) ) ?;
84+ let into_path = match listing {
85+ WorkDirItem :: Dirent ( dirent) => path. join ( & dirent. entryname ) ,
86+ WorkDirItem :: FileOrDirectory ( val) => match & * * val {
87+ DefaultValue :: File ( file) => {
88+ let location = Path :: new ( file. location . as_ref ( ) . unwrap ( ) ) ;
89+ path. join ( location. file_name ( ) . unwrap ( ) )
90+ }
91+ DefaultValue :: Directory ( directory) => {
92+ let location = Path :: new ( directory. location . as_ref ( ) . unwrap ( ) ) ;
93+ path. join ( location. file_name ( ) . unwrap ( ) )
9294 }
93- }
94- Entry :: Include ( include) => {
95- let mut include_path = tool_path. join ( & include. include ) ;
96- if !include_path. exists ( ) || !include_path. is_file ( ) {
97- let current = env:: current_dir ( ) ?;
98- let file_path: String = include. include . clone ( ) . trim_start_matches ( |c : char | !c. is_alphabetic ( ) ) . to_string ( ) ;
99- include_path = current. join ( file_path. clone ( ) ) ;
100- if !include_path. exists ( ) || !include_path. is_file ( ) {
101- include_path = current. join ( tool_path) . join ( file_path) ;
95+ _ => unreachable ! ( ) ,
96+ } ,
97+ WorkDirItem :: Expression ( _) => unreachable ! ( ) , //resolved before!
98+ } ;
99+ //stage as listing's entry name
100+ let path_str = & into_path. to_string_lossy ( ) ;
101+ match & listing {
102+ WorkDirItem :: Dirent ( dirent) => match & dirent. entry {
103+ Entry :: Source ( src) => {
104+ if fs:: exists ( src) . unwrap_or ( false ) {
105+ copy_file ( src, & into_path) . map_err ( |e| format ! ( "Failed to copy file from {} to {}: {}" , src, path_str, e) ) ?;
106+ } else {
107+ create_and_write_file ( & into_path, src) . map_err ( |e| format ! ( "Failed to create file {:?}: {}" , into_path, e) ) ?;
102108 }
103109 }
104- copy_file ( include_path. to_str ( ) . unwrap ( ) , & into_path)
105- . map_err ( |e| format ! ( "Failed to copy file from {:?} to {:?}: {}" , include_path, into_path, e) ) ?;
106- }
110+ Entry :: Include ( include) => {
111+ let path = get_iwdr_src ( tool_path, & include. include ) ?;
112+ copy_file ( & path, & into_path) . map_err ( |e| format ! ( "Failed to copy file from {:?} to {:?}: {}" , path, into_path, e) ) ?;
113+ }
114+ } ,
115+ WorkDirItem :: FileOrDirectory ( val) => match & * * val {
116+ DefaultValue :: File ( file) => {
117+ let path = get_iwdr_src ( tool_path, file. location . as_ref ( ) . unwrap ( ) ) ?;
118+ copy_file ( & path, & into_path) . map_err ( |e| format ! ( "Failed to copy file from {:?} to {:?}: {}" , path, into_path, e) ) ?;
119+ }
120+ DefaultValue :: Directory ( directory) => {
121+ let path = get_iwdr_src ( tool_path, directory. location . as_ref ( ) . unwrap ( ) ) ?;
122+ copy_dir ( & path, & into_path) . map_err ( |e| format ! ( "Failed to copy dir from {:?} to {:?}: {}" , path, into_path, e) ) ?;
123+ }
124+ _ => unreachable ! ( ) ,
125+ } ,
126+ WorkDirItem :: Expression ( _) => unreachable ! ( ) ,
107127 }
108128 staged_files. push ( path_str. clone ( ) . into_owned ( ) ) ;
109129 }
@@ -120,6 +140,20 @@ fn stage_requirements(requirements: &Option<Vec<Requirement>>, tool_path: &Path,
120140 Ok ( staged_files)
121141}
122142
143+ fn get_iwdr_src ( tool_path : & Path , basepath : & String ) -> Result < PathBuf , Box < dyn Error + ' static > > {
144+ let mut path = tool_path. join ( basepath) ;
145+ if !path. exists ( ) {
146+ let current = env:: current_dir ( ) ?;
147+ let file_path: String = basepath. clone ( ) . trim_start_matches ( |c : char | !c. is_alphabetic ( ) ) . to_string ( ) ;
148+ path = current. join ( file_path. clone ( ) ) ;
149+ if !path. exists ( ) {
150+ path = current. join ( tool_path) . join ( file_path) ;
151+ }
152+ }
153+
154+ Ok ( path)
155+ }
156+
123157fn stage_input_files (
124158 inputs : & [ CommandInputParameter ] ,
125159 runtime : & mut RuntimeEnvironment ,
0 commit comments