z230
This commit is contained in:
20
70 MD5.py
20
70 MD5.py
@@ -5,6 +5,7 @@
|
|||||||
FAST MD5 indexer with in-memory cache
|
FAST MD5 indexer with in-memory cache
|
||||||
- prints every processed file
|
- prints every processed file
|
||||||
- skips unchanged files instantly
|
- skips unchanged files instantly
|
||||||
|
- restart-safe (no reprocessing same files)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@@ -60,7 +61,7 @@ def main():
|
|||||||
print("📥 Loading already indexed files into memory...")
|
print("📥 Loading already indexed files into memory...")
|
||||||
|
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT full_path, file_size, mtime
|
SELECT full_path, file_size, UNIX_TIMESTAMP(mtime)
|
||||||
FROM file_md5_index
|
FROM file_md5_index
|
||||||
""")
|
""")
|
||||||
|
|
||||||
@@ -84,11 +85,10 @@ def main():
|
|||||||
except (OSError, FileNotFoundError):
|
except (OSError, FileNotFoundError):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
key = (
|
mtime = int(stat.st_mtime)
|
||||||
full_path,
|
size = stat.st_size
|
||||||
stat.st_size,
|
|
||||||
datetime.fromtimestamp(stat.st_mtime),
|
key = (full_path, size, mtime)
|
||||||
)
|
|
||||||
|
|
||||||
# FAST PATH
|
# FAST PATH
|
||||||
if key in indexed:
|
if key in indexed:
|
||||||
@@ -99,7 +99,7 @@ def main():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
print("➕ NEW / UPDATED")
|
print("➕ NEW / UPDATED")
|
||||||
print(f" Size: {format_size(stat.st_size)}")
|
print(f" Size: {format_size(size)}")
|
||||||
print(f" File: {full_path}")
|
print(f" File: {full_path}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -111,7 +111,7 @@ def main():
|
|||||||
cur.execute("""
|
cur.execute("""
|
||||||
INSERT INTO file_md5_index
|
INSERT INTO file_md5_index
|
||||||
(full_path, file_name, directory, file_size, mtime, md5)
|
(full_path, file_name, directory, file_size, mtime, md5)
|
||||||
VALUES (%s, %s, %s, %s, %s, %s)
|
VALUES (%s, %s, %s, %s, FROM_UNIXTIME(%s), %s)
|
||||||
ON DUPLICATE KEY UPDATE
|
ON DUPLICATE KEY UPDATE
|
||||||
file_size=VALUES(file_size),
|
file_size=VALUES(file_size),
|
||||||
mtime=VALUES(mtime),
|
mtime=VALUES(mtime),
|
||||||
@@ -121,8 +121,8 @@ def main():
|
|||||||
full_path,
|
full_path,
|
||||||
fname,
|
fname,
|
||||||
root,
|
root,
|
||||||
stat.st_size,
|
size,
|
||||||
datetime.fromtimestamp(stat.st_mtime),
|
mtime,
|
||||||
md5,
|
md5,
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user