Skip to content

Commit

Permalink
lib: rename validateMode to parseMode
Browse files Browse the repository at this point in the history
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 <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BridgeAR committed Mar 27, 2019
1 parent 9d854fb commit 50a3fe2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
18 changes: 9 additions & 9 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const {
} = require('internal/constants');
const {
isUint32,
validateMode,
parseMode,
validateInteger,
validateInt32,
validateUint32
Expand Down Expand Up @@ -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);

Expand All @@ -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),
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const {
validatePath
} = require('internal/fs/utils');
const {
validateMode,
parseMode,
validateInteger,
validateUint32
} = require('internal/validators');
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/internal/process/main_thread_only.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
}
} = require('internal/errors');
const {
validateMode,
parseMode,
validateUint32,
validateString
} = require('internal/validators');
Expand All @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions lib/internal/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ 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
* @param {string} name Name of the argument
* @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;
}
Expand Down Expand Up @@ -115,7 +115,7 @@ function validateNumber(value, name) {
module.exports = {
isInt32,
isUint32,
validateMode,
parseMode,
validateInteger,
validateInt32,
validateUint32,
Expand Down

0 comments on commit 50a3fe2

Please sign in to comment.