Windows上的节点文件模式? [英] Node file modes on Windows?

查看:127
本文介绍了Windows上的节点文件模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

节点中,文件模式(例如在POSIX世界(一个三位八进制值)的条款。但是,这并不能映射到Windows如何执行操作。 Windows在用户权限和文件系统之间没有如此紧密的耦合。 Windows' OpenFile 功能甚至没有任何相关的参数。但是从目前我收集到的信息来看,它们并没有完全忽略。



有没有关于如何在Windows上使用Node文件模式的解释?

解决方案

请看来源。它似乎是他们正在做的唯一的事情是设置FILE_ATTRIBUTE_READONLY基于文件是否可写。

  if(flags& amp; amp; ;(!req-> mode&〜current_umask)& _S_IWRITE)){
attributes | = FILE_ATTRIBUTE_READONLY; _O_CREAT){
if


$ / code $ / pre

fs.chmod上的注释也很有趣。

  / *待办事项:st_mode对于每个人来说可能总是0666。如果文件是一个.exe或一个目录,我们也可能
*要报告0777。
*
*目前它基于是否设置'readonly'属性,哪个
*没有意义,因为语义是如此不同:'只读'
*标志只是用户防止意外删除的一种方式,
*不起任何安全作用。 Windows使用ACL。
*
*此外,人们现在使用uv_fs_chmod()来取消
*原因的可写位。然而,Windows只是使文件成为只读文件,这使得
*不可能随后删除文件,因为只读文件不能被
*删除。
*
* IOW这些都只是一个clusterfuck,我们应该想到
*使得稍微有点意义。
*
*而uv_fs_chmod可能只是在Windows上失败,或者是一个完全没有操作。
*无论如何,没有任何明智的做法。
* /


In Node, file modes (e.g. for fs.open) are defined in the terms of the POSIX world (a three-digit octal value). However, that does not map to how Windows does things. Windows does not have such tight coupling between user permissions and the filesystem. Windows' OpenFile function does not even have any related parameters. But from what I gathered so far, they are not entirely ignored either.

Is there any explanation on how to use Node file modes on Windows?

解决方案

Take a look at the source. It seems like the only thing they are doing is setting FILE_ATTRIBUTE_READONLY based on whether the file is writeable or not.

  if (flags & _O_CREAT) {
    if (!((req->mode & ~current_umask) & _S_IWRITE)) {
      attributes |= FILE_ATTRIBUTE_READONLY;
    }
  }

The notes on fs.chmod are interesting as well.

  /* Todo: st_mode should probably always be 0666 for everyone. We might also
   * want to report 0777 if the file is a .exe or a directory.
   *
   * Currently it's based on whether the 'readonly' attribute is set, which
   * makes little sense because the semantics are so different: the 'read-only'
   * flag is just a way for a user to protect against accidental deleteion, and
   * serves no security purpose. Windows uses ACLs for that.
   *
   * Also people now use uv_fs_chmod() to take away the writable bit for good
   * reasons. Windows however just makes the file read-only, which makes it
   * impossible to delete the file afterwards, since read-only files can't be
   * deleted.
   *
   * IOW it's all just a clusterfuck and we should think of something that
   * makes slighty more sense.
   *
   * And uv_fs_chmod should probably just fail on windows or be a total no-op.
   * There's nothing sensible it can do anyway.
   */

这篇关于Windows上的节点文件模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆