views:

493

answers:

2

I know of two methods which are not reliable:

  • _access() - doesn't work on directories (only checks existence)
  • CreateFile() - gives false positives in the presence of virtual store (AFAIK)

Most useful would be a code sample, because the win32 ACL access functions are extremely complicated. Please don't post links to msdn, I've been there and can't for the life of me figure out what I'm supposed to do with all those DACLs, SACLs and security descriptors - I work on a cross-platform app which needs this particular piece of functionality, but otherwise is platform-agnostic. Solutions simpler than accessing Windows ACLs more than welcome.

Edit: you can safely assume that directory permissions won't change while the app is running.

A: 

There is no reliable method, on any operating system, because the permissions can be changed between testing them and actually writing a file.

anon
yes, and it doesn't matter, i can assume a _sane_ working environment for the app.
Baczek
It does matter - the only way to check that a file can be succesfully written is to write the file.
anon
and it'll end up in the virtual store due to some idiotic idea someone at MS had, which i've already written about in the post...
Baczek
The "idiotic idea" wasn't idiotic. It was to prevent the end users from having tons of non-working software because stupid developers didn't bother to follow the guidelines about where their apps could read and write. Pointless MS bashing because you don't understand isn't very smart; nor is being rude to people who are trying to answer your questions. It makes them less willing to try and help you in the future.
Ken White
+4  A: 

you can disable location virtualization for your application in a manifest file (http://www.codeguru.com/csharp/csharp/cs_misc/designtechniques/article.php/c15455/) - this should make CreateFile reliable enough for your purposes.

Andrey