Modify file hashing function.

We remove the inode from the hash as it is unstable when the
files are on an SMB filesystem, and replace it with an MD5
of the absolute file path.
This commit is contained in:
D. Berge
2022-02-07 15:51:38 +01:00
parent 75f91a9553
commit 53ed096e1b

View File

@@ -4,6 +4,7 @@ import psycopg2
import configuration import configuration
import preplots import preplots
import p111 import p111
from hashlib import md5 # Because it's good enough
""" """
Interface to the PostgreSQL database. Interface to the PostgreSQL database.
@@ -11,13 +12,16 @@ Interface to the PostgreSQL database.
def file_hash(file): def file_hash(file):
""" """
Calculate a file hash based on its size, inode, modification and creation times. Calculate a file hash based on its name, size, modification and creation times.
The hash is used to uniquely identify files in the database and detect if they The hash is used to uniquely identify files in the database and detect if they
have changed. have changed.
""" """
h = md5()
h.update(file.encode())
name_digest = h.hexdigest()[:16]
st = os.stat(file) st = os.stat(file)
return ":".join([str(v) for v in [st.st_size, st.st_mtime, st.st_ctime, st.st_ino]]) return ":".join([str(v) for v in [st.st_size, st.st_mtime, st.st_ctime, name_digest]])
class Datastore: class Datastore:
""" """