os.path.isdir strange behaviouring

Thomas Mangin thomasm at legend.co.uk
Tue Jun 20 10:54:06 EDT 2000


Aahz Maruch <aahz at netcom.com> wrote in message
news:8inrg6$mm2$1 at slb7.atl.mindspring.net...
> [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.

I still disagree I don't know if it is as I missexpressed myself
or if I misunderstood you.

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

I my case it IS a directory and I could be a file as the program is not able
to stat it but if the function is not able to perform its action properly
as a programmer I would like to know it

When you write this :

try:
    if not os.path.isfile(xx) and not os.path.isfile(xx):
        try:
            createDir(xx)
        except:
            print "creation failed"
exception:
    print "Dont have the right to access the directory"

A = 10
print a

You are not expecting `None` to appear to the screen as "a" is not defined.
You want to know a is not defined you want a error.

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

Yes, a pain, ;*) But I guess I have no choice.
I will have to write my own isfile() and isdir()

Thomas





More information about the Python-list mailing list