msg288863 - (view) |
Author: ollieparanoid (Oliver Smith) |
Date: 2017-03-03 07:09 |
After mounting a folder to another folder on the same filesystem with mount --bind, os.path.ismount() still returns False on the destination folder (although there is a mountpoint). A shell script to reproduce this is below. (Maybe this can be fixed by using /proc/mounts (if available, may not be the case eg. for chroots) for verifying, if the destination folder is really a mountpoint on POSIX/Linux. Although I am not sure how consistent that is through POSIX.) --- #!/bin/sh # Output: # contents of /tmp/destination (should have test.py -> obviously mounted): # test.py # os.path.ismount(): False # create source and destination folders source=/tmp/source destination=/tmp/destination mkdir -p sourcesource sourcedestination # add the python script in the source folder echo "import os.path" >> source/test.pyecho"print(′os.path.ismount():′+str(os.path.ismount(′source/test.py echo "print('os.path.ismount(): ' + str(os.path.ismount('source/test.pyecho"print(′os.path.ismount():′+str(os.path.ismount(′destination')))" >> source/test.py#dothemount−−bindsudomount−−bindsource/test.py # do the mount --bind sudo mount --bind source/test.py#dothemount−−bindsudomount−−bindsource destinationecho"contentsofdestination echo "contents of destinationecho"contentsofdestination (should have test.py -> obviously mounted):" ls destination#showthepythonbugpython3destination # show the python bug python3 destination#showthepythonbugpython3source/test.py # clean up sudo umount destinationrmdestination rm destinationrmsource/test.py rm -d sourcesource sourcedestination |
|
|
msg301053 - (view) |
Author: Alex Richman (Alex Richman) |
Date: 2017-08-31 17:30 |
Can confirm, ran into this issue. It's because os.path.ismount() works by checking if the path's parent is on a different device (e.g. st_dev is the same for 'path/' and 'path/..'), which obviously it is for a bind mount on the same filesystem. It is actually documented that this is how it works (https://docs.python.org/2/library/os.path.html#os.path.ismount) but it's more of a passing comment than a warning, and who reads the docs for such an apparently simple function anyway? ;) Agree that it should be fixed by parsing /proc/mounts instead of the current mess, perhaps using getmntent(3) and friends. |
|
|
msg331908 - (view) |
Author: Eryk Sun (eryksun) *  |
Date: 2018-12-15 22:05 |
It's also inconsistent. ismount() is true for a bind mount to the parent directory (e.g. dir/mount -> dir). |
|
|
msg331921 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2018-12-16 09:03 |
I do not think that we should use /proc/mounts or getmntent ,because they are not portable. os.path.ismount() uses the traditional way to detect mountpoints which is not able to detect bind mounts. But what is the problem with getting False for bind mounts on the same filesystem? |
|
|
msg331922 - (view) |
Author: Eryk Sun (eryksun) *  |
Date: 2018-12-16 09:51 |
> what is the problem with getting False for bind mounts > on the same filesystem? Probably there's no problem if it's consistently false for all bind mounts on the same file system, but ismount() is true for a bind mount to the parent directory on the same file system, since the inodes match. |
|
|
msg332137 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2018-12-19 13:19 |
I am not sure that we need to change ismount(), but its behavior should be documented. |
|
|
msg333652 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2019-01-15 08:55 |
New changeset 32ebd8508d4807a7c85d2ed8e9c3b44ecd6de591 by Serhiy Storchaka in branch 'master': bpo-29707: Document that os.path.ismount() is not able to reliable detect bind mounts. (GH-11238) https://github.com/python/cpython/commit/32ebd8508d4807a7c85d2ed8e9c3b44ecd6de591 |
|
|
msg333653 - (view) |
Author: miss-islington (miss-islington) |
Date: 2019-01-15 09:01 |
New changeset a4aade2cf82dfa889c2bdad9fa0aa874f43c0bf8 by Miss Islington (bot) in branch '3.7': bpo-29707: Document that os.path.ismount() is not able to reliable detect bind mounts. (GH-11238) https://github.com/python/cpython/commit/a4aade2cf82dfa889c2bdad9fa0aa874f43c0bf8 |
|
|
msg339751 - (view) |
Author: Cheryl Sabella (cheryl.sabella) *  |
Date: 2019-04-09 13:53 |
Can this be closed as a documentation only change? Thanks! |
|
|
msg339752 - (view) |
Author: Christian Heimes (christian.heimes) *  |
Date: 2019-04-09 14:02 |
Yes, it can be closed as doc-only fix. |
|
|
msg361367 - (view) |
Author: Mikko Korkalo (Mikko Korkalo) |
Date: 2020-02-04 20:36 |
I disagree about whether this should be fixed or not. It's definitely a bug. If you ask whether a bind mount destination is a mount, it should return true. I wrote a logic that does bind mounting. The logic cannot use ismount() because it does not work for me, it would keep remounting the same bind mount. Not fixing this just causes people to write even less portable hackery on their own. I have to parse /proc/mounts or something manually, which obviously should be the job of ismount(). Python has a lot of platform-specific underlying implementations anyway. |
|
|
msg392763 - (view) |
Author: R0b0t1 (R0b0t1) |
Date: 2021-05-03 04:01 |
https://bugs.python.org/issue29707#msg331921 > But what is the problem with getting False for bind mounts on the same filesystem? When doing directory traversal it is important to not duplicate listings. It seems this can cause duplication. I'm replying to echo Mikko Korkalo's sentiment, this really should not have been closed. This should likely be addressed along with https://bugs.python.org/issue23407. |
|
|