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:
parent
9d854fb60c
commit
50a3fe20ea
18
lib/fs.js
18
lib/fs.js
@ -80,7 +80,7 @@ const {
|
||||
} = require('internal/constants');
|
||||
const {
|
||||
isUint32,
|
||||
validateMode,
|
||||
parseMode,
|
||||
validateInteger,
|
||||
validateInt32,
|
||||
validateUint32
|
||||
@ -426,7 +426,7 @@ function open(path, flags, mode, callback) {
|
||||
}
|
||||
const flagsNumber = stringToFlags(flags);
|
||||
if (arguments.length >= 4) {
|
||||
mode = validateMode(mode, 'mode', 0o666);
|
||||
mode = parseMode(mode, 'mode', 0o666);
|
||||
}
|
||||
callback = makeCallback(callback);
|
||||
|
||||
@ -444,7 +444,7 @@ function openSync(path, flags, mode) {
|
||||
path = toPathIfFileURL(path);
|
||||
validatePath(path);
|
||||
const flagsNumber = stringToFlags(flags || 'r');
|
||||
mode = validateMode(mode, 'mode', 0o666);
|
||||
mode = parseMode(mode, 'mode', 0o666);
|
||||
|
||||
const ctx = { path };
|
||||
const result = binding.open(pathModule.toNamespacedPath(path),
|
||||
@ -754,7 +754,7 @@ function mkdir(path, options, callback) {
|
||||
const req = new FSReqCallback();
|
||||
req.oncomplete = callback;
|
||||
binding.mkdir(pathModule.toNamespacedPath(path),
|
||||
validateMode(mode, 'mode', 0o777), recursive, req);
|
||||
parseMode(mode, 'mode', 0o777), recursive, req);
|
||||
}
|
||||
|
||||
function mkdirSync(path, options) {
|
||||
@ -773,7 +773,7 @@ function mkdirSync(path, options) {
|
||||
|
||||
const ctx = { path };
|
||||
binding.mkdir(pathModule.toNamespacedPath(path),
|
||||
validateMode(mode, 'mode', 0o777), recursive, undefined,
|
||||
parseMode(mode, 'mode', 0o777), recursive, undefined,
|
||||
ctx);
|
||||
handleErrorFromBinding(ctx);
|
||||
}
|
||||
@ -1010,7 +1010,7 @@ function unlinkSync(path) {
|
||||
|
||||
function fchmod(fd, mode, callback) {
|
||||
validateInt32(fd, 'fd', 0);
|
||||
mode = validateMode(mode, 'mode');
|
||||
mode = parseMode(mode, 'mode');
|
||||
callback = makeCallback(callback);
|
||||
|
||||
const req = new FSReqCallback();
|
||||
@ -1020,7 +1020,7 @@ function fchmod(fd, mode, callback) {
|
||||
|
||||
function fchmodSync(fd, mode) {
|
||||
validateInt32(fd, 'fd', 0);
|
||||
mode = validateMode(mode, 'mode');
|
||||
mode = parseMode(mode, 'mode');
|
||||
const ctx = {};
|
||||
binding.fchmod(fd, mode, undefined, ctx);
|
||||
handleErrorFromBinding(ctx);
|
||||
@ -1061,7 +1061,7 @@ function lchmodSync(path, mode) {
|
||||
function chmod(path, mode, callback) {
|
||||
path = toPathIfFileURL(path);
|
||||
validatePath(path);
|
||||
mode = validateMode(mode, 'mode');
|
||||
mode = parseMode(mode, 'mode');
|
||||
callback = makeCallback(callback);
|
||||
|
||||
const req = new FSReqCallback();
|
||||
@ -1072,7 +1072,7 @@ function chmod(path, mode, callback) {
|
||||
function chmodSync(path, mode) {
|
||||
path = toPathIfFileURL(path);
|
||||
validatePath(path);
|
||||
mode = validateMode(mode, 'mode');
|
||||
mode = parseMode(mode, 'mode');
|
||||
|
||||
const ctx = { path };
|
||||
binding.chmod(pathModule.toNamespacedPath(path), mode, undefined, ctx);
|
||||
|
@ -33,7 +33,7 @@ const {
|
||||
validatePath
|
||||
} = require('internal/fs/utils');
|
||||
const {
|
||||
validateMode,
|
||||
parseMode,
|
||||
validateInteger,
|
||||
validateUint32
|
||||
} = require('internal/validators');
|
||||
@ -198,7 +198,7 @@ async function open(path, flags, mode) {
|
||||
validatePath(path);
|
||||
if (arguments.length < 2) flags = 'r';
|
||||
const flagsNumber = stringToFlags(flags);
|
||||
mode = validateMode(mode, 'mode', 0o666);
|
||||
mode = parseMode(mode, 'mode', 0o666);
|
||||
return new FileHandle(
|
||||
await binding.openFileHandle(pathModule.toNamespacedPath(path),
|
||||
flagsNumber, mode, kUsePromises));
|
||||
@ -309,7 +309,7 @@ async function mkdir(path, options) {
|
||||
throw new ERR_INVALID_ARG_TYPE('recursive', 'boolean', recursive);
|
||||
|
||||
return binding.mkdir(pathModule.toNamespacedPath(path),
|
||||
validateMode(mode, 'mode', 0o777), recursive,
|
||||
parseMode(mode, 'mode', 0o777), recursive,
|
||||
kUsePromises);
|
||||
}
|
||||
|
||||
@ -386,14 +386,14 @@ async function unlink(path) {
|
||||
|
||||
async function fchmod(handle, mode) {
|
||||
validateFileHandle(handle);
|
||||
mode = validateMode(mode, 'mode');
|
||||
mode = parseMode(mode, 'mode');
|
||||
return binding.fchmod(handle.fd, mode, kUsePromises);
|
||||
}
|
||||
|
||||
async function chmod(path, mode) {
|
||||
path = toPathIfFileURL(path);
|
||||
validatePath(path);
|
||||
mode = validateMode(mode, 'mode');
|
||||
mode = parseMode(mode, 'mode');
|
||||
return binding.chmod(pathModule.toNamespacedPath(path), mode, kUsePromises);
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ const {
|
||||
}
|
||||
} = require('internal/errors');
|
||||
const {
|
||||
validateMode,
|
||||
parseMode,
|
||||
validateUint32,
|
||||
validateString
|
||||
} = require('internal/validators');
|
||||
@ -27,7 +27,7 @@ function wrapProcessMethods(binding) {
|
||||
|
||||
function umask(mask) {
|
||||
if (mask !== undefined) {
|
||||
mask = validateMode(mask, 'mask');
|
||||
mask = parseMode(mask, 'mask');
|
||||
}
|
||||
return binding.umask(mask);
|
||||
}
|
||||
|
@ -21,10 +21,10 @@ const octalReg = /^[0-7]+$/;
|
||||
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).
|
||||
* Only valid numbers and octal strings are allowed. They could be converted
|
||||
* to 32-bit unsigned integers or non-negative signed integers in the C++
|
||||
* land, but any value higher than 0o777 will result in platform-specific
|
||||
* Parse and validate values that will be converted into mode_t (the S_*
|
||||
* constants). Only valid numbers and octal strings are allowed. They could be
|
||||
* converted to 32-bit unsigned integers or non-negative signed integers in the
|
||||
* C++ land, but any value higher than 0o777 will result in platform-specific
|
||||
* behaviors.
|
||||
*
|
||||
* @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
|
||||
* @returns {number}
|
||||
*/
|
||||
function validateMode(value, name, def) {
|
||||
function parseMode(value, name, def) {
|
||||
if (isUint32(value)) {
|
||||
return value;
|
||||
}
|
||||
@ -115,7 +115,7 @@ function validateNumber(value, name) {
|
||||
module.exports = {
|
||||
isInt32,
|
||||
isUint32,
|
||||
validateMode,
|
||||
parseMode,
|
||||
validateInteger,
|
||||
validateInt32,
|
||||
validateUint32,
|
||||
|
Loading…
x
Reference in New Issue
Block a user