mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:37:08 +00:00
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:
@@ -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:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user