@@ -233,22 +233,22 @@ fn evaluate_output_impl(
233233}
234234
235235fn handle_file_output ( entry : & PathBuf , initial_dir : & Path , output : & CommandOutputParameter ) -> Result < DefaultValue , Box < dyn Error > > {
236- let current_dir = env:: temp_dir ( ) . to_string_lossy ( ) . into_owned ( ) ;
236+ let current_dir = env:: current_dir ( ) ? . to_string_lossy ( ) . into_owned ( ) ;
237237 let path = & initial_dir. join ( entry. strip_prefix ( & current_dir) . unwrap_or ( entry) ) ;
238238 fs:: copy ( entry, path) . map_err ( |e| format ! ( "Failed to copy file from {entry:?} to {path:?}: {e}" ) ) ?;
239239 info ! ( "📜 Wrote output file: {path:?}" ) ;
240240
241241 let mut file = get_file_metadata ( path, output. format . clone ( ) ) ;
242242 if !output. secondary_files . is_empty ( ) {
243243 set_self ( & file) ?;
244- let folder = entry. parent ( ) . unwrap_or ( Path :: new ( ". " ) ) ;
244+ let folder = entry. parent ( ) . unwrap_or ( Path :: new ( "" ) ) ;
245245 let mut secondary_files = vec ! [ ] ;
246246 for secondary in & output. secondary_files {
247247 let pattern = replace_expressions ( & secondary. pattern ) ?;
248- let pattern = format ! ( "{}*{}" , folder. to_string_lossy( ) , pattern) ;
248+ let pattern = format ! ( "{}/ *{}" , folder. to_string_lossy( ) , pattern) ;
249249 for entry in glob ( & pattern) ? {
250250 let entry = entry?;
251- let sec_path = initial_dir. join ( & entry) ;
251+ let sec_path = initial_dir. join ( entry . strip_prefix ( & current_dir ) . unwrap_or ( & entry) ) ;
252252 fs:: copy ( & entry, & sec_path) . map_err ( |e| format ! ( "Failed to copy file from {entry:?} to {sec_path:?}: {e}" ) ) ?;
253253 info ! ( "📜 Wrote secondary file: {sec_path:?}" ) ;
254254 secondary_files. push ( DefaultValue :: File ( get_file_metadata ( & sec_path, None ) ) ) ;
@@ -287,17 +287,22 @@ pub(crate) fn get_diretory_metadata<P: AsRef<Path>>(path: P) -> Directory {
287287pub ( crate ) fn copy_output_dir < P : AsRef < Path > , Q : AsRef < Path > > ( src : P , dest : Q ) -> Result < Directory , std:: io:: Error > {
288288 fs:: create_dir_all ( & dest) ?;
289289 let mut dir = get_diretory_metadata ( & dest) ;
290-
290+ dir. listing = Some ( vec ! [ ] ) ;
291+
291292 for entry in fs:: read_dir ( src) ? {
292293 let entry = entry?;
293294 let src_path = entry. path ( ) ;
294295 let dest_path = dest. as_ref ( ) . join ( entry. file_name ( ) ) ;
295- if src_path. is_dir ( ) {
296+ let entry = if src_path. is_dir ( ) {
296297 let sub_dir = copy_output_dir ( src_path, dest_path) ?;
297- dir . listing . push ( DefaultValue :: Directory ( sub_dir) ) ;
298+ DefaultValue :: Directory ( sub_dir)
298299 } else {
299300 copy_file ( src_path, & dest_path) ?;
300- dir. listing . push ( DefaultValue :: File ( get_file_metadata ( dest_path, None ) ) ) ;
301+ DefaultValue :: File ( get_file_metadata ( dest_path, None ) )
302+ } ;
303+
304+ if let Some ( ref mut listing) = dir. listing {
305+ listing. push ( entry) ;
301306 }
302307 }
303308 Ok ( dir)
@@ -549,18 +554,19 @@ mod tests {
549554 copy_dir ( cwd, stage. to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
550555
551556 let mut result = copy_output_dir ( stage. to_str ( ) . unwrap ( ) , cwd) . expect ( "could not copy dir" ) ;
552- result. listing . sort_by_key ( |item| match item {
553- DefaultValue :: File ( file) => file. basename . clone ( ) ,
554- _ => Some ( String :: new ( ) ) ,
555- } ) ;
556-
557+ if let Some ( ref mut listing) = result. listing {
558+ listing. sort_by_key ( |item| match item {
559+ DefaultValue :: File ( file) => file. basename . clone ( ) ,
560+ _ => Some ( String :: new ( ) ) ,
561+ } ) ;
562+ }
557563 let file = current. join ( "file.txt" ) . to_string_lossy ( ) . into_owned ( ) ;
558564 let input = current. join ( "input.txt" ) . to_string_lossy ( ) . into_owned ( ) ;
559565
560566 let expected = Directory {
561567 location : Some ( format ! ( "file://{cwd}" ) ) ,
562568 basename : Some ( "test_dir" . to_string ( ) ) ,
563- listing : vec ! [
569+ listing : Some ( vec ! [
564570 DefaultValue :: File ( File {
565571 class: "File" . into( ) ,
566572 location: Some ( format!( "file://{file}" ) ) ,
@@ -583,7 +589,7 @@ mod tests {
583589 path: Some ( input) ,
584590 ..Default :: default ( )
585591 } ) ,
586- ] ,
592+ ] ) ,
587593 path : Some ( cwd. to_string ( ) ) ,
588594 ..Default :: default ( )
589595 } ;
0 commit comments