os.path.ismounts: further situations it doesn't detect correctly
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug report
I had a look at os.path.ismount():
https://github.com/python/cpython/blob/43a6deadbb40bc93e0eaebb3c56c34f8a3502132/Lib/posixpath.py#L186-L216
And it may have some issues:
- The documentation already says, that it isn't capable of detecting bind-mounts of some filesystem on the very same filesystem. While it's good that it mentions this, the results of
ismount()is IMO still simply wrong in these cases, cause it is a mountpoint. - The same problem in the detection algorithm is not only limited to bind-mounts, but also to any other mount points, where the path’s
st_devequals that of its parent. For example, btrfs subvolumes. This is however not documented.
Looking a the code, it effectively does: lstat(), check whether it’s a symlink, lstat() the parent, check whether the device numbers are different (then it's a mountpoint), check whether the inodes are the same.
Now I thought about the latter, and what it is meant for.
The only case I could think of at first is /, where /.. is the same inode. [Is there any other?]
- This however already requires, that not only the inodes are the same, but also the device numbers. which is given because of the order of these checks, however, I'd suggest to comment that accordingly.
- If the above were the only case, wouldn't it be faster to simply check the pathname for being
"/"orb"/". Would perhaps require somerealpath()though, to also catch things like"/../.."and so on. - However, I found that
/is not the only case: Within a chroot, the chroot's/may (or may not) be a mountpoint - the problem is just, the current algorithm doesn't detect this either. Instead, it wrongly claims that a chroot’s "/" would be a mountpoint, even when it isn't.
Not sure what one could do about all that… /etc/mtab is dead... /proc/mounts may not be available on all POSIX systems and even on Linux it's nowadays rather superseded by /proc/self/mountinfo.
Your environment
- CPython versions tested on: 3.10.6
- Operating system and architecture: Debian sid
Cheers,
Chris.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với os.path.ismount() trong Lib/posixpath.py, đặc biệt là phần triển khai được liên kết, và xem xét tài liệu của phần này. Tái hiện các trường hợp bind-mount, subvolume btrfs và chroot đã được báo cáo trên môi trường Debian đã nêu. Công việc được xem là hoàn tất khi có phương pháp phát hiện đã được thống nhất, hành vi được sửa đúng và tài liệu về các giới hạn còn lại của nền tảng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- operating-systems
- Loại issue
- Lỗi
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 30/100