Skip to content

Commit

Permalink
fs: improve error performance of fchownSync
Browse files Browse the repository at this point in the history
  • Loading branch information
evelez7 committed Sep 29, 2023
1 parent a8c8d4b commit 77696fa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,9 @@ function fchown(fd, uid, gid, callback) {
* @returns {void}
*/
function fchownSync(fd, uid, gid) {
fd = getValidatedFd(fd);
validateInteger(uid, 'uid', -1, kMaxUserId);
validateInteger(gid, 'gid', -1, kMaxUserId);
return syncFs.fchown(fd, uid, gid);
}

Expand Down
5 changes: 1 addition & 4 deletions lib/internal/fs/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
getStatFsFromBinding,
getValidatedFd,
} = require('internal/fs/utils');
const { parseFileMode, isInt32, validateInteger } = require('internal/validators');
const { parseFileMode, isInt32 } = require('internal/validators');

const binding = internalBinding('fs');

Expand Down Expand Up @@ -94,9 +94,6 @@ function unlink(path) {
}

function fchown(fd, uid, gid) {
fd = getValidatedFd(fd);
validateInteger(uid, 'uid', -1);
validateInteger(gid, 'gid', -1);
return binding.fchownSync(fd, uid, gid);
}

Expand Down
2 changes: 1 addition & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2814,7 +2814,7 @@ static void FChownSync(const FunctionCallbackInfo<Value>& args) {
CHECK_GE(argc, 3);

CHECK(args[0]->IsInt32());
const uv_gid_t fd = static_cast<uv_gid_t>(args[0].As<Int32>()->Value());
const uv_file fd = static_cast<uv_file>(args[0].As<Int32>()->Value());

CHECK(args[1]->IsInt32());
const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Int32>()->Value());
Expand Down

0 comments on commit 77696fa

Please sign in to comment.