Description of the fs. lchmod method in node. js, node. jsfs. lchmod
Method description:
Change file permissions (do not parse symbolic links ).
Syntax:
Copy codeThe Code is as follows:
Fs. lchmod (fd, mode, [callback (err)])
Because this method belongs to the fs module, we need to introduce the fs module (var fs = require ("fs") before use "))
Receiving parameters:
Fd file descriptor
Mode File Permission
Callback, passing the exception parameter err
Example:
Copy codeThe Code is as follows:
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 ');
});
})
});
Source code:
Copy codeThe Code is as follows:
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 );
});
});
});
};