Skip to content

Commit cfc82c6

Browse files
just-an-engineerAnirbanHalder654322
authored and
just-an-engineer
committed
Simplified parent/cur dir deletion avoidance in rm
Co-authored-by: Anirban Halder <anirbanhalder752@gmail.com>
1 parent 650976e commit cfc82c6

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/uu/rm/src/rm.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -326,17 +326,20 @@ pub fn remove(files: &[&OsStr], options: &Options) -> bool {
326326
fn handle_dir(path: &Path, options: &Options) -> bool {
327327
let mut had_err = false;
328328

329-
let path_as_str = path.as_os_str().to_str().unwrap();
330329
#[cfg(unix)]
331-
if path_as_str.ends_with("/.") || path_as_str.ends_with("/..") {
332-
show_error!(
333-
"refusing to remove '.' or '..' directory: skipping {}",
334-
path.quote()
335-
);
336-
return true;
337-
}
330+
let del = "/";
338331
#[cfg(windows)]
339-
if path_as_str.ends_with("\\.") || path_as_str.ends_with("\\..") {
332+
let del = "\\";
333+
334+
if path
335+
.to_str()
336+
.unwrap()
337+
.ends_with(format!("{}.", del).as_str())
338+
|| path
339+
.to_str()
340+
.unwrap()
341+
.ends_with(format!("{}..", del).as_str())
342+
{
340343
show_error!(
341344
"refusing to remove '.' or '..' directory: skipping {}",
342345
path.quote()

0 commit comments

Comments
 (0)