如何在保留 inode 的同时更改符号链接目标
通常,要更改符号链接目标,首先会取消链接文件,然后使用新的目标路径重新创建符号链接。但是,它将被分配一个新的索引节点号。
也许有一个带有 update_target_for_symlink()
函数的私有 Mac api,因此 inode 可以保持不变?
如果你想知道我需要它做什么......文件管理器。我怀疑这是否可能。无论如何,这就是让它变得有趣的原因。
Normally to change a symlink target one will first unlink the file and then re-creating the symlink with the new target path. However it will be assigned a new inode number.
Maybe there is a private Mac api with an update_target_for_symlink()
function, so the inode can stay the same?
In case you wonder what I need it for.. a file manager. I doubt that this is possible at all. Anyways thats what makes it interesting.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来这根本不可能。
It looks a lot like this isn't possible at all.
链接是与索引节点关联的附加名称。因此,不可能重新定位链接,因为链接不是针对文件的唯一对象。它更像是文件的辅助名称。
这就是为什么您必须首先取消链接(删除与文件关联的名称),然后创建到新文件的新链接(添加附加名称)。
链接的Inode不属于链接,它属于文件。文件由名称列表(“链接”)、标识符(索引节点)和一堆包含文件内容的数据块组成。
符号链接应该可以重命名,因为它仅引用文件的文本名称。
根据手册:有九个系统调用不遵循链接,而是对符号链接本身进行操作。它们是:lchflags(2)、lchmod(2)、lchown(2)、lstat(2)、lutimes(2)、readlink(2)、rename(2)、rmdir(2) 和 unlink(2)。
A link is an additional name associated with the inode. So there is no possibility to retarget a link since the link is not a unique object targeting a file. It is more a secondary name of a file.
Thats why you have to unlink it first (delete the name associated with the file) and then create a new link (add a additional name) to the new file.
The Inode of the link does not belong to the link, it belongs to the file. A file consists of list of names("links"), an identifier (inode) and a bunch of data blocks containing the file contents.
A symlink should be possible to rename, cause it only refers to the text name of a file.
From manual: There are nine system calls that do not follow links, and which operate on the symbolic link itself. They are: lchflags(2), lchmod(2), lchown(2), lstat(2), lutimes(2), readlink(2), rename(2), rmdir(2), and unlink(2).
仔细一看, ln -sf 似乎做了你想做的事。
第一列是索引节点号。请注意它没有改变:
看起来 ln-sf 仅使用 unlink() 和 symlink() 来完成此操作:
Upon looking closer, ln -sf seems to do what you want.
The first column is the inode number. Note it doesn't change:
It looks like ln-sf uses simply unlink() and symlink() to accomplish this: