mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
fs: use throwIfNoEntry option on statSync calls
PR-URL: https://github.com/nodejs/node/pull/36975 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
1 parent
85e6089c4d
commit
a87190b00c
3 files changed
+13
-23
No files matched your search
@@ -1215,12 +1215,10 @@ function symlink(target, path, type_, callback_) {
|
||||
function symlinkSync(target, path, type) {
|
||||
type = (typeof type === 'string' ? type : null);
|
||||
if (isWindows && type === null) {
|
||||
try {
|
||||
const absoluteTarget = pathModule.resolve(path, '..', target);
|
||||
if (statSync(absoluteTarget).isDirectory()) {
|
||||
type = 'dir';
|
||||
}
|
||||
} catch { }
|
||||
const absoluteTarget = pathModule.resolve(`${path}`, '..', `${target}`);
|
||||
if (statSync(absoluteTarget, { throwIfNoEntry: false })?.isDirectory()) {
|
||||
type = 'dir';
|
||||
}
|
||||
}
|
||||
target = getValidatedPath(target, 'target');
|
||||
path = getValidatedPath(path);
|
||||
|
||||
@@ -280,14 +280,13 @@ function fixWinEPERMSync(path, options, originalErr) {
|
||||
let stats;
|
||||
|
||||
try {
|
||||
stats = statSync(path);
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT')
|
||||
return;
|
||||
|
||||
stats = statSync(path, { throwIfNoEntry: false });
|
||||
} catch {
|
||||
throw originalErr;
|
||||
}
|
||||
|
||||
if (stats === undefined) return;
|
||||
|
||||
if (stats.isDirectory())
|
||||
_rmdirSync(path, options, originalErr);
|
||||
else
|
||||
|
||||
@@ -720,14 +720,15 @@ const validateRmOptionsSync = hideStackFrames((path, options, warn) => {
|
||||
options = validateRmdirOptions(options, defaultRmOptions);
|
||||
validateBoolean(options.force, 'options.force');
|
||||
|
||||
try {
|
||||
const stats = lazyLoadFs().statSync(path);
|
||||
if (!options.force || warn || !options.recursive) {
|
||||
const isDirectory = lazyLoadFs()
|
||||
.statSync(path, { throwIfNoEntry: !options.force })?.isDirectory();
|
||||
|
||||
if (warn && !stats.isDirectory()) {
|
||||
if (warn && !isDirectory) {
|
||||
emitPermissiveRmdirWarning();
|
||||
}
|
||||
|
||||
if (stats.isDirectory() && !options.recursive) {
|
||||
if (isDirectory && !options.recursive) {
|
||||
throw new ERR_FS_EISDIR({
|
||||
code: 'EISDIR',
|
||||
message: 'is a directory',
|
||||
@@ -736,14 +737,6 @@ const validateRmOptionsSync = hideStackFrames((path, options, warn) => {
|
||||
errno: EISDIR
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
} else if (err.code === 'ENOENT' && !options.force) {
|
||||
throw err;
|
||||
} else if (warn && err.code === 'ENOENT') {
|
||||
emitPermissiveRmdirWarning();
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
|
||||
Reference in new issue
Block a user