This article mainly introduces node. fs. lchown method usage instructions. This article introduces fs. lchown method description, syntax, receive parameters, use instances, and implement source code. For more information, see
Method description:
Change file ownership (do not parse symbolic links ).
Syntax:
The code is as follows:
Fs. lchown (path, uid, gid, [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:
Path directory path
Uid user ID
Gid group identity (the identity of the user of the shared resource system)
Callback, passing the exception parameter err
Example:
The code 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 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 );
});
};