MCPcopy Index your code
hub / github.com/python/cpython / ensure_distinct_paths

Function ensure_distinct_paths

Lib/pathlib/_os.py:264–281  ·  view source on GitHub ↗

Raise OSError(EINVAL) if the other path is within this path.

(source, target)

Source from the content-addressed store, hash-verified

262
263
264def ensure_distinct_paths(source, target):
265 """
266 Raise OSError(EINVAL) if the other path is within this path.
267 """
268 # Note: there is no straightforward, foolproof algorithm to determine
269 # if one directory is within another (a particularly perverse example
270 # would be a single network share mounted in one location via NFS, and
271 # in another location via CIFS), so we simply checks whether the
272 # other path is lexically equal to, or within, this path.
273 if source == target:
274 err = OSError(EINVAL, "Source and target are the same path")
275 elif source in target.parents:
276 err = OSError(EINVAL, "Source path is a parent of target path")
277 else:
278 return
279 err.filename = vfspath(source)
280 err.filename2 = vfspath(target)
281 raise err
282
283
284def ensure_different_files(source, target):

Callers 2

copyMethod · 0.90
copyMethod · 0.90

Calls 1

vfspathFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…