diff --git a/cwltool/command_line_tool.py b/cwltool/command_line_tool.py index 0b0d7f3ec2..5b2bea5b22 100644 --- a/cwltool/command_line_tool.py +++ b/cwltool/command_line_tool.py @@ -866,7 +866,7 @@ def calc_checksum(location: str) -> Optional[str]: and "checksum" in e and e["checksum"] != "sha1$hash" ): - return cast(Optional[str], e["checksum"]) + return cast(str, e["checksum"]) return None def remove_prefix(s: str, prefix: str) -> str: diff --git a/cwltool/process.py b/cwltool/process.py index c442bf249b..4f046928b5 100644 --- a/cwltool/process.py +++ b/cwltool/process.py @@ -1342,10 +1342,15 @@ def compute_checksums(fs_access: StdFsAccess, fileobj: CWLObjectType) -> None: if "checksum" not in fileobj: checksum = hashlib.sha1() # nosec location = cast(str, fileobj["location"]) - with fs_access.open(location, "rb") as f: - contents = f.read(1024 * 1024) - while contents != b"": - checksum.update(contents) + if "contents" in fileobj: + contents = cast(str, fileobj["contents"]).encode("utf-8") + checksum.update(contents) + fileobj["size"] = len(contents) + else: + with fs_access.open(location, "rb") as f: contents = f.read(1024 * 1024) + while contents != b"": + checksum.update(contents) + contents = f.read(1024 * 1024) + fileobj["size"] = fs_access.size(location) fileobj["checksum"] = "sha1$%s" % checksum.hexdigest() - fileobj["size"] = fs_access.size(location)