Forum Moderators: coopster

Message Too Old, No Replies

can delete function?

         

Nutter

3:09 pm on Jul 30, 2006 (gmt 0)

10+ Year Member



Is there a way to tell if a file can be deleted before trying the unlink() function?

What I'm trying to do is have the ability to delete a folder, but only if that entire folder can be deleted. I don't want to have the script delete half the files because of a permissions issue and leave the other half there. It would be better to leave the whole thing and return an error.

My thought is that is_writable should let me know. Can anyone confirm that? It seems that if the file has the right permissions for the script to overwrite it with nothing, it should have the permissions to remove the file.

My other idea if that doesn't work is to check permissions on every file, but I'm not sure whether it would take write or execute permissions to be able to delete a file.

mcavic

4:38 pm on Jul 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In order to delete files, the user only has to have write permission on the directory that they're in. And the directory must be set non-sticky (chmod nnn rather than 1nnn).

/tmp is usually set as sticky, but in most other cases, calling is_writable on the directory should tell you.

Nutter

5:35 pm on Jul 30, 2006 (gmt 0)

10+ Year Member



So do the permissions of the individual file matter for deletions, or is it just the parent folder?

mcavic

5:46 pm on Jul 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just the parent folder. The rationale is that you don't technically have to either view or modify a file in order to delete it.

Subfolders seem to work the same way. You can remove an empty directory even if you don't have write permission on it, but you still have to have write permission on the parent.