@@ -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,30 @@ 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 :
1345+ """
1346+ Compute the checksums of a file object.
1347+
1348+ :param fs_access: Used to compute file stats such as its size.
1349+ :param builder: Optional CWL builder that must have a :py:class:`PathMapper` , which
1350+ will be used to resolve the actual file location (not its ``stagedir``).
1351+ :param fileobj: File object.
1352+ :raises ValueError: If a builder is provided but without having a :py:class:`PathMapper`.
1353+ """
13451354 if "checksum" not in fileobj :
13461355 checksum = hashlib .sha1 () # nosec
1347- location = cast (str , fileobj ["location" ])
1348- with fs_access .open (location , "rb" ) as f :
1356+ location = file_path = cast (str , fileobj ["location" ])
1357+ if builder :
1358+ if not builder .pathmapper :
1359+ raise ValueError (
1360+ "Do not call compute_checksums using a "
1361+ "builder that doesn't have a pathmapper."
1362+ )
1363+ file_path = builder .pathmapper .mapper (location )[0 ]
1364+ with fs_access .open (file_path , "rb" ) as f :
13491365 contents = f .read (1024 * 1024 )
13501366 while contents != b"" :
13511367 checksum .update (contents )
13521368 contents = f .read (1024 * 1024 )
13531369 fileobj ["checksum" ] = "sha1$%s" % checksum .hexdigest ()
1354- fileobj ["size" ] = fs_access .size (location )
1370+ fileobj ["size" ] = fs_access .size (file_path )
0 commit comments