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: https://github.com/nodejs/node/pull/26809
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Ruben Bridgewater 2019-03-20 12:00:47 +01:00
parent 9d854fb60c
commit 50a3fe20ea
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
4 changed files with 22 additions and 22 deletions

View File

@ -80,7 +80,7 @@ const {
} = require('internal/constants'); } = require('internal/constants');
const { const {
isUint32, isUint32,
validateMode, parseMode,
validateInteger, validateInteger,
validateInt32, validateInt32,
validateUint32 validateUint32
@ -426,7 +426,7 @@ function open(path, flags, mode, callback) {
} }
const flagsNumber = stringToFlags(flags); const flagsNumber = stringToFlags(flags);
if (arguments.length >= 4) { if (arguments.length >= 4) {
mode = validateMode(mode, 'mode', 0o666); mode = parseMode(mode, 'mode', 0o666);
} }
callback = makeCallback(callback); callback = makeCallback(callback);
@ -444,7 +444,7 @@ function openSync(path, flags, mode) {
path = toPathIfFileURL(path); path = toPathIfFileURL(path);
validatePath(path); validatePath(path);
const flagsNumber = stringToFlags(flags || 'r'); const flagsNumber = stringToFlags(flags || 'r');
mode = validateMode(mode, 'mode', 0o666); mode = parseMode(mode, 'mode', 0o666);
const ctx = { path }; const ctx = { path };
const result = binding.open(pathModule.toNamespacedPath(path), const result = binding.open(pathModule.toNamespacedPath(path),
@ -754,7 +754,7 @@ function mkdir(path, options, callback) {
const req = new FSReqCallback(); const req = new FSReqCallback();
req.oncomplete = callback; req.oncomplete = callback;
binding.mkdir(pathModule.toNamespacedPath(path), binding.mkdir(pathModule.toNamespacedPath(path),
validateMode(mode, 'mode', 0o777), recursive, req); parseMode(mode, 'mode', 0o777), recursive, req);
} }
function mkdirSync(path, options) { function mkdirSync(path, options) {
@ -773,7 +773,7 @@ function mkdirSync(path, options) {
const ctx = { path }; const ctx = { path };
binding.mkdir(pathModule.toNamespacedPath(path), binding.mkdir(pathModule.toNamespacedPath(path),
validateMode(mode, 'mode', 0o777), recursive, undefined, parseMode(mode, 'mode', 0o777), recursive, undefined,
ctx); ctx);
handleErrorFromBinding(ctx); handleErrorFromBinding(ctx);
} }
@ -1010,7 +1010,7 @@ function unlinkSync(path) {
function fchmod(fd, mode, callback) { function fchmod(fd, mode, callback) {
validateInt32(fd, 'fd', 0); validateInt32(fd, 'fd', 0);
mode = validateMode(mode, 'mode'); mode = parseMode(mode, 'mode');
callback = makeCallback(callback); callback = makeCallback(callback);
const req = new FSReqCallback(); const req = new FSReqCallback();
@ -1020,7 +1020,7 @@ function fchmod(fd, mode, callback) {
function fchmodSync(fd, mode) { function fchmodSync(fd, mode) {
validateInt32(fd, 'fd', 0); validateInt32(fd, 'fd', 0);
mode = validateMode(mode, 'mode'); mode = parseMode(mode, 'mode');
const ctx = {}; const ctx = {};
binding.fchmod(fd, mode, undefined, ctx); binding.fchmod(fd, mode, undefined, ctx);
handleErrorFromBinding(ctx); handleErrorFromBinding(ctx);
@ -1061,7 +1061,7 @@ function lchmodSync(path, mode) {
function chmod(path, mode, callback) { function chmod(path, mode, callback) {
path = toPathIfFileURL(path); path = toPathIfFileURL(path);
validatePath(path); validatePath(path);
mode = validateMode(mode, 'mode'); mode = parseMode(mode, 'mode');
callback = makeCallback(callback); callback = makeCallback(callback);
const req = new FSReqCallback(); const req = new FSReqCallback();
@ -1072,7 +1072,7 @@ function chmod(path, mode, callback) {
function chmodSync(path, mode) { function chmodSync(path, mode) {
path = toPathIfFileURL(path); path = toPathIfFileURL(path);
validatePath(path); validatePath(path);
mode = validateMode(mode, 'mode'); mode = parseMode(mode, 'mode');
const ctx = { path }; const ctx = { path };
binding.chmod(pathModule.toNamespacedPath(path), mode, undefined, ctx); binding.chmod(pathModule.toNamespacedPath(path), mode, undefined, ctx);

View File

@ -33,7 +33,7 @@ const {
validatePath validatePath
} = require('internal/fs/utils'); } = require('internal/fs/utils');
const { const {
validateMode, parseMode,
validateInteger, validateInteger,
validateUint32 validateUint32
} = require('internal/validators'); } = require('internal/validators');
@ -198,7 +198,7 @@ async function open(path, flags, mode) {
validatePath(path); validatePath(path);
if (arguments.length < 2) flags = 'r'; if (arguments.length < 2) flags = 'r';
const flagsNumber = stringToFlags(flags); const flagsNumber = stringToFlags(flags);
mode = validateMode(mode, 'mode', 0o666); mode = parseMode(mode, 'mode', 0o666);
return new FileHandle( return new FileHandle(
await binding.openFileHandle(pathModule.toNamespacedPath(path), await binding.openFileHandle(pathModule.toNamespacedPath(path),
flagsNumber, mode, kUsePromises)); flagsNumber, mode, kUsePromises));
@ -309,7 +309,7 @@ async function mkdir(path, options) {
throw new ERR_INVALID_ARG_TYPE('recursive', 'boolean', recursive); throw new ERR_INVALID_ARG_TYPE('recursive', 'boolean', recursive);
return binding.mkdir(pathModule.toNamespacedPath(path), return binding.mkdir(pathModule.toNamespacedPath(path),
validateMode(mode, 'mode', 0o777), recursive, parseMode(mode, 'mode', 0o777), recursive,
kUsePromises); kUsePromises);
} }
@ -386,14 +386,14 @@ async function unlink(path) {
async function fchmod(handle, mode) { async function fchmod(handle, mode) {
validateFileHandle(handle); validateFileHandle(handle);
mode = validateMode(mode, 'mode'); mode = parseMode(mode, 'mode');
return binding.fchmod(handle.fd, mode, kUsePromises); return binding.fchmod(handle.fd, mode, kUsePromises);
} }
async function chmod(path, mode) { async function chmod(path, mode) {
path = toPathIfFileURL(path); path = toPathIfFileURL(path);
validatePath(path); validatePath(path);
mode = validateMode(mode, 'mode'); mode = parseMode(mode, 'mode');
return binding.chmod(pathModule.toNamespacedPath(path), mode, kUsePromises); return binding.chmod(pathModule.toNamespacedPath(path), mode, kUsePromises);
} }

View File

@ -11,7 +11,7 @@ const {
} }
} = require('internal/errors'); } = require('internal/errors');
const { const {
validateMode, parseMode,
validateUint32, validateUint32,
validateString validateString
} = require('internal/validators'); } = require('internal/validators');
@ -27,7 +27,7 @@ function wrapProcessMethods(binding) {
function umask(mask) { function umask(mask) {
if (mask !== undefined) { if (mask !== undefined) {
mask = validateMode(mask, 'mask'); mask = parseMode(mask, 'mask');
} }
return binding.umask(mask); return binding.umask(mask);
} }

View File

@ -21,10 +21,10 @@ const octalReg = /^[0-7]+$/;
const modeDesc = 'must be a 32-bit unsigned integer or an octal string'; const modeDesc = 'must be a 32-bit unsigned integer or an octal string';
/** /**
* Validate values that will be converted into mode_t (the S_* constants). * Parse and validate values that will be converted into mode_t (the S_*
* Only valid numbers and octal strings are allowed. They could be converted * constants). Only valid numbers and octal strings are allowed. They could be
* to 32-bit unsigned integers or non-negative signed integers in the C++ * converted to 32-bit unsigned integers or non-negative signed integers in the
* land, but any value higher than 0o777 will result in platform-specific * C++ land, but any value higher than 0o777 will result in platform-specific
* behaviors. * behaviors.
* *
* @param {*} value Values to be validated * @param {*} value Values to be validated
@ -32,7 +32,7 @@ const modeDesc = 'must be a 32-bit unsigned integer or an octal string';
* @param {number} def If specified, will be returned for invalid values * @param {number} def If specified, will be returned for invalid values
* @returns {number} * @returns {number}
*/ */
function validateMode(value, name, def) { function parseMode(value, name, def) {
if (isUint32(value)) { if (isUint32(value)) {
return value; return value;
} }
@ -115,7 +115,7 @@ function validateNumber(value, name) {
module.exports = { module.exports = {
isInt32, isInt32,
isUint32, isUint32,
validateMode, parseMode,
validateInteger, validateInteger,
validateInt32, validateInt32,
validateUint32, validateUint32,