Method description:
Change file ownership (without parsing symbolic links).
grammar:
The code copy is as follows:
fs.lchown(path, uid, gid, [callback(err)])
Since this method belongs to the fs module, it is necessary to introduce the fs module before use (var fs= require("fs") )
Receive parameters:
path directory path
uid user ID
gid group identity (refers to the identity of the user of the shared resource system)
callback callback, passing exception parameter err
example:
The code copy is as follows:
fs.lchown('content.txt', uid, gid, function(err){
if(err){
console.log(err);
}else{
console.log("change done");
}
})
Source code:
The code copy is as follows:
fs.lchown = function(path, uid, gid, callback) {
callback = maybeCallback(callback);
fs.open(path, constants.O_WRONLY | constants.O_SYMLINK, function(err, fd) {
if (err) {
callback(err);
return;
}
fs.fchown(fd, uid, gid, callback);
});
};