ajout de fonctionnalités
This commit is contained in:
+27
-2
@@ -582,6 +582,30 @@ def _remove_file_from_structures(vault_name: str, rel_path: str) -> Optional[Dic
|
||||
return removed
|
||||
|
||||
|
||||
def _ensure_parent_dirs_in_path_index(vault_name: str, rel_path: str, existing: set):
|
||||
"""Ensure all parent directories of a file path exist in path_index.
|
||||
|
||||
For a path like ``a/b/c/file.md``, ensures ``a``, ``a/b``, and ``a/b/c``
|
||||
directory entries exist in path_index.
|
||||
|
||||
Args:
|
||||
vault_name: Name of the vault.
|
||||
rel_path: Relative path of the file (e.g. ``a/b/c/file.md``).
|
||||
existing: Set of paths already in path_index for this vault.
|
||||
"""
|
||||
parts = rel_path.split("/")
|
||||
# Build parent directory paths
|
||||
for i in range(1, len(parts)):
|
||||
dir_path = "/".join(parts[:i])
|
||||
if dir_path and dir_path not in existing:
|
||||
existing.add(dir_path)
|
||||
path_index[vault_name].append({
|
||||
"path": dir_path,
|
||||
"name": parts[i - 1],
|
||||
"type": "directory",
|
||||
})
|
||||
|
||||
|
||||
def _add_file_to_structures(vault_name: str, file_info: Dict[str, Any]):
|
||||
"""Add a file entry to all index structures.
|
||||
|
||||
@@ -608,9 +632,8 @@ def _add_file_to_structures(vault_name: str, file_info: Dict[str, Any]):
|
||||
_file_lookup[key] = []
|
||||
_file_lookup[key].append(entry)
|
||||
|
||||
# Add to path_index
|
||||
# Add to path_index — also ensures parent directories are present
|
||||
if vault_name in path_index:
|
||||
# Check if already present (avoid duplicates)
|
||||
existing = {p["path"] for p in path_index[vault_name]}
|
||||
if rel_path not in existing:
|
||||
path_index[vault_name].append({
|
||||
@@ -618,6 +641,8 @@ def _add_file_to_structures(vault_name: str, file_info: Dict[str, Any]):
|
||||
"name": rel_path.rsplit("/", 1)[-1],
|
||||
"type": "file",
|
||||
})
|
||||
# Ensure all parent directories are in path_index
|
||||
_ensure_parent_dirs_in_path_index(vault_name, rel_path, existing)
|
||||
|
||||
_index_generation += 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user