Skip to content

Commit 50a3fe2

Browse files
committed
lib: rename validateMode to parseMode
The function did not only validate the mode but it returns a new value depending on the input. Thus `validate` did not seem to be an appropriate name. PR-URL: #26809 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 9d854fb commit 50a3fe2

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

lib/fs.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const {
8080
} = require('internal/constants');
8181
const {
8282
isUint32,
83-
validateMode,
83+
parseMode,
8484
validateInteger,
8585
validateInt32,
8686
validateUint32
@@ -426,7 +426,7 @@ function open(path, flags, mode, callback) {
426426
}
427427
const flagsNumber = stringToFlags(flags);
428428
if (arguments.length >= 4) {
429-
mode = validateMode(mode, 'mode', 0o666);
429+
mode = parseMode(mode, 'mode', 0o666);
430430
}
431431
callback = makeCallback(callback);
432432

@@ -444,7 +444,7 @@ function openSync(path, flags, mode) {
444444
path = toPathIfFileURL(path);
445445
validatePath(path);
446446
const flagsNumber = stringToFlags(flags || 'r');
447-
mode = validateMode(mode, 'mode', 0o666);
447+
mode = parseMode(mode, 'mode', 0o666);
448448

449449
const ctx = { path };
450450
const result = binding.open(pathModule.toNamespacedPath(path),
@@ -754,7 +754,7 @@ function mkdir(path, options, callback) {
754754
const req = new FSReqCallback();
755755
req.oncomplete = callback;
756756
binding.mkdir(pathModule.toNamespacedPath(path),
757-
validateMode(mode, 'mode', 0o777), recursive, req);
757+
parseMode(mode, 'mode', 0o777), recursive, req);
758758
}
759759

760760
function mkdirSync(path, options) {
@@ -773,7 +773,7 @@ function mkdirSync(path, options) {
773773

774774
const ctx = { path };
775775
binding.mkdir(pathModule.toNamespacedPath(path),
776-
validateMode(mode, 'mode', 0o777), recursive, undefined,
776+
parseMode(mode, 'mode', 0o777), recursive, undefined,
777777
ctx);
778778
handleErrorFromBinding(ctx);
779779
}
@@ -1010,7 +1010,7 @@ function unlinkSync(path) {
10101010

10111011
function fchmod(fd, mode, callback) {
10121012
validateInt32(fd, 'fd', 0);
1013-
mode = validateMode(mode, 'mode');
1013+
mode = parseMode(mode, 'mode');
10141014
callback = makeCallback(callback);
10151015

10161016
const req = new FSReqCallback();
@@ -1020,7 +1020,7 @@ function fchmod(fd, mode, callback) {
10201020

10211021
function fchmodSync(fd, mode) {
10221022
validateInt32(fd, 'fd', 0);
1023-
mode = validateMode(mode, 'mode');
1023+
mode = parseMode(mode, 'mode');
10241024
const ctx = {};
10251025
binding.fchmod(fd, mode, undefined, ctx);
10261026
handleErrorFromBinding(ctx);
@@ -1061,7 +1061,7 @@ function lchmodSync(path, mode) {
10611061
function chmod(path, mode, callback) {
10621062
path = toPathIfFileURL(path);
10631063
validatePath(path);
1064-
mode = validateMode(mode, 'mode');
1064+
mode = parseMode(mode, 'mode');
10651065
callback = makeCallback(callback);
10661066

10671067
const req = new FSReqCallback();
@@ -1072,7 +1072,7 @@ function chmod(path, mode, callback) {
10721072
function chmodSync(path, mode) {
10731073
path = toPathIfFileURL(path);
10741074
validatePath(path);
1075-
mode = validateMode(mode, 'mode');
1075+
mode = parseMode(mode, 'mode');
10761076

10771077
const ctx = { path };
10781078
binding.chmod(pathModule.toNamespacedPath(path), mode, undefined, ctx);

lib/internal/fs/promises.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const {
3333
validatePath
3434
} = require('internal/fs/utils');
3535
const {
36-
validateMode,
36+
parseMode,
3737
validateInteger,
3838
validateUint32
3939
} = require('internal/validators');
@@ -198,7 +198,7 @@ async function open(path, flags, mode) {
198198
validatePath(path);
199199
if (arguments.length < 2) flags = 'r';
200200
const flagsNumber = stringToFlags(flags);
201-
mode = validateMode(mode, 'mode', 0o666);
201+
mode = parseMode(mode, 'mode', 0o666);
202202
return new FileHandle(
203203
await binding.openFileHandle(pathModule.toNamespacedPath(path),
204204
flagsNumber, mode, kUsePromises));
@@ -309,7 +309,7 @@ async function mkdir(path, options) {
309309
throw new ERR_INVALID_ARG_TYPE('recursive', 'boolean', recursive);
310310

311311
return binding.mkdir(pathModule.toNamespacedPath(path),
312-
validateMode(mode, 'mode', 0o777), recursive,
312+
parseMode(mode, 'mode', 0o777), recursive,
313313
kUsePromises);
314314
}
315315

@@ -386,14 +386,14 @@ async function unlink(path) {
386386

387387
async function fchmod(handle, mode) {
388388
validateFileHandle(handle);
389-
mode = validateMode(mode, 'mode');
389+
mode = parseMode(mode, 'mode');
390390
return binding.fchmod(handle.fd, mode, kUsePromises);
391391
}
392392

393393
async function chmod(path, mode) {
394394
path = toPathIfFileURL(path);
395395
validatePath(path);
396-
mode = validateMode(mode, 'mode');
396+
mode = parseMode(mode, 'mode');
397397
return binding.chmod(pathModule.toNamespacedPath(path), mode, kUsePromises);
398398
}
399399

lib/internal/process/main_thread_only.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const {
1111
}
1212
} = require('internal/errors');
1313
const {
14-
validateMode,
14+
parseMode,
1515
validateUint32,
1616
validateString
1717
} = require('internal/validators');
@@ -27,7 +27,7 @@ function wrapProcessMethods(binding) {
2727

2828
function umask(mask) {
2929
if (mask !== undefined) {
30-
mask = validateMode(mask, 'mask');
30+
mask = parseMode(mask, 'mask');
3131
}
3232
return binding.umask(mask);
3333
}

lib/internal/validators.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ const octalReg = /^[0-7]+$/;
2121
const modeDesc = 'must be a 32-bit unsigned integer or an octal string';
2222

2323
/**
24-
* Validate values that will be converted into mode_t (the S_* constants).
25-
* Only valid numbers and octal strings are allowed. They could be converted
26-
* to 32-bit unsigned integers or non-negative signed integers in the C++
27-
* land, but any value higher than 0o777 will result in platform-specific
24+
* Parse and validate values that will be converted into mode_t (the S_*
25+
* constants). Only valid numbers and octal strings are allowed. They could be
26+
* converted to 32-bit unsigned integers or non-negative signed integers in the
27+
* C++ land, but any value higher than 0o777 will result in platform-specific
2828
* behaviors.
2929
*
3030
* @param {*} value Values to be validated
3131
* @param {string} name Name of the argument
3232
* @param {number} def If specified, will be returned for invalid values
3333
* @returns {number}
3434
*/
35-
function validateMode(value, name, def) {
35+
function parseMode(value, name, def) {
3636
if (isUint32(value)) {
3737
return value;
3838
}
@@ -115,7 +115,7 @@ function validateNumber(value, name) {
115115
module.exports = {
116116
isInt32,
117117
isUint32,
118-
validateMode,
118+
parseMode,
119119
validateInteger,
120120
validateInt32,
121121
validateUint32,

0 commit comments

Comments
 (0)