问题描述
我对权限的理解今天已被破坏.
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/
我拥有CWD和mine
,并且对两者都有写权限.
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
我当然不能将目录移到他们的目录中;我在theirs
中没有写权限.
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
为什么不能将theirs
移到mine
?我可以编写CWD和目标(mine
).我没有以任何方式修改theirs
.
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)
如果我对其拥有写权限,则可以进行MV播放.
I can mv if I have write permission on theirs.
维基百科的解释是:
Arch Wiki声明类似,这似乎加强了我(显然是错误的)的理解.
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)
我尝试直接使用重命名(2).
I have tried to use rename(2) directly.
rename("theirs", "mine");
Works IFF mine
为空. -有效地取代了我的.如果我有文件; ENOTEMPTY 39 Directory not empty
.
Works IFF mine
is empty. - effectively mine is replaced my theirs. If mine has files; ENOTEMPTY 39 Directory not empty
.
rename("theirs", "mine/theirs");
给予EACCES 13 Permission denied
.这既是我想要做的,也是mv
所提供的-所以显然不是mv
中的错误(据我所知仍然是错误).
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).
推荐答案
我认为rename(2)手册页中的解释如下:
I think the rename(2) man page has the explanation:
ERRORS
EACCES Write permission is denied for the directory containing oldpath or newpath, or, search per‐
mission is denied for one of the directories in the path prefix of oldpath or newpath, or
oldpath is a directory and does not allow write permission (needed to update the ..
entry). (See also path_resolution(7).)
显然,为了将theirs
移到mine
,您需要具有更新theirs
上的..
链接的权限.
So apparently in order to move theirs
into mine
, you need to have permissions to update the ..
link on theirs
.
这篇关于为什么我的`mv`目录没有额外的写权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!