ObsiGate/backend/utils.py

37 lines
1.2 KiB
Python

"""Utility functions shared across backend modules."""
from typing import Dict, Any, Tuple
def should_include_path(rel_parts: Tuple[str, ...], vault_config: Dict[str, Any]) -> bool:
"""Check if a path should be included based on hidden files configuration.
Args:
rel_parts: Tuple of path parts relative to vault root
vault_config: Vault configuration dict with includeHidden and hiddenWhitelist
Returns:
True if the path should be included, False otherwise
"""
include_hidden = vault_config.get("includeHidden", False)
hidden_whitelist = vault_config.get("hiddenWhitelist", [])
# Check if any part of the path starts with a dot (hidden)
hidden_parts = [part for part in rel_parts if part.startswith(".")]
if not hidden_parts:
# No hidden parts, always include
return True
if include_hidden:
# Include all hidden files/folders
return True
# Check if ALL hidden parts are in the whitelist
# If any hidden part is NOT in the whitelist, exclude the path
for hidden_part in hidden_parts:
if hidden_part not in hidden_whitelist:
return False
# All hidden parts are in the whitelist
return True