node.js中的fs.lchmod方法使用说明


方法说明:

更改文件权限(不解析符号链接)。

语法:

fs.lchmod(fd, mode, [callback(err)])

由于该方法属于fs模块,使用前需要引入fs模块(var fs= require(“fs”) )

接收参数:

fd 文件描述符

mode 文件权限

callback 回调,传递异常参数err

例子:

fs.open('content.txt', 'a', function (err, fd) {

  if (err) {

    throw err;

  }

  fs.lchmod(fd, 0777, function(err){

 if (err) {

      throw err;

    }

 console.log('fchmod complete');

    fs.close(fd, function () {

      console.log('Done');

    });

  })

});

源码:

fs.lchmod = function(path, mode, callback) {

    callback = maybeCallback(callback);

    fs.open(path, constants.O_WRONLY | constants.O_SYMLINK, function(err, fd) {

      if (err) {

        callback(err);

        return;

      }

      // prefer to return the chmod error, if one occurs,

      // but still try to close, and report closing errors if they occur.

      fs.fchmod(fd, mode, function(err) {

        fs.close(fd, function(err2) {

          callback(err || err2);

        });

      });

    });

  };

node.js中的fs.lchmodSync方法使用说明
方法说明:同步版的lchmod()。语法:fs.lchmodSync(fd,mode)由于该方法属于fs模块,使用前需要引入fs模块(varfs=require(fs))接收参数:fd文件描述符mode文件权

node.js中的fs.fchmod方法使用说明
方法说明:更改文件权限(文件描述符)。语法:fs.fchmod(fd,mode,[callback(err)])由于该方法属于fs模块,使用前需要引入fs模块(varfs=require(fs))接收参数:f

node.js中的fs.fchmodSync方法使用说明
方法说明:同步版的fchmod()。语法:fs.fchmodSync(fd,mode)由于该方法属于fs模块,使用前需要引入fs模块(varfs=require(fs))接收参数:fd文件描述符mode文件权