Skip to content

Commit f69dd02

Browse files
rm: fix windows build issue
1 parent 7864683 commit f69dd02

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

src/uu/rm/src/rm.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
// spell-checker:ignore (path) eacces inacc
77

88
use clap::{builder::ValueParser, crate_version, parser::ValueSource, Arg, ArgAction, Command};
9+
#[cfg(not(windows))]
910
use regex::bytes::Regex;
1011
use std::collections::VecDeque;
1112
use std::ffi::{OsStr, OsString};
1213
use std::fs::{self, File, Metadata};
1314
use std::io::ErrorKind;
1415
use std::ops::BitOr;
16+
#[cfg(not(windows))]
1517
use std::os::unix::ffi::OsStrExt;
18+
1619
use std::path::{Path, PathBuf};
1720
use uucore::display::Quotable;
1821
use uucore::error::{UResult, USimpleError, UUsageError};
@@ -296,28 +299,31 @@ pub fn remove(files: &[&OsStr], options: &Options) -> bool {
296299
had_err = match file.symlink_metadata() {
297300
Ok(metadata) => {
298301
#[cfg(not(windows))]
299-
let re = Regex::new(r"/\.{1,2}\/*$").unwrap();
300-
if re.is_match(filename.as_bytes()) {
301-
show_error!(
302-
"refusing to remove '.' or '..' directory: skipping '{:}'",
303-
clean_trailing_slashes(filename).display()
304-
);
305-
true
306-
} else if metadata.is_dir() {
307-
handle_dir(file, options)
308-
} else if is_symlink_dir(&metadata) {
309-
remove_dir(file, options)
310-
} else {
311-
remove_file(file, options)
302+
{
303+
let re = Regex::new(r"/\.{1,2}\/*$").unwrap();
304+
if re.is_match(filename.as_bytes()) {
305+
show_error!(
306+
"refusing to remove '.' or '..' directory: skipping '{:}'",
307+
clean_trailing_slashes(filename).display()
308+
);
309+
true
310+
} else if metadata.is_dir() {
311+
handle_dir(file, options)
312+
} else if is_symlink_dir(&metadata) {
313+
remove_dir(file, options)
314+
} else {
315+
remove_file(file, options)
316+
}
312317
}
313-
314318
#[cfg(windows)]
315-
if metadata.is_dir() {
316-
handle_dir(file, options)
317-
} else if is_symlink_dir(&metadata) {
318-
remove_dir(file, options)
319-
} else {
320-
remove_file(file, options)
319+
{
320+
if metadata.is_dir() {
321+
handle_dir(file, options)
322+
} else if is_symlink_dir(&metadata) {
323+
remove_dir(file, options)
324+
} else {
325+
remove_file(file, options)
326+
}
321327
}
322328
}
323329
Err(_e) => {
@@ -606,6 +612,7 @@ fn handle_writable_directory(path: &Path, options: &Options, metadata: &Metadata
606612
}
607613
}
608614

615+
#[cfg(not(windows))]
609616
/// Removes trailing slashes, for example 'd/../////' yield 'd/../' required to fix rm-r4 GNU test
610617
fn clean_trailing_slashes(path: &OsStr) -> &Path {
611618
let path_bytes = path.as_bytes();

0 commit comments

Comments
 (0)