Skip to content

Commit

Permalink
utils: sort dirs upon hash calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidalgarcia committed Nov 23, 2020
1 parent a48dcd8 commit 24fd766
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion reana_commons/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ def calculate_hash_of_dir(directory, file_list=None):
if not os.path.exists(directory):
return -1

sorted_by_dirs = sorted(list(os.walk(directory)), key=lambda x: x[2])
try:
for subdir, dirs, files in os.walk(directory):
for subdir, dirs, files in sorted_by_dirs:
for _file in files:
file_path = os.path.join(subdir, _file)
if file_list is not None and file_path not in file_list:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_calculate_hash_of_dir(sample_workflow_workspace): # noqa: F811
assert non_existing_dir_hash == -1
sample_workflow_workspace_path = next(sample_workflow_workspace("sample"))
dir_hash = calculate_hash_of_dir(sample_workflow_workspace_path)
assert dir_hash == "8d287a3e2240b1762862d485a424363c"
assert dir_hash == "cb2669b4d7651aa717b6952fce85575f"
include_only_path = os.path.join(
sample_workflow_workspace_path, "code", "worldpopulation.ipynb"
)
Expand Down

0 comments on commit 24fd766

Please sign in to comment.