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
Path.glob() sometimes misses files that match #83075
Comments
I have observed this on a linux box running fedora29 $ python3 --version
Python 3.7.5
$ uname -a
Linux faraday.inria.fr 5.3.11-100.fc29.x86_64 #1 SMP Tue Nov 12 20:41:25 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/fedora-release
Fedora release 29 (Twenty Nine) ============ steps to reproduce: This assumes that /root is not readable by lambda users ----- as root: # mkdir /tmp/foo # ls -l ----- as a lambda user: we can see all files $ ls -l /tmp/foo
total 0
-rw-r--r-- 1 root root 0 Nov 22 14:51 a
-rw-r--r-- 1 root root 0 Nov 22 14:51 b
lrwxrwxrwx 1 root root 14 Nov 22 14:53 c -> /root/anywhere
-rw-r--r-- 1 root root 0 Nov 22 14:51 d
-rw-r--r-- 1 root root 0 Nov 22 14:51 e and with glob.glob() too In [1]: import glob In [2]: for filename in glob.glob("/tmp/foo/*"): BUT Path.glob() is not working as expected In [3]: from pathlib import Path In [4]: for filename in Path("/tmp/foo/").glob("*"): ----- If I now I go back as root and remove the problematic file in /tmp/foo # rm /tmp/foo/c ----- and try again as a lambda user In [5]: for filename in Path("/tmp/foo/").glob("*"): ============ discussion in my case in a real application I was getting *some* files - not an empty list like here. I ran strace on that real application ============ strace extract <snip> ==> that's the line about the broken symlink in my real app write(1, "/var/lib/rhubarbe-images/fedora-"..., 82/var/lib/rhubarbe-images/fedora-31.ndz |
to clarify, when I said 'lambda user' I mean regular, non-root user that has no permission to read in /root |
A simple test case for this issue: ~>mkdir tmp So far so good, but if the subdirectory isn't readable, things fall apart: tmp>chmod 000 subdir Looks like this is caused by entry.is_dir() in pathlib._WildcardSelector raising a PermissionError when trying to check if a symlink pointing into an unreadable directory is or isn't a directory. EACCESS isn't in IGNORED_ERROS (sic) and so the loop over directory entries is broken out of, and the "except PermissionError:" block in _select_from swallows the exception so that the failure is silent. |
Ok, I managed to reproduce. This seems a regression introduced by #11988 in issue https://bugs.python.org/issue36035. |
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: