@@ -672,18 +672,25 @@ const defaultRmdirOptions = {
672
672
recursive : false ,
673
673
} ;
674
674
675
- const validateRmOptions = hideStackFrames ( ( path , options , callback ) => {
675
+ const validateRmOptions = hideStackFrames ( ( path , options , warn , callback ) => {
676
676
options = validateRmdirOptions ( options , defaultRmOptions ) ;
677
677
validateBoolean ( options . force , 'options.force' ) ;
678
678
679
679
lazyLoadFs ( ) . stat ( path , ( err , stats ) => {
680
680
if ( err ) {
681
681
if ( options . force && err . code === 'ENOENT' ) {
682
+ if ( warn ) {
683
+ emitPermissiveRmdirWarning ( ) ;
684
+ }
682
685
return callback ( null , options ) ;
683
686
}
684
687
return callback ( err , options ) ;
685
688
}
686
689
690
+ if ( warn && ! stats . isDirectory ( ) ) {
691
+ emitPermissiveRmdirWarning ( ) ;
692
+ }
693
+
687
694
if ( stats . isDirectory ( ) && ! options . recursive ) {
688
695
return callback ( new ERR_FS_EISDIR ( {
689
696
code : 'EISDIR' ,
@@ -697,13 +704,17 @@ const validateRmOptions = hideStackFrames((path, options, callback) => {
697
704
} ) ;
698
705
} ) ;
699
706
700
- const validateRmOptionsSync = hideStackFrames ( ( path , options ) => {
707
+ const validateRmOptionsSync = hideStackFrames ( ( path , options , warn ) => {
701
708
options = validateRmdirOptions ( options , defaultRmOptions ) ;
702
709
validateBoolean ( options . force , 'options.force' ) ;
703
710
704
711
try {
705
712
const stats = lazyLoadFs ( ) . statSync ( path ) ;
706
713
714
+ if ( warn && ! stats . isDirectory ( ) ) {
715
+ emitPermissiveRmdirWarning ( ) ;
716
+ }
717
+
707
718
if ( stats . isDirectory ( ) && ! options . recursive ) {
708
719
throw new ERR_FS_EISDIR ( {
709
720
code : 'EISDIR' ,
@@ -718,12 +729,29 @@ const validateRmOptionsSync = hideStackFrames((path, options) => {
718
729
throw err ;
719
730
} else if ( err . code === 'ENOENT' && ! options . force ) {
720
731
throw err ;
732
+ } else if ( warn && err . code === 'ENOENT' ) {
733
+ emitPermissiveRmdirWarning ( ) ;
721
734
}
722
735
}
723
736
724
737
return options ;
725
738
} ) ;
726
739
740
+ let permissiveRmdirWarned = false ;
741
+
742
+ function emitPermissiveRmdirWarning ( ) {
743
+ if ( ! permissiveRmdirWarned ) {
744
+ process . emitWarning (
745
+ 'In future versions of Node.js, fs.rmdir(path, { recursive: true }) ' +
746
+ 'will throw if path does not exist or is a file. Use fs.rm(path, ' +
747
+ '{ recursive: true, force: true }) instead' ,
748
+ 'DeprecationWarning' ,
749
+ 'DEP0147'
750
+ ) ;
751
+ permissiveRmdirWarned = true ;
752
+ }
753
+ }
754
+
727
755
const validateRmdirOptions = hideStackFrames (
728
756
( options , defaults = defaultRmdirOptions ) => {
729
757
if ( options === undefined )
0 commit comments