对不起新手问题.我想知道,vim如何设法写一个只读文件.我对文本文件有555个权限.但是,当我打开&写点什么,然后:w!,我对文件所做的更改已保存.我想知道vim是如何在后台做这个的!!是暂时将权限更改为755并写入并恢复权限?请指教.
解决方法
编辑:我最初回答了有关UNIX权限如何工作的正确但最终无关的信息:这不是Vim正在做的事情.
确实,你是对的:当你发布:w!,并且你在UNIX上时,如果需要,Vim将添加写权限:
/* When using ":w!" and the file was read-only: make it writable */ if (forceit && perm >= 0 && !(perm & 0200) && st_old.st_uid == getuid() && vim_strchr(p_cpo,CPO_FWRITE) == NULL) { perm |= 0200; (void)mch_setperm(fname,perm); made_writable = TRUE; }
然后重新将其重置:
if (made_writable) perm &= ~0200; /* reset 'w' bit for security reasons */
它也反映在帮助中:
Note: This may change the permission and ownership of the file and break (symbolic) links. Add the ‘W’ flag to ‘cpoptions’ to avoid this.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。