import os from datetime import datetime 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, PermissionError): continue rel_path = os.path.relpath(full_path, root_path).replace("\\", "/") rel_dir = os.path.relpath(root, root_path).replace("\\", "/") # Truncate microseconds — MySQL DATETIME rounds to whole seconds, # which causes false "modified" detections on every run. mtime = datetime.fromtimestamp(stat.st_mtime).replace(microsecond=0) result[rel_path] = { "full_path": full_path, "file_name": name, "directory": rel_dir, "size": stat.st_size, "mtime": mtime, } return result