Skip to content

Commit

Permalink
Pass a PathMapper to the function that computes checksums, so it can …
Browse files Browse the repository at this point in the history
…resolve files downloaded for instance
  • Loading branch information
kinow committed Apr 19, 2023
1 parent 0fb96db commit beaeccc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion cwltool/command_line_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ def job(
_checksum = partial(
compute_checksums,
runtimeContext.make_fs_access(runtimeContext.basedir),
cachebuilder,
)
visit_class(
[cachebuilder.files, cachebuilder.bindings],
Expand Down Expand Up @@ -1252,7 +1253,7 @@ def collect_output_ports(
)

if compute_checksum:
adjustFileObjs(ret, partial(compute_checksums, fs_access))
adjustFileObjs(ret, partial(compute_checksums, fs_access, builder))
expected_schema = cast(Schema, self.names.get_name("outputs_record_schema", None))
validate_ex(
expected_schema,
Expand Down
14 changes: 9 additions & 5 deletions cwltool/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def _check_adjust(a_file: CWLObjectType) -> CWLObjectType:
visit_class(outputObj, ("File", "Directory"), _check_adjust)

if compute_checksum:
visit_class(outputObj, ("File",), functools.partial(compute_checksums, fs_access))
visit_class(outputObj, ("File",), functools.partial(compute_checksums, fs_access, None))
return outputObj


Expand Down Expand Up @@ -1341,14 +1341,18 @@ def scandeps(
return r


def compute_checksums(fs_access: StdFsAccess, fileobj: CWLObjectType) -> None:
def compute_checksums(fs_access: StdFsAccess, builder: Builder, 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:
location = file_path = cast(str, fileobj["location"])
if builder:
if not builder.pathmapper:
raise ValueError("Do not call compute_checksums using a builder that doesn't have a pathmapper.")
file_path = builder.pathmapper.mapper(location)[0]
with fs_access.open(file_path, "rb") as f:
contents = f.read(1024 * 1024)
while contents != b"":
checksum.update(contents)
contents = f.read(1024 * 1024)
fileobj["checksum"] = "sha1$%s" % checksum.hexdigest()
fileobj["size"] = fs_access.size(location)
fileobj["size"] = fs_access.size(file_path)

0 comments on commit beaeccc

Please sign in to comment.