@@ -390,31 +390,56 @@ def _capture_files(f): # type: (Dict[str, str]) -> Dict[str, str]
390
390
if not sfname :
391
391
continue
392
392
found = False
393
+
394
+ if isinstance (sfname , str ):
395
+ sf_location = (
396
+ datum ["location" ][
397
+ 0 : datum ["location" ].rindex ("/" ) + 1
398
+ ]
399
+ + sfname
400
+ )
401
+ sfbasename = sfname
402
+ elif isinstance (sfname , MutableMapping ):
403
+ sf_location = sfname ["location" ]
404
+ sfbasename = sfname ["basename" ]
405
+ else :
406
+ raise WorkflowException (
407
+ "Expected secondaryFile expression to return type 'str' or 'MutableMapping', received '%s'"
408
+ % (type (sfname ))
409
+ )
410
+
393
411
for d in datum ["secondaryFiles" ]:
394
412
if not d .get ("basename" ):
395
413
d ["basename" ] = d ["location" ][
396
414
d ["location" ].rindex ("/" ) + 1 :
397
415
]
398
- if d ["basename" ] == sfname :
416
+ if d ["basename" ] == sfbasename :
399
417
found = True
418
+
400
419
if not found :
401
- sf_location = (
402
- datum ["location" ][
403
- 0 : datum ["location" ].rindex ("/" ) + 1
404
- ]
405
- + sfname
406
- )
420
+
421
+ def addsf (
422
+ files : MutableSequence [MutableMapping [str , Any ]],
423
+ newsf : MutableMapping [str , Any ],
424
+ ) -> None :
425
+ for f in files :
426
+ if f ["location" ] == newsf ["location" ]:
427
+ f ["basename" ] = newsf ["basename" ]
428
+ return
429
+ files .append (newsf )
430
+
407
431
if isinstance (sfname , MutableMapping ):
408
- datum ["secondaryFiles" ]. append ( sfname )
432
+ addsf ( datum ["secondaryFiles" ], sfname )
409
433
elif discover_secondaryFiles and self .fs_access .exists (
410
434
sf_location
411
435
):
412
- datum ["secondaryFiles" ].append (
436
+ addsf (
437
+ datum ["secondaryFiles" ],
413
438
{
414
439
"location" : sf_location ,
415
440
"basename" : sfname ,
416
441
"class" : "File" ,
417
- }
442
+ },
418
443
)
419
444
elif sf_required :
420
445
raise WorkflowException (
0 commit comments