Return the canonical path (realpath) if it is accessible from the userspace. Otherwise (for example, if the path is a symlink to an anonymous pipe), return the original path. See GH-142315.
(path)
| 209 | |
| 210 | @staticmethod |
| 211 | def _safe_realpath(path): |
| 212 | """ |
| 213 | Return the canonical path (realpath) if it is accessible from the userspace. |
| 214 | Otherwise (for example, if the path is a symlink to an anonymous pipe), |
| 215 | return the original path. |
| 216 | |
| 217 | See GH-142315. |
| 218 | """ |
| 219 | realpath = os.path.realpath(path) |
| 220 | return realpath if os.path.exists(realpath) else path |
| 221 | |
| 222 | def __repr__(self): |
| 223 | return self._target |