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

Antoine Pitrou solipsis at pitrou.net
Thu May 7 18:23:24 CEST 2015


Hello Frank,

On Thu, 7 May 2015 12:06:32 -0400
Frank Woodall <frankwoodall at gmail.com>
wrote:
> 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?

It is not unexpected :) Actually, this case was simply not envisioned.
I agree that being more laxist could be convenient here.

If you want to provide a patch for this, you can start at
https://docs.python.org/devguide/

Regards

Antoine.


> 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)
> 




More information about the Python-ideas mailing list