MCPcopy Index your code
hub / github.com/github/spec-kit / _validate_safe_shared_directory

Function _validate_safe_shared_directory

src/specify_cli/shared_infra.py:199–217  ·  view source on GitHub ↗

Validate existing directory parents while allowing missing directories.

(project_path: Path, directory: Path)

Source from the content-addressed store, hash-verified

197
198
199def _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
220def _ensure_safe_shared_destination(

Callers 1

Calls 4

_shared_relative_pathFunction · 0.85
resolveMethod · 0.45

Tested by

no test coverage detected