Skip to content

Commit 0341f64

Browse files
committed
adding crypto argument to hash_dir (as in hash_file)
1 parent f8e817a commit 0341f64

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pydra/engine/helpers_file.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ def hash_file(afile, chunk_len=8192, crypto=sha256, raise_notfound=True):
8888

8989

9090
def hash_dir(
91-
dirpath, ignore_hidden_files=False, ignore_hidden_dirs=False, raise_notfound=True
91+
dirpath,
92+
crypto=sha256,
93+
ignore_hidden_files=False,
94+
ignore_hidden_dirs=False,
95+
raise_notfound=True,
9296
):
9397
"""Compute hash of directory contents.
9498
@@ -100,6 +104,8 @@ def hash_dir(
100104
----------
101105
dirpath : :obj:`str`
102106
Path to directory.
107+
crypto : :obj: `function`
108+
cryptographic hash functions
103109
ignore_hidden_files : :obj:`bool`
104110
If `True`, ignore filenames that begin with `.`.
105111
ignore_hidden_dirs : :obj:`bool`
@@ -136,11 +142,11 @@ def hash_dir(
136142
this_hash = hash_file(dpath / filename)
137143
file_hashes.append(this_hash)
138144

139-
sha = sha256()
145+
crypto_obj = crypto()
140146
for h in file_hashes:
141-
sha.update(h.encode())
147+
crypto_obj.update(h.encode())
142148

143-
return sha.hexdigest()
149+
return crypto_obj.hexdigest()
144150

145151

146152
def _parse_mount_table(exit_code, output):

0 commit comments

Comments
 (0)