Skip to content

Commit

Permalink
fix compute_checksums for literal files
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-c committed Dec 5, 2023
1 parent 65ddfc9 commit e9e5aa9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cwltool/command_line_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 10 additions & 5 deletions cwltool/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 1348 in cwltool/process.py

View check run for this annotation

Codecov / codecov/patch

cwltool/process.py#L1346-L1348

Added lines #L1346 - L1348 were not covered by tests
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)

0 comments on commit e9e5aa9

Please sign in to comment.