os.path.isdir strange behaviouring

Aahz Maruch aahz at netcom.com
Tue Jun 20 09:27:34 EDT 2000


[BTW, please maintain attributions for quoted text; it makes it much
easier to keep track when multiple people are writing.]

In article <394f2d55.0 at katana.legend.co.uk>,
Thomas Mangin <thomasm at legend.co.uk> wrote:
>Attribution restored: Aahz
>>Attribution restored: Thomas Mangin
>>>
>>>I notice that if a directory is root owned and chmoded 700 (let say /test)
>>>and if it contain a directory called test2
>>>os.path.isdir("/test/test2") return 0 if called by a "normal user"
>>>I was expecting an exception.
>>
>> Why were you expecting an exception?
>
>I created few directories for my application as "myself" but I am running
>the script as a cgi.
>
>drwx------ thomas thomas  [somwehere in the world]/test
>drwx------ thomas thomas  [somwehere in the world]/test/test2
>
>my web server and I are different users,  as "nobody" have no read/go
>through access on the parent (test) directory I am checking, it can not even
>try to perform any action on the child one (test2).

But it's not performing any action on test or test2; it's performing an
action on the path /test/test2.  I believe it actually uses the OS call
stat(), but that doesn't really matter; the point is that whatever
internal function gets called on the *entire* path returns an error,
therefore the path cannot be a directory.

>Nothing with the current return code indicate that the test failed.
>I was just guessing : return 0 means no directory present, not enable to
>perform the requested action ..

It means that for whatever reason (permission denied or non-existence or
because it's a file), the path you gave isdir() is not a directory.  If
you want more information than that, you need to get it yourself.  More
than that, if you want to test individual path components, you have to
do that yourself, too.
--
                      --- Aahz (Copyright 2000 by aahz at netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"The only problem with Microsoft is they just have no taste." --Steve Jobs
(From _Triumph of the Nerds_ PBS special)



More information about the Python-list mailing list