Skip to content

Commit 77696fa

Browse files
committed
fs: improve error performance of fchownSync
1 parent a8c8d4b commit 77696fa

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

lib/fs.js

+3
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,9 @@ function fchown(fd, uid, gid, callback) {
20222022
* @returns {void}
20232023
*/
20242024
function fchownSync(fd, uid, gid) {
2025+
fd = getValidatedFd(fd);
2026+
validateInteger(uid, 'uid', -1, kMaxUserId);
2027+
validateInteger(gid, 'gid', -1, kMaxUserId);
20252028
return syncFs.fchown(fd, uid, gid);
20262029
}
20272030

lib/internal/fs/sync.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const {
99
getStatFsFromBinding,
1010
getValidatedFd,
1111
} = require('internal/fs/utils');
12-
const { parseFileMode, isInt32, validateInteger } = require('internal/validators');
12+
const { parseFileMode, isInt32 } = require('internal/validators');
1313

1414
const binding = internalBinding('fs');
1515

@@ -94,9 +94,6 @@ function unlink(path) {
9494
}
9595

9696
function fchown(fd, uid, gid) {
97-
fd = getValidatedFd(fd);
98-
validateInteger(uid, 'uid', -1);
99-
validateInteger(gid, 'gid', -1);
10097
return binding.fchownSync(fd, uid, gid);
10198
}
10299

src/node_file.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2814,7 +2814,7 @@ static void FChownSync(const FunctionCallbackInfo<Value>& args) {
28142814
CHECK_GE(argc, 3);
28152815

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

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

0 commit comments

Comments
 (0)