My understanding of permissions has been broken today.
evaben@evaben /t/test> ll
total 16K
drwxr-xr-x 4 evaben evaben 4.0K Mar 13 12:44 ./
drwxrwxrwt 19 root root 4.0K Mar 13 12:43 ../
drwxr-xr-x 2 evaben evaben 4.0K Mar 13 12:44 mine/
drwxr-xr-x 2 root root 4.0K Mar 13 12:44 theirs/
I own the CWD, and mine
, and have write permission on both.
evaben@evaben /t/test> mv mine theirs/
mv: cannot move 'mine' to 'theirs/mine': Permission denied
Of course I cannot move my directory into theirs; I do not have write permission in theirs
.
evaben@evaben /t/test [1]> mv theirs/ mine/
mv: cannot move 'theirs/' to 'mine/theirs': Permission denied
Why can't I move theirs
into mine
? I can write the CWD, AND the dest (mine
). I am not modifying theirs
in any way.
evaben@evaben /t/test [1]> sudo chmod o+w theirs/
evaben@evaben /t/test> mv theirs/ mine/
(works)
I can mv if I have write permission on theirs.
The wikipedia explanation states:
When set for a directory, this (write) permission grants the ability to modify entries in the directory, which includes creating files, deleting files, and renaming files.
Arch wiki states similar, which seems to reinforce my (clearly wrong) understanding.
To further cloud my brain, it works as I expect for a file:
evaben@evaben /t/test> ll
total 12K
drwxr-xr-x 3 evaben evaben 4.0K Mar 13 13:04 ./
drwxrwxrwt 19 root root 4.0K Mar 13 12:43 ../
drwxr-xr-x 3 evaben evaben 4.0K Mar 13 13:03 mine/
-rw-r--r-- 1 root root 0 Mar 13 13:04 their_file
evaben@evaben /t/test> mv their_file mine/
(worked)
EDIT:
I have tried to use rename(2) directly.
rename("theirs", "mine");
Works IFF mine
is empty. - effectively mine is replaced my theirs. If mine has files; ENOTEMPTY 39 Directory not empty
.
rename("theirs", "mine/theirs");
Gives EACCES 13 Permission denied
. Which is both what I want to do and what mv
gives - so apparently not a bug in mv
(still a bug in my understanding).
Not quite correct. Part of the
mv
process is deleting the file from its original location. Which means you need write permission for that original location, which you don't have. Try usingcp
instead.I think the rename(2) man page has the explanation:
So apparently in order to move
theirs
intomine
, you need to have permissions to update the..
link ontheirs
.