MCPcopy
hub / github.com/psf/black / resolves_outside_root_or_cannot_stat

Function resolves_outside_root_or_cannot_stat

src/black/files.py:255–276  ·  view source on GitHub ↗

Returns whether the path is a symbolic link that points outside the root directory. Also returns True if we failed to resolve the path.

(
    path: Path,
    root: Path,
    report: Report | None = None,
)

Source from the content-addressed store, hash-verified

253
254
255def resolves_outside_root_or_cannot_stat(
256 path: Path,
257 root: Path,
258 report: Report | None = None,
259) -> bool:
260 """
261 Returns whether the path is a symbolic link that points outside the
262 root directory. Also returns True if we failed to resolve the path.
263 """
264 try:
265 resolved_path = _cached_resolve(path)
266 except OSError as e:
267 if report:
268 report.path_ignored(path, f"cannot be read because {e}")
269 return True
270 try:
271 resolved_path.relative_to(root)
272 except ValueError:
273 if report:
274 report.path_ignored(path, f"is a symbolic link that points outside {root}")
275 return True
276 return False
277
278
279def best_effort_relative_path(path: Path, root: Path) -> Path:

Callers 2

get_sourcesFunction · 0.90
gen_python_filesFunction · 0.85

Calls 2

_cached_resolveFunction · 0.85
path_ignoredMethod · 0.80

Tested by

no test coverage detected