in reply to Overwrite file protection
Note that there's a race condition in this technique. User 1 uploads a file called "hello", it doesn't exist, we fall out of the if statement, then User 1's process goes to sleep. User 2 logs in, uploads a file called "hello", it doesn't exist, we fall out, and User 2's process creates hello. Now User 1 wakes back up, and happily overwrites User 2's hello.
To solve this (with has nothing to do with your original question, I know) you'll need to use sysopen with the O_EXCL flag, use some kind of file locking, or else write to a temp file with a unique name and use link to rename it to the ~1-style name.
|
|---|