Skip to content

Commit 488ad6f

Browse files
authored
Fix to compute checksums and record file sizes for secondaryFiles. (#147)
1 parent 6fd0b23 commit 488ad6f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cwltool/draft2tool.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,19 @@ def check_adjust(builder, f):
125125
raise WorkflowException("Invalid filename: '%s' contains illegal characters" % (f["basename"]))
126126
return f
127127

128+
def compute_checksums(fs_access, fileobj):
129+
if "checksum" not in fileobj:
130+
checksum = hashlib.sha1()
131+
with fs_access.open(fileobj["location"], "rb") as f:
132+
contents = f.read(1024*1024)
133+
while contents != "":
134+
checksum.update(contents)
135+
contents = f.read(1024*1024)
136+
f.seek(0, 2)
137+
filesize = f.tell()
138+
fileobj["checksum"] = "sha1$%s" % checksum.hexdigest()
139+
fileobj["size"] = filesize
140+
128141
class CommandLineTool(Process):
129142
def __init__(self, toolpath_object, **kwargs):
130143
# type: (Dict[unicode, Any], **Any) -> None
@@ -478,6 +491,9 @@ def collect_output(self, schema, builder, outdir, compute_checksum=True):
478491
if not r and optional:
479492
r = None
480493

494+
if r and compute_checksum:
495+
adjustFileObjs(r, partial(compute_checksums, builder.fs_access))
496+
481497
if (not r and isinstance(schema["type"], dict) and
482498
schema["type"]["type"] == "record"):
483499
out = {}

0 commit comments

Comments
 (0)