Skip to content

Commit 131de56

Browse files
committed
fixup! fs: use throwIfNoEntry option on statSync calls
1 parent 7da52d8 commit 131de56

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

lib/internal/fs/utils.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -720,21 +720,23 @@ const validateRmOptionsSync = hideStackFrames((path, options, warn) => {
720720
options = validateRmdirOptions(options, defaultRmOptions);
721721
validateBoolean(options.force, 'options.force');
722722

723-
const stats = lazyLoadFs().statSync(path, { throwIfNoEntry: !options.force });
724-
const isDirectory = stats?.isDirectory();
723+
if (!options.force || warn || !options.recursive) {
724+
const isDirectory = lazyLoadFs()
725+
.statSync(path, { throwIfNoEntry: !options.force })?.isDirectory();
725726

726-
if (warn && !isDirectory) {
727-
emitPermissiveRmdirWarning();
728-
}
727+
if (warn && !isDirectory) {
728+
emitPermissiveRmdirWarning();
729+
}
729730

730-
if (isDirectory && !options.recursive) {
731-
throw new ERR_FS_EISDIR({
732-
code: 'EISDIR',
733-
message: 'is a directory',
734-
path,
735-
syscall: 'rm',
736-
errno: EISDIR
737-
});
731+
if (isDirectory && !options.recursive) {
732+
throw new ERR_FS_EISDIR({
733+
code: 'EISDIR',
734+
message: 'is a directory',
735+
path,
736+
syscall: 'rm',
737+
errno: EISDIR
738+
});
739+
}
738740
}
739741

740742
return options;

0 commit comments

Comments
 (0)