mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
fs: refactor to use optional chaining
PR-URL: https://github.com/nodejs/node/pull/36524 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
1 parent
e3c5adc6d0
commit
e30af7be33
5 files changed
+15
-15
No files matched your search
@@ -877,7 +877,7 @@ function rmdir(path, options, callback) {
|
||||
callback = makeCallback(callback);
|
||||
path = pathModule.toNamespacedPath(getValidatedPath(path));
|
||||
|
||||
if (options && options.recursive) {
|
||||
if (options?.recursive) {
|
||||
validateRmOptions(
|
||||
path,
|
||||
{ ...options, force: true },
|
||||
@@ -901,7 +901,7 @@ function rmdir(path, options, callback) {
|
||||
function rmdirSync(path, options) {
|
||||
path = getValidatedPath(path);
|
||||
|
||||
if (options && options.recursive) {
|
||||
if (options?.recursive) {
|
||||
options = validateRmOptionsSync(path, { ...options, force: true }, true);
|
||||
lazyLoadRimraf();
|
||||
return rimrafSync(pathModule.toNamespacedPath(path), options);
|
||||
@@ -1087,7 +1087,7 @@ function stat(path, options = { bigint: false }, callback) {
|
||||
function hasNoEntryError(ctx) {
|
||||
if (ctx.errno) {
|
||||
const uvErr = uvErrmapGet(ctx.errno);
|
||||
return uvErr && uvErr[0] === 'ENOENT';
|
||||
return uvErr?.[0] === 'ENOENT';
|
||||
}
|
||||
|
||||
if (ctx.error) {
|
||||
@@ -1711,7 +1711,7 @@ function realpathSync(p, options) {
|
||||
p = pathModule.resolve(p);
|
||||
|
||||
const cache = options[realpathCacheKey];
|
||||
const maybeCachedResult = cache && cache.get(p);
|
||||
const maybeCachedResult = cache?.get(p);
|
||||
if (maybeCachedResult) {
|
||||
return maybeCachedResult;
|
||||
}
|
||||
@@ -1760,7 +1760,7 @@ function realpathSync(p, options) {
|
||||
}
|
||||
|
||||
// Continue if not a symlink, break if a pipe/socket
|
||||
if (knownHard[base] || (cache && cache.get(base) === base)) {
|
||||
if (knownHard[base] || cache?.get(base) === base) {
|
||||
if (isFileType(statValues, S_IFIFO) ||
|
||||
isFileType(statValues, S_IFSOCK)) {
|
||||
break;
|
||||
@@ -1769,7 +1769,7 @@ function realpathSync(p, options) {
|
||||
}
|
||||
|
||||
let resolvedLink;
|
||||
const maybeCachedResolved = cache && cache.get(base);
|
||||
const maybeCachedResolved = cache?.get(base);
|
||||
if (maybeCachedResolved) {
|
||||
resolvedLink = maybeCachedResolved;
|
||||
} else {
|
||||
@@ -1783,7 +1783,7 @@ function realpathSync(p, options) {
|
||||
|
||||
if (!isFileType(stats, S_IFLNK)) {
|
||||
knownHard[base] = true;
|
||||
if (cache) cache.set(base, base);
|
||||
cache?.set(base, base);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1828,7 +1828,7 @@ function realpathSync(p, options) {
|
||||
}
|
||||
}
|
||||
|
||||
if (cache) cache.set(original, p);
|
||||
cache?.set(original, p);
|
||||
return encodeRealpathResult(p, options);
|
||||
}
|
||||
|
||||
|
||||
@@ -291,14 +291,14 @@ async function writeFileHandle(filehandle, data, signal) {
|
||||
}
|
||||
|
||||
async function readFileHandle(filehandle, options) {
|
||||
const signal = options && options.signal;
|
||||
const signal = options?.signal;
|
||||
|
||||
if (signal && signal.aborted) {
|
||||
if (signal?.aborted) {
|
||||
throw lazyDOMException('The operation was aborted', 'AbortError');
|
||||
}
|
||||
const statFields = await binding.fstat(filehandle.fd, false, kUsePromises);
|
||||
|
||||
if (signal && signal.aborted) {
|
||||
if (signal?.aborted) {
|
||||
throw lazyDOMException('The operation was aborted', 'AbortError');
|
||||
}
|
||||
|
||||
@@ -318,7 +318,7 @@ async function readFileHandle(filehandle, options) {
|
||||
MathMin(size, kReadFileMaxChunkSize);
|
||||
let endOfFile = false;
|
||||
do {
|
||||
if (signal && signal.aborted) {
|
||||
if (signal?.aborted) {
|
||||
throw lazyDOMException('The operation was aborted', 'AbortError');
|
||||
}
|
||||
const buf = Buffer.alloc(chunkSize);
|
||||
|
||||
@@ -94,7 +94,7 @@ class ReadFileContext {
|
||||
let offset;
|
||||
let length;
|
||||
|
||||
if (this.signal && this.signal.aborted) {
|
||||
if (this.signal?.aborted) {
|
||||
return this.close(
|
||||
lazyDOMException('The operation was aborted', 'AbortError')
|
||||
);
|
||||
|
||||
@@ -189,7 +189,7 @@ function rimrafSync(path, options) {
|
||||
|
||||
try {
|
||||
// SunOS lets the root user unlink directories.
|
||||
if (stats !== undefined && stats.isDirectory())
|
||||
if (stats?.isDirectory())
|
||||
_rmdirSync(path, options, null);
|
||||
else
|
||||
_unlinkSync(path, options);
|
||||
|
||||
@@ -137,7 +137,7 @@ StatWatcher.prototype[kFSStatWatcherAddOrCleanRef] = function(operate) {
|
||||
// Clean up all
|
||||
this[KFSStatWatcherMaxRefCount] = 0;
|
||||
this[KFSStatWatcherRefCount] = 0;
|
||||
this._handle && this._handle.unref();
|
||||
this._handle?.unref();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user