11
11
import logging
12
12
import hashlib
13
13
import random
14
- from process import Process , shortname , uniquename
14
+ from process import Process , shortname , uniquename , adjustFiles
15
15
from errors import WorkflowException
16
16
import schema_salad .validate as validate
17
17
from aslist import aslist
@@ -200,6 +200,20 @@ def collect_output_ports(self, ports, builder, outdir):
200
200
raise WorkflowException ("Error validating output record, " + str (e ) + "\n in " + json .dumps (ret , indent = 4 ))
201
201
202
202
def collect_output (self , schema , builder , outdir ):
203
+ def revmap_file (f ):
204
+ """Remap a file back to original path. For Docker, this is outside the container.
205
+
206
+ Uses either files in the pathmapper or remaps internal output directories
207
+ to the external directory.
208
+ """
209
+ revmap_f = builder .pathmapper .reversemap (f )
210
+ if revmap_f :
211
+ return revmap_f [- 1 ]
212
+ elif f .startswith (builder .outdir ):
213
+ return f .replace (builder .outdir , outdir )
214
+ else :
215
+ return f
216
+
203
217
r = None
204
218
if "outputBinding" in schema :
205
219
binding = schema ["outputBinding" ]
@@ -263,6 +277,8 @@ def collect_output(self, schema, builder, outdir):
263
277
r = r [0 ]
264
278
265
279
if "secondaryFiles" in schema :
280
+ # remap secondaryFiles since we check if they exist
281
+ adjustFiles (r , revmap_file )
266
282
for primary in aslist (r ):
267
283
if isinstance (primary , dict ):
268
284
primary ["secondaryFiles" ] = []
@@ -285,5 +301,6 @@ def collect_output(self, schema, builder, outdir):
285
301
r = {}
286
302
for f in schema ["type" ]["fields" ]:
287
303
r [shortname (f ["name" ])] = self .collect_output (f , builder , outdir )
288
-
304
+ # Ensure files point to local references outside of the run environment
305
+ adjustFiles (r , revmap_file )
289
306
return r
0 commit comments