Skip to content

Commit 8575507

Browse files
fix(verifier): close file handle when computing checksum (#176)
Replace bare `open().read()` with a `with` block in `get_file_checksum()` so the file descriptor is released deterministically instead of waiting for garbage collection. Apply the same cleanup to `setup.py` for `README.md` and `CHANGELOG.md`. Co-authored-by: Tibor Šimko <tibor.simko@cern.ch>
1 parent 2fbd023 commit 8575507

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ The list of contributors in alphabetical order:
1313
- [Pablo Saiz](https://github.com/psaiz)
1414
- [Parth Shandilya](https://github.com/ParthS007)
1515
- [Tibor Simko](https://orcid.org/0000-0001-7202-5803)
16+
- [Zhuohang Shen](https://github.com/Stephen0512)

cernopendata_client/verifier.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# This file is part of cernopendata-client.
44
#
5-
# Copyright (C) 2020, 2025 CERN.
5+
# Copyright (C) 2020, 2025, 2026 CERN.
66
#
77
# cernopendata-client is free software; you can redistribute it and/or modify
88
# it under the terms of the GPLv3 license; see LICENSE file for more details.
@@ -38,9 +38,8 @@ def get_file_checksum(afile):
3838
:return: Adler32 checksum of file
3939
:rtype: str
4040
"""
41-
return "adler32:{:08x}".format(
42-
zlib.adler32(open(afile, "rb").read(), 1) & 0xFFFFFFFF
43-
)
41+
with open(afile, "rb") as f:
42+
return "adler32:{:08x}".format(zlib.adler32(f.read(), 1) & 0xFFFFFFFF)
4443

4544

4645
def get_file_info_local(recid):

setup.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# This file is part of cernopendata-client.
44
#
5-
# Copyright (C) 2019, 2020, 2021, 2022, 2023, 2024, 2025 CERN.
5+
# Copyright (C) 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026 CERN.
66
#
77
# cernopendata-client is free software; you can redistribute it and/or modify
88
# it under the terms of the GPLv3 license; see LICENSE file for more details.
@@ -13,9 +13,10 @@
1313

1414
from setuptools import setup
1515

16-
readme = open("README.md").read()
17-
history = open("CHANGELOG.md").read()
18-
16+
with open("README.md", "r") as f:
17+
readme = f.read()
18+
with open("CHANGELOG.md", "r") as f:
19+
history = f.read()
1920

2021
extras_require = {
2122
"docs": [

0 commit comments

Comments
 (0)