This commit is contained in:
2026-02-09 20:16:37 +01:00
parent e7dd89962e
commit 9838164b88
9 changed files with 444 additions and 150 deletions

View File

@@ -1,21 +1,30 @@
import os
from datetime import datetime
from indexer.hasher import blake3_file
def scan_files(root_path):
def scan_files(root_path: str) -> dict:
"""
Projde celý adresářový strom a vrátí dict všech souborů.
Nehasuje obsah — to se dělá až pro změněné soubory.
Returns:
{relative_path: {full_path, file_name, directory, size, mtime}}
"""
result = {}
for root, _, files in os.walk(root_path):
for name in files:
full_path = os.path.join(root, name)
try:
stat = os.stat(full_path)
except FileNotFoundError:
except (FileNotFoundError, PermissionError):
continue
yield {
"full_path": full_path.replace("\\", "/"),
rel_path = os.path.relpath(full_path, root_path).replace("\\", "/")
rel_dir = os.path.relpath(root, root_path).replace("\\", "/")
result[rel_path] = {
"full_path": full_path,
"file_name": name,
"directory": root.replace("\\", "/"),
"directory": rel_dir,
"size": stat.st_size,
"mtime": datetime.fromtimestamp(stat.st_mtime),
"content_hash": blake3_file(full_path),
}
return result