Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise exception on trying to compute MD5 sum of directory. #256

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doit/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def get_file_md5(path):
@param path: (string) file path
@return: (string) md5
"""
if os.path.isdir(path):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually this is probably not a good location for doing this check. check_modified was carefully implemented to avoid getting file_stat more than once. since this is a relatively expensive operation.

raise ValueError("Cannot compute MD5 sum of directory. You must "
"specify a file as a dependency instead.")
with open(path, 'rb') as file_data:
md5 = hashlib.md5()
block_size = 128 * md5.block_size
Expand Down
3 changes: 3 additions & 0 deletions tests/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def test_md5():
expected_crlf = "cf7b48b2fec3b581b135f7c9a1f7ae04"
assert get_file_md5(filePath) in {expected_lf, expected_crlf}

with pytest.raises(ValueError):
get_file_md5(os.path.dirname(filePath))


def test_sqlite_import():
"""
Expand Down