Skip to content

Commit afe65cb

Browse files
committed
Pass a PathMapper to the function that computes checksums, so it can resolve files downloaded for instance
1 parent 0fb96db commit afe65cb

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

cwltool/command_line_tool.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ def job(
826826
_checksum = partial(
827827
compute_checksums,
828828
runtimeContext.make_fs_access(runtimeContext.basedir),
829+
cachebuilder,
829830
)
830831
visit_class(
831832
[cachebuilder.files, cachebuilder.bindings],
@@ -1252,7 +1253,7 @@ def collect_output_ports(
12521253
)
12531254

12541255
if compute_checksum:
1255-
adjustFileObjs(ret, partial(compute_checksums, fs_access))
1256+
adjustFileObjs(ret, partial(compute_checksums, fs_access, builder))
12561257
expected_schema = cast(Schema, self.names.get_name("outputs_record_schema", None))
12571258
validate_ex(
12581259
expected_schema,

cwltool/process.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def _check_adjust(a_file: CWLObjectType) -> CWLObjectType:
391391
visit_class(outputObj, ("File", "Directory"), _check_adjust)
392392

393393
if compute_checksum:
394-
visit_class(outputObj, ("File",), functools.partial(compute_checksums, fs_access))
394+
visit_class(outputObj, ("File",), functools.partial(compute_checksums, fs_access, None))
395395
return outputObj
396396

397397

@@ -1341,14 +1341,21 @@ def scandeps(
13411341
return r
13421342

13431343

1344-
def compute_checksums(fs_access: StdFsAccess, fileobj: CWLObjectType) -> None:
1344+
def compute_checksums(fs_access: StdFsAccess, builder: Builder, fileobj: CWLObjectType) -> None:
13451345
if "checksum" not in fileobj:
13461346
checksum = hashlib.sha1() # nosec
1347-
location = cast(str, fileobj["location"])
1348-
with fs_access.open(location, "rb") as f:
1347+
location = file_path = cast(str, fileobj["location"])
1348+
if builder:
1349+
if not builder.pathmapper:
1350+
raise ValueError(
1351+
"Do not call compute_checksums using a "
1352+
"builder that doesn't have a pathmapper."
1353+
)
1354+
file_path = builder.pathmapper.mapper(location)[0]
1355+
with fs_access.open(file_path, "rb") as f:
13491356
contents = f.read(1024 * 1024)
13501357
while contents != b"":
13511358
checksum.update(contents)
13521359
contents = f.read(1024 * 1024)
13531360
fileobj["checksum"] = "sha1$%s" % checksum.hexdigest()
1354-
fileobj["size"] = fs_access.size(location)
1361+
fileobj["size"] = fs_access.size(file_path)

0 commit comments

Comments
 (0)