summaryrefslogtreecommitdiff
path: root/lib/fs.js
diff options
context:
space:
mode:
authorSergey Golovin <golovim@gmail.com>2018-02-11 21:29:19 +0300
committerAnatoli Papirovski <apapirovski@mac.com>2018-03-04 11:17:16 +0100
commit523d44a66e5a4f9bbe335b7872919aa39d6ee4c4 (patch)
tree7b96c08b7e13cd9ec26355746d39d3082a8788ba /lib/fs.js
parent5a55a711505489af7fd75a83b4905afc7468ebec (diff)
downloadandroid-node-v8-523d44a66e5a4f9bbe335b7872919aa39d6ee4c4.tar.gz
android-node-v8-523d44a66e5a4f9bbe335b7872919aa39d6ee4c4.tar.bz2
android-node-v8-523d44a66e5a4f9bbe335b7872919aa39d6ee4c4.zip
fs: replace duplicate conditions by function
PR-URL: https://github.com/nodejs/node/pull/18717 Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib/fs.js')
-rw-r--r--lib/fs.js24
1 files changed, 12 insertions, 12 deletions
diff --git a/lib/fs.js b/lib/fs.js
index 2dcfb25348..afbc412058 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -145,6 +145,12 @@ function isFd(path) {
fs.Stats = Stats;
+function isFileType(fileType) {
+ // Use stats array directly to avoid creating an fs.Stats instance just for
+ // our internal use.
+ return (statValues[1/*mode*/] & S_IFMT) === fileType;
+}
+
// Don't allow mode to accidentally be overwritten.
Object.defineProperties(fs, {
F_OK: { enumerable: true, value: constants.F_OK || 0 },
@@ -317,10 +323,8 @@ function readFileAfterStat(err) {
if (err)
return context.close(err);
- // Use stats array directly to avoid creating an fs.Stats instance just for
- // our internal use.
var size;
- if ((statValues[1/*mode*/] & S_IFMT) === S_IFREG)
+ if (isFileType(S_IFREG))
size = context.size = statValues[8];
else
size = context.size = 0;
@@ -432,10 +436,8 @@ fs.readFileSync = function(path, options) {
var fd = isUserFd ? path : fs.openSync(path, options.flag || 'r', 0o666);
tryStatSync(fd, isUserFd);
- // Use stats array directly to avoid creating an fs.Stats instance just for
- // our internal use.
var size;
- if ((statValues[1/*mode*/] & S_IFMT) === S_IFREG)
+ if (isFileType(S_IFREG))
size = statValues[8];
else
size = 0;
@@ -1604,8 +1606,7 @@ fs.realpathSync = function realpathSync(p, options) {
// continue if not a symlink, break if a pipe/socket
if (knownHard[base] || (cache && cache.get(base) === base)) {
- if ((statValues[1/*mode*/] & S_IFMT) === S_IFIFO ||
- (statValues[1/*mode*/] & S_IFMT) === S_IFSOCK) {
+ if (isFileType(S_IFIFO) || isFileType(S_IFSOCK)) {
break;
}
continue;
@@ -1624,7 +1625,7 @@ fs.realpathSync = function realpathSync(p, options) {
binding.lstat(baseLong, undefined, ctx);
handleErrorFromBinding(ctx);
- if ((statValues[1/*mode*/] & S_IFMT) !== S_IFLNK) {
+ if (!isFileType(S_IFLNK)) {
knownHard[base] = true;
if (cache) cache.set(base, base);
continue;
@@ -1750,8 +1751,7 @@ fs.realpath = function realpath(p, options, callback) {
// continue if not a symlink, break if a pipe/socket
if (knownHard[base]) {
- if ((statValues[1/*mode*/] & S_IFMT) === S_IFIFO ||
- (statValues[1/*mode*/] & S_IFMT) === S_IFSOCK) {
+ if (isFileType(S_IFIFO) || isFileType(S_IFSOCK)) {
return callback(null, encodeRealpathResult(p, options));
}
return process.nextTick(LOOP);
@@ -1767,7 +1767,7 @@ fs.realpath = function realpath(p, options, callback) {
// our internal use.
// if not a symlink, skip to the next path part
- if ((statValues[1/*mode*/] & S_IFMT) !== S_IFLNK) {
+ if (!isFileType(S_IFLNK)) {
knownHard[base] = true;
return process.nextTick(LOOP);
}