os.access() under windows

Tim Golden mail at timgolden.me.uk
Mon Dec 3 09:56:09 EST 2007


Tim Golden wrote:
> Yann Leboulanger wrote:
>> Martin v. Löwis a écrit :
>>>> I create a folder test under e:
>>>>
>>>> then os.access('e:\\test', os.W_OK) returns True. Everything's ok.
>>>>
>>>> Now I move My Documents to this e:\test folder
>>>>
>>>> Then os.access('e:\\test', os.W_OK) returns False !!
>>> This description is, unfortunately, too imprecise to allow reproducing
>>> that effect. What precisely do you mean by "I move My Documents to
>>> this e:\test folder"?
>>>
>>
>> I Right click on "My Documents" folder, and change the path to e:\test 
>> there.
>> So that "My documents" folder points to e:\test
> 
> Python uses the GetFileAttributesW API call to determine
> access to the path you pass in. It then tests the return
> against the FILE_ATTRIBUTE_READONLY flag and returns False
> if you asked for Write and the Readonly flag is set.
> 
> The problem seems to be twofold: whereas a normal directory
> (such as e:\temp) will not usually have its readonly flag set,
> on a special directory such as the My Documents folder the flag
> seems to be set by the system; also, the READONLY flag on a
> directory refers to its deleteability, not to its writeablility.
> At least, according to:
> 
> http://msdn2.microsoft.com/en-us/library/aa364944.aspx
> 
> I suspect this constitutes a bug in os.access which
> should do some more interpretation of the results. But
> no doubt Martin von L can comment with more authority
> than I on this one.
> 
> TJG

And just to complicate matters, it seems that readonly on
a folder has an entirely special meaning. At least, according
to this:

http://support.microsoft.com/kb/326549

Goodness knows what we're supposed to do with that.
Part of the issue here is that we're using a Unix-style
access API against Windows-style filesystem semantics.
According to the man pages, it looks as though it basically
checks the standard security bits against whatever you're
asking for for your user. On Windows, the security semantics
are quite different and you have to make some kind of
decision as to what the os.access means.

I'm happy to contribute a doc patch if I can imagine what
exactly to write.

TJG



More information about the Python-list mailing list