@@ -45,6 +45,8 @@ enum RmError {
4545 UseNoPreserveRoot ,
4646 #[ error( "{}" , translate!( "rm-error-refusing-to-remove-directory" , "path" => _0. quote( ) ) ) ]
4747 RefusingToRemoveDirectory ( OsString ) ,
48+ #[ error( "{}" , translate!( "rm-error-may-not-abbreviate-no-preserve-root" ) ) ]
49+ MayNotAbbreviateNoPreserveRoot ,
4850}
4951
5052impl UError for RmError { }
@@ -200,7 +202,8 @@ static ARG_FILES: &str = "files";
200202
201203#[ uucore:: main]
202204pub fn uumain ( args : impl uucore:: Args ) -> UResult < ( ) > {
203- let matches = uucore:: clap_localization:: handle_clap_result ( uu_app ( ) , args) ?;
205+ let args: Vec < OsString > = args. collect ( ) ;
206+ let matches = uucore:: clap_localization:: handle_clap_result ( uu_app ( ) , args. iter ( ) ) ?;
204207
205208 let files: Vec < _ > = matches
206209 . get_many :: < OsString > ( ARG_FILES )
@@ -253,6 +256,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
253256 None
254257 } ,
255258 } ;
259+
260+ // manually parse all args to verify --no-preserve-root did not get abbreviated (clap does
261+ // allow this)
262+ if !options. preserve_root && !args. iter ( ) . any ( |arg| arg == "--no-preserve-root" ) {
263+ return Err ( RmError :: MayNotAbbreviateNoPreserveRoot . into ( ) ) ;
264+ }
265+
256266 if options. interactive == InteractiveMode :: Once && ( options. recursive || files. len ( ) > 3 ) {
257267 let msg: String = format ! (
258268 "remove {} {}{}" ,
0 commit comments