Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
Handle closing files after reading for hashing (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonagestam authored Jun 5, 2020
1 parent eb0a280 commit ca1ac17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ lint:
sorti --check .
black --check .
mypy .

format:
sorti .
black .
8 changes: 7 additions & 1 deletion collectfast/strategies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ def get_gzipped_local_file_hash(
@lru_cache(maxsize=None)
def get_local_file_hash(self, path: str, local_storage: Storage) -> str:
"""Create md5 hash from file contents."""
contents = local_storage.open(path).read()
# Read file contents and handle file closing
file = local_storage.open(path)
try:
contents = file.read()
finally:
file.close()

file_hash = hashlib.md5(contents).hexdigest()

# Check if content should be gzipped and hash gzipped content
Expand Down

0 comments on commit ca1ac17

Please sign in to comment.