@@ -108,7 +108,9 @@ def __init__(self, job, output_callback, cachebuilder, jobcache):
108
108
def run (self , ** kwargs ):
109
109
# type: (**Any) -> None
110
110
self .output_callback (self .job .collect_output_ports (self .job .tool ["outputs" ],
111
- self .cachebuilder , self .outdir ),
111
+ self .cachebuilder ,
112
+ self .outdir ,
113
+ kwargs .get ("compute_checksum" , True )),
112
114
"success" )
113
115
114
116
# map files to assigned path inside a container. We need to also explicitly
@@ -337,12 +339,12 @@ def rm_pending_output_callback(output_callback, jobcachepending,
337
339
338
340
j .pathmapper = builder .pathmapper
339
341
j .collect_outputs = partial (
340
- self .collect_output_ports , self .tool ["outputs" ], builder )
342
+ self .collect_output_ports , self .tool ["outputs" ], builder , compute_checksum = kwargs . get ( "compute_checksum" , True ) )
341
343
j .output_callback = output_callback
342
344
343
345
yield j
344
346
345
- def collect_output_ports (self , ports , builder , outdir ):
347
+ def collect_output_ports (self , ports , builder , outdir , compute_checksum = True ):
346
348
# type: (Set[Dict[str,Any]], Builder, str) -> Dict[unicode, Union[unicode, List[Any], Dict[unicode, Any]]]
347
349
try :
348
350
ret = {} # type: Dict[unicode, Union[unicode, List[Any], Dict[unicode, Any]]]
@@ -364,7 +366,7 @@ def collect_output_ports(self, ports, builder, outdir):
364
366
for port in ports :
365
367
fragment = shortname (port ["id" ])
366
368
try :
367
- ret [fragment ] = self .collect_output (port , builder , outdir )
369
+ ret [fragment ] = self .collect_output (port , builder , outdir , compute_checksum )
368
370
except Exception as e :
369
371
_logger .debug (u"Error collecting output for parameter '%s'" % shortname (port ["id" ]), exc_info = e )
370
372
raise WorkflowException (u"Error collecting output for parameter '%s': %s" % (shortname (port ["id" ]), e ))
@@ -377,7 +379,7 @@ def collect_output_ports(self, ports, builder, outdir):
377
379
except validate .ValidationException as e :
378
380
raise WorkflowException ("Error validating output record, " + str (e ) + "\n in " + json .dumps (ret , indent = 4 ))
379
381
380
- def collect_output (self , schema , builder , outdir ):
382
+ def collect_output (self , schema , builder , outdir , compute_checksum = True ):
381
383
# type: (Dict[str,Any], Builder, str) -> Union[Dict[unicode, Any], List[Union[Dict[unicode, Any], unicode]]]
382
384
r = [] # type: List[Any]
383
385
if "outputBinding" in schema :
@@ -410,17 +412,20 @@ def collect_output(self, schema, builder, outdir):
410
412
if files ["class" ] == "Directory" and "listing" not in files :
411
413
getListing (builder .fs_access , files )
412
414
else :
413
- checksum = hashlib .sha1 ()
414
415
with builder .fs_access .open (files ["location" ], "rb" ) as f :
415
- contents = f .read (CONTENT_LIMIT )
416
+ contents = ""
417
+ if binding .get ("loadContents" ) or compute_checksum :
418
+ contents = f .read (CONTENT_LIMIT )
416
419
if binding .get ("loadContents" ):
417
420
files ["contents" ] = contents
418
- filesize = 0
419
- while contents != "" :
420
- checksum .update (contents )
421
- filesize += len (contents )
422
- contents = f .read (1024 * 1024 )
423
- files ["checksum" ] = "sha1$%s" % checksum .hexdigest ()
421
+ if compute_checksum :
422
+ checksum = hashlib .sha1 ()
423
+ while contents != "" :
424
+ checksum .update (contents )
425
+ contents = f .read (1024 * 1024 )
426
+ files ["checksum" ] = "sha1$%s" % checksum .hexdigest ()
427
+ f .seek (0 , 2 )
428
+ filesize = f .tell ()
424
429
files ["size" ] = filesize
425
430
if "format" in schema :
426
431
files ["format" ] = builder .do_eval (schema ["format" ], context = files )
@@ -478,6 +483,6 @@ def collect_output(self, schema, builder, outdir):
478
483
out = {}
479
484
for f in schema ["type" ]["fields" ]:
480
485
out [shortname (f ["name" ])] = self .collect_output ( # type: ignore
481
- f , builder , outdir )
486
+ f , builder , outdir , compute_checksum )
482
487
return out
483
488
return r
0 commit comments