From d924eaf4dad26bf0c2dcd465e347a95b781a5584 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 21 Mar 2024 10:15:59 -0400 Subject: [PATCH] Remove the sha256_hash() utility function --- netbox/core/models/data.py | 5 +++-- netbox/utilities/files.py | 13 ------------- 2 files changed, 3 insertions(+), 15 deletions(-) delete mode 100644 netbox/utilities/files.py diff --git a/netbox/core/models/data.py b/netbox/core/models/data.py index 4ceb22ba9..48fa2ff71 100644 --- a/netbox/core/models/data.py +++ b/netbox/core/models/data.py @@ -1,3 +1,4 @@ +import hashlib import logging import os import yaml @@ -18,7 +19,6 @@ from netbox.constants import CENSOR_TOKEN, CENSOR_TOKEN_CHANGED from netbox.models import PrimaryModel from netbox.models.features import JobsMixin from netbox.registry import registry -from utilities.files import sha256_hash from utilities.querysets import RestrictedQuerySet from ..choices import * from ..exceptions import SyncError @@ -357,7 +357,8 @@ class DataFile(models.Model): has changed. """ file_path = os.path.join(source_root, self.path) - file_hash = sha256_hash(file_path).hexdigest() + with open(file_path, 'rb') as f: + file_hash = hashlib.sha256(f.read()).hexdigest() # Update instance file attributes & data if is_modified := file_hash != self.hash: diff --git a/netbox/utilities/files.py b/netbox/utilities/files.py deleted file mode 100644 index 09ed2c90b..000000000 --- a/netbox/utilities/files.py +++ /dev/null @@ -1,13 +0,0 @@ -import hashlib - -__all__ = ( - 'sha256_hash', -) - - -def sha256_hash(filepath): - """ - Return the SHA256 hash of the file at the specified path. - """ - with open(filepath, 'rb') as f: - return hashlib.sha256(f.read())