From 0b07abbac1efe22a761dc42282ec8f1db4fe202d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=9D=EC=A7=80=EC=98=81/=EC=B1=85=EC=9E=84=EC=97=B0?= =?UTF-8?q?=EA=B5=AC=EC=9B=90/SW=EA=B3=B5=ED=95=99=28=EC=97=B0=29Open=20So?= =?UTF-8?q?urce=20TP?= Date: Fri, 3 Jul 2026 11:23:32 +0900 Subject: [PATCH 1/2] fix(oss_item): fix checksum from file content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 석지영/책임연구원/SW공학(연)Open Source TP --- src/fosslight_util/oss_item.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/fosslight_util/oss_item.py b/src/fosslight_util/oss_item.py index 9895cea..cb7f632 100644 --- a/src/fosslight_util/oss_item.py +++ b/src/fosslight_util/oss_item.py @@ -177,15 +177,12 @@ def get_print_json(self): def get_checksum_sha1(source_name_or_path) -> str: checksum = CHECKSUM_NULL try: - checksum = str(hashlib.sha1(source_name_or_path.encode()).hexdigest()) - except Exception: - try: - f = open(source_name_or_path, "rb") - byte = f.read() - checksum = str(hashlib.sha1(byte).hexdigest()) - f.close() - except Exception as ex: - _logger.info(f"(Error) Get_checksum: {ex}") + if os.path.isfile(source_name_or_path): + with open(source_name_or_path, "rb") as f: + byte = f.read() + checksum = str(hashlib.sha1(byte).hexdigest()) + except Exception as ex: + _logger.debug(f"(Error) Get_checksum: {ex}") return checksum From e6895c9ccac76162ccd6d0b88866456734c06bdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=9D=EC=A7=80=EC=98=81/=EC=B1=85=EC=9E=84=EC=97=B0?= =?UTF-8?q?=EA=B5=AC=EC=9B=90/SW=EA=B3=B5=ED=95=99=28=EC=97=B0=29Open=20So?= =?UTF-8?q?urce=20TP?= Date: Fri, 3 Jul 2026 14:29:31 +0900 Subject: [PATCH 2/2] fix(oss_item): change file read method to chunk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 석지영/책임연구원/SW공학(연)Open Source TP --- src/fosslight_util/oss_item.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/fosslight_util/oss_item.py b/src/fosslight_util/oss_item.py index cb7f632..50e76d3 100644 --- a/src/fosslight_util/oss_item.py +++ b/src/fosslight_util/oss_item.py @@ -12,6 +12,7 @@ _logger = logging.getLogger(LOGGER_NAME) CHECKSUM_NULL = "0" +_CHECKSUM_CHUNK_SIZE = 1024 * 1024 # 1 MiB class OssItem: @@ -178,9 +179,11 @@ def get_checksum_sha1(source_name_or_path) -> str: checksum = CHECKSUM_NULL try: if os.path.isfile(source_name_or_path): - with open(source_name_or_path, "rb") as f: - byte = f.read() - checksum = str(hashlib.sha1(byte).hexdigest()) + sha1 = hashlib.sha1() + with open(source_name_or_path, 'rb') as f: + for chunk in iter(lambda: f.read(_CHECKSUM_CHUNK_SIZE), b''): + sha1.update(chunk) + checksum = sha1.hexdigest() except Exception as ex: _logger.debug(f"(Error) Get_checksum: {ex}")