2012/6/27 Cameron Simpson <c...@zip.com.au>: > On 27Jun2012 01:49, Giampaolo Rodolà <g.rod...@gmail.com> wrote: > | I've just noticed a strange behavior when dealing with gvfs filesystems: > | > | giampaolo@ubuntu:~$ python -c "import os; > | print(os.path.exists('/home/giampaolo/.gvfs'))" > | True > | giampaolo@ubuntu:~$ sudo su > | root@ubuntu:~# python -c "import os; > | print(os.path.exists('/home/giampaolo/.gvfs'))" > | False > | > | This is due to os.stat() which internally fails with PermissionError > (EACCES). > | The same problem exists with os.path.isdir() which will return True as > | limited user and False as root. > | I'm not sure what's best to do here nor I know if there are other > | cases other than when dealing with gvfs which can produce similar > | behaviors but here's an idea: > | > | - make os.path.exists() return True in case of PermissionError because > | that's supposed to mean there's an existing path to deny access to > > Definitely not. > > Firstly, if I ask about "a/b/c" and am denied access to "a/b", then it > would be a lie to say "c" exists - it may not.
Right, I wasn't taking that into account. > So I'd be +0.5 for making the docs more clear that True is reliable and > False may merely mean "could not access". +1. I was about to propose a 'strict' parameter which lets the exception propagate in case of errno != EACCES/EPERM but a doc fix is probably just fine. I'll file a bug report later today. Regards, --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ http://code.google.com/p/pysendfile/ _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com