Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 18th, 2005, 07:41 PM
Qiangning Hong
Guest
 
Posts: n/a
Default predict directory write permission under windows?

I want to know if I can write files into a directory before I actually
perferm the write behavor. I found os.access(path, os.W_OK) but it uses
real uid/gid to check instead of euid/egid so it doesn't fit my problem.

I don't know how to get euid/egid under windows so I cannot use the mode
infomation returned by os.stat().

Anybody give me a hint?




  #2  
Old July 18th, 2005, 07:41 PM
Christos TZOTZIOY Georgiou
Guest
 
Posts: n/a
Default Re: predict directory write permission under windows?

On Mon, 13 Dec 2004 22:14:03 +0800, rumours say that Qiangning Hong
<hongqn@gmail.com> might have written:
[color=blue]
>I want to know if I can write files into a directory before I actually
>perferm the write behavor. I found os.access(path, os.W_OK) but it uses
>real uid/gid to check instead of euid/egid so it doesn't fit my problem.[/color]

I didn't even know that the notion of effective uid/gid existed on
windows. Unless that's a "service" from the Run as a different user
service, but I wouldn't know.
[color=blue]
>I don't know how to get euid/egid under windows so I cannot use the mode
>infomation returned by os.stat().[/color]
[color=blue]
>Anybody give me a hint?[/color]

I won't be very helpful, but Python is mostly built around the
philosophy of asking forgiveness instead of permission (the opposite of
"look before you leap", which is what you want). There are other
typical arguments (what if permissions change between your check and the
actual write? what if the directory disappears before writing? etc)
which you might think they do not apply to you, but they most probably
do.

In case you want that to update some form of UI where the user should
know in advance, well, create a dummy file in the directory (and
instantly delete it) and report success or failure.

However, if you insist on knowing something that could be false, pywin32
might offer more functions to check for permissions.
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
  #3  
Old July 18th, 2005, 07:41 PM
Larry Bates
Guest
 
Posts: n/a
Default Re: predict directory write permission under windows?

My method isn't elegant, but I use tempfile to create a
tempfile in the directory (inside a try block). If it
works, closing the file makes it go away.

Larry Bates
Syscon, Inc.


Qiangning Hong wrote:[color=blue]
> I want to know if I can write files into a directory before I actually
> perferm the write behavor. I found os.access(path, os.W_OK) but it uses
> real uid/gid to check instead of euid/egid so it doesn't fit my problem.
>
> I don't know how to get euid/egid under windows so I cannot use the mode
> infomation returned by os.stat().
>
> Anybody give me a hint?
>[/color]
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.