Validate existing directory parents while allowing missing directories.
(project_path: Path, directory: Path)
| 197 | |
| 198 | |
| 199 | def _validate_safe_shared_directory(project_path: Path, directory: Path) -> None: |
| 200 | """Validate existing directory parents while allowing missing directories.""" |
| 201 | root = project_path.resolve() |
| 202 | rel = _shared_relative_path(project_path, directory) |
| 203 | current = project_path |
| 204 | |
| 205 | for part in rel.parts: |
| 206 | current = current / part |
| 207 | label = _shared_destination_label(project_path, current) |
| 208 | if current.is_symlink(): |
| 209 | raise SymlinkedSharedPathError(f"Refusing to use symlinked shared infrastructure directory: {label}") |
| 210 | if not current.exists(): |
| 211 | continue |
| 212 | if not current.is_dir(): |
| 213 | raise ValueError(f"Shared infrastructure directory path is not a directory: {label}") |
| 214 | try: |
| 215 | current.resolve().relative_to(root) |
| 216 | except (OSError, ValueError): |
| 217 | raise ValueError(f"Shared infrastructure directory escapes project root: {label}") from None |
| 218 | |
| 219 | |
| 220 | def _ensure_safe_shared_destination( |
no test coverage detected