Просмотр исходного кода

Remove the sha256_hash() utility function

Jeremy Stretch 1 год назад
Родитель
Сommit
d924eaf4da
2 измененных файлов с 3 добавлено и 15 удалено
  1. 3 2
      netbox/core/models/data.py
  2. 0 13
      netbox/utilities/files.py

+ 3 - 2
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:

+ 0 - 13
netbox/utilities/files.py

@@ -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())