Closed bbaldino closed 6 years ago
It looks like maybe it's just a missing call to checkAccess
around here? I'll take a shot at a PR with a change there and see how it goes.
It is my understanding that only a write permission on the parent directory is needed to delete a file. (And probably also the execute permission on all parents).
The following works for me
touch to-delete
chmod a-w to-delete
rm to-delete
https://en.wikipedia.org/wiki/Rm_(Unix)
Usually, on most filesystems, deleting a file requires write permission on the parent directory
When I try that, I get a prompt:
-r--r--r-- 1 bbaldino bbaldino 0 May 25 05:30 to-delete
bbaldino:/tmp$ rm to-delete
rm: remove write-protected regular empty file 'to-delete'? y
And it does delete it. Trying it from a different user gives the same prompt but fails even if they enter 'y'. So I guess it depends on the user doing the delete?
bbaldino:/tmp$ touch to-delete
bbaldino:/tmp$ chmod a-w to-delete
bbaldino:/tmp$ sudo su other_user
other_user:/tmp$ rm to-delete
rm: remove write-protected regular empty file 'to-delete'? y
rm: cannot remove 'to-delete': Operation not permitted
Even though the containing directory (tmp) is
drwxrwxrwt 239 root root 20480 May 25 05:35 tmp
EDIT: Interesting! The bit right after what you pasted explains it I guess:
(Note that, confusingly for beginners, permissions on the file itself are irrelevant. However, GNU rm asks for confirmation if a write-protected file is to be deleted, unless the -f option is used.)
Good to know, that does seem counterintuitive but I guess no bug here. Though wonder why it doesn't work for the other user.
Thanks for the great library, saved me when testing some complicated filesystem interactions.
Yeah, UNIX permission can be confusing at first.
Though wonder why it doesn't work for the other user.
Does the other have execute permission on all parent folders?
You're welcome.
Though wonder why it doesn't work for the other user.
Does the other have execute permission on all parent folders?
Yeah this was in /tmp
/ so tmp was the only parent.
Yeah this was in
/tmp/
so tmp was the only parent.
Strictly speaking /
as well but the other user will have execute permission there as well.
Given the following code:
It will print:
So even though the file only has read permissions, it can still be deleted.