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

Function ensure_different_files

Lib/pathlib/_os.py:284–303  ·  view source on GitHub ↗

Raise OSError(EINVAL) if both paths refer to the same file.

(source, target)

Source from the content-addressed store, hash-verified

282
283
284def ensure_different_files(source, target):
285 """
286 Raise OSError(EINVAL) if both paths refer to the same file.
287 """
288 try:
289 source_file_id = source.info._file_id
290 target_file_id = target.info._file_id
291 except AttributeError:
292 if source != target:
293 return
294 else:
295 try:
296 if source_file_id() != target_file_id():
297 return
298 except (OSError, ValueError):
299 return
300 err = OSError(EINVAL, "Source and target are the same file")
301 err.filename = vfspath(source)
302 err.filename2 = vfspath(target)
303 raise err

Callers 3

_copy_from_fileMethod · 0.90
moveMethod · 0.90
_copy_fromMethod · 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…