Currently posixpath.ismount uses realpath(join(path, '..')) to get the parent of the mount. This is absolutely overkill and should only be used when join(path, '..') isn't sufficient.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Let /mnt/storage/link be a link to /mnt, /mnt/storage is a mount point, and the original path is /mnt/storage/link/../mnt/storage. abspath() will return /mnt/storage/mnt/storage. dirname() will then return /mnt/storage/mnt which is on the same device as the original path, therefore ismount() will return False. But the real path is /mnt/storage, and it is a mount point.
Let /mnt/storage/link be a link to /mnt, /mnt/storage is a mount point, and the original path is /mnt/storage/link/../mnt/storage.
Actually, you can work around this: ismount(realpath('/mnt/storage/link/../mnt/storage')).
You couldn't remove realpath from the old implemenation, because that would raise a PermissionError.
If documented, I feel like this is a cleaner solution, what do you think?
Currently this workaround is built in ismount() (see bpo-2466). Your solution replaces realpath() with abspath(), but the latter is not suitable for this. realpath() is relatively expensive, so my solution only calls it if it is needed.
Activity
barneygale commented on Apr 1, 2024
Related to #96328
serhiy-storchaka commented on Apr 1, 2024
abspath is broken by design.
Let /mnt/storage/link be a link to /mnt, /mnt/storage is a mount point, and the original path is /mnt/storage/link/../mnt/storage. abspath() will return /mnt/storage/mnt/storage. dirname() will then return /mnt/storage/mnt which is on the same device as the original path, therefore ismount() will return False. But the real path is /mnt/storage, and it is a mount point.
nineteendo commented on Apr 1, 2024
Are you sure? ntpath.realpath() doesn't handle symlinks that way:
Does that work the same on Linux?
barneygale commented on Apr 1, 2024
It works differently on Linux - .. entries point to the real parent of a directory.
pythongh-117394: Speed up os.path.ismount() on Posix
serhiy-storchaka commented on Apr 2, 2024
#117447 is an alternate PR which achieves the same or better speed up.
nineteendo commented on Apr 2, 2024
Actually, you can work around this: ismount(realpath('/mnt/storage/link/../mnt/storage')).
You couldn't remove realpath from the old implemenation, because that would raise a PermissionError.
If documented, I feel like this is a cleaner solution, what do you think?
serhiy-storchaka commented on Apr 2, 2024
Currently this workaround is built in ismount() (see bpo-2466). Your solution replaces realpath() with abspath(), but the latter is not suitable for this. realpath() is relatively expensive, so my solution only calls it if it is needed.
gh-117394: Speed up os.path.ismount() on Posix (GH-117447)
pythongh-117394: Speed up os.path.ismount() on Posix (pythonGH-117447)