Raise OSError(EINVAL) if the other path is within this path.
(source, target)
| 262 | |
| 263 | |
| 264 | def 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 | |
| 284 | def ensure_different_files(source, target): |