[Python-ideas] Handling lack of permissions/groups with pathlib's rglob

Frank Woodall frankwoodall at gmail.com
Thu May 7 18:06:32 CEST 2015


Greetings,

I am attempting to use pathlib to recursively glob and/or find files. File
permissions and groups are all over the place due to poor management of the
filesystem which is out of my control.

The problem occurs when I lack both permissions and group membership to a
directory that rglob attempts to descend into. Rglob throws a KeyError and
then a PermissionError and finally stops entirely. I see no way to recover
gracefully from this and continue globbing. Is this the expected behavior
in this case?

The behavior that I want is for rglob to skip directories that I don't have
permissions on and to generate the list of everything that it saw/had
permissions on. The all or nothing nature isn't going to get me very far in
this particular case because I'm almost guaranteed to have bad permissions
on some directory or another on every run.

More specifics: Python: 3.4.1 (and 3.4.3) compiled from source for linux

Filesystem I am globbing on: automounted nfs share

How to reproduce:

mkdir /tmp/path_test && cd /tmp/path_test && mkdir dir1 dir2 dir2/dir3
&& touch dir1/file1 dir1/file2 dir2/file1 dir2/file2 dir2/dir3/file1
su
chmod 700 dir2/dir3/
chown root:root dir2/dir3/
exit

python 3.4.1

from pathlib import Path
p = Path('/tmp/path_test')
for x in p.rglob('*') : print(x)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150507/86c054e0/attachment.html>


More information about the Python-ideas mailing list