New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os.path.exists returns false negatives in MAC environments. #41538
Comments
In Mandatory Access Control environments (such as |
Logged In: YES Does 'access denied' always mean 'present but not readable' In any case, a reproducible example would help someone to |
Logged In: YES As far as I know (at least for SELinux), permission denied |
Logged In: YES I believe Terry was curious about something like |
Logged In: YES In the case of /etc/shadow/abc123, the stat will fail with One possible way around this is to attempt to get a listing |
hsoft-dev:~ hsoft$ mkdir foobar
hsoft-dev:~ hsoft$ echo "baz" > foobar/baz
hsoft-dev:~ hsoft$ chmod 000 foobar/baz
hsoft-dev:~ hsoft$ python
Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os.path
>>> os.path.exists('foobar/baz')
True
>>>
hsoft-dev:~ hsoft$ chmod 000 foobar
hsoft-dev:~ hsoft$ python
Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os.path
>>> os.path.exists('foobar/baz')
False
>>> os.path.exists('foobar')
True
>>> This seems like the correct behavior to me. |
The only sane alternative to the current behaviour would be to raise an If there is no other straightforward method than stat() to know if a |
Antoine, I think that when this bug was filed, the first So it's not that this bug shouldn't be fixed, but that it is already |
I also hit upon this issue and IMHO returning False in a "permission It also means I have no way to catch this edge case in my own code os.path.exists should absolutely raise a Permission exception. |
Previous comments suggest there is no agreement as to whether or not this is an oustanding bug. |
FWIW, I have just been experiencing this on CentOS 6.5 with Python 2.7.5 (sorry). I could make the Python code happy by running chcon[1] with the correct context type, otherwise os.path.exists would happily return False for a file that actually existed. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: