Raise OSError(EINVAL) if the other path is within this path.
(source, target)
| 211 | |
| 212 | |
| 213 | def ensure_distinct_paths(source, target): |
| 214 | """ |
| 215 | Raise OSError(EINVAL) if the other path is within this path. |
| 216 | """ |
| 217 | # Note: there is no straightforward, foolproof algorithm to determine |
| 218 | # if one directory is within another (a particularly perverse example |
| 219 | # would be a single network share mounted in one location via NFS, and |
| 220 | # in another location via CIFS), so we simply checks whether the |
| 221 | # other path is lexically equal to, or within, this path. |
| 222 | if source == target: |
| 223 | err = OSError(EINVAL, "Source and target are the same path") |
| 224 | elif source in target.parents: |
| 225 | err = OSError(EINVAL, "Source path is a parent of target path") |
| 226 | else: |
| 227 | return |
| 228 | err.filename = str(source) |
| 229 | err.filename2 = str(target) |
| 230 | raise err |
| 231 | |
| 232 | |
| 233 | def ensure_different_files(source, target): |