mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Remove the sha256_hash() utility function
This commit is contained in:
parent
19bb808936
commit
d924eaf4da
@ -1,3 +1,4 @@
|
|||||||
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import yaml
|
import yaml
|
||||||
@ -18,7 +19,6 @@ from netbox.constants import CENSOR_TOKEN, CENSOR_TOKEN_CHANGED
|
|||||||
from netbox.models import PrimaryModel
|
from netbox.models import PrimaryModel
|
||||||
from netbox.models.features import JobsMixin
|
from netbox.models.features import JobsMixin
|
||||||
from netbox.registry import registry
|
from netbox.registry import registry
|
||||||
from utilities.files import sha256_hash
|
|
||||||
from utilities.querysets import RestrictedQuerySet
|
from utilities.querysets import RestrictedQuerySet
|
||||||
from ..choices import *
|
from ..choices import *
|
||||||
from ..exceptions import SyncError
|
from ..exceptions import SyncError
|
||||||
@ -357,7 +357,8 @@ class DataFile(models.Model):
|
|||||||
has changed.
|
has changed.
|
||||||
"""
|
"""
|
||||||
file_path = os.path.join(source_root, self.path)
|
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
|
# Update instance file attributes & data
|
||||||
if is_modified := file_hash != self.hash:
|
if is_modified := file_hash != self.hash:
|
||||||
|
@ -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())
|
|
Loading…
Reference in New Issue
Block a user