diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index 330124467..e3154aa51 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -400,7 +400,7 @@ fn directory(paths: &[String], b: &Behavior) -> UResult<()> { // install -d foo/. should work and just create foo/ // std::fs::create_dir("foo/."); fails in pure Rust // See also mkdir.rs for another occurrence of this - let path_to_create = dir_strip_dot_for_creation(path.to_path_buf()); + let path_to_create = dir_strip_dot_for_creation(path); // Differently than the primary functionality // (MainFunction::Standard), the directory functionality should // create all ancestors (or components) of a directory diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index 35078d296..7c8d4e413 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -12,12 +12,12 @@ extern crate uucore; use clap::{crate_version, Arg, ArgMatches, Command, OsValues}; use std::path::{Path, PathBuf}; -use uucore::display::Quotable; #[cfg(not(windows))] use uucore::error::FromIo; use uucore::error::{UResult, USimpleError}; #[cfg(not(windows))] use uucore::mode; +use uucore::{display::Quotable, fs::dir_strip_dot_for_creation}; use uucore::{format_usage, InvalidEncodingHandling}; static DEFAULT_PERM: u32 = 0o755; @@ -146,9 +146,8 @@ fn exec(dirs: OsValues, recursive: bool, mode: u32, verbose: bool) -> UResult<() // Special case to match GNU's behavior: // mkdir -p foo/. should work and just create foo/ // std::fs::create_dir("foo/."); fails in pure Rust - let path = if recursive && dir.to_string_lossy().ends_with("/.") { - // Do a simple dance to strip the "/." - Path::new(dir).components().collect::() + let path = if recursive { + dir_strip_dot_for_creation(&PathBuf::from(dir)) } else { // Normal case PathBuf::from(dir) diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index 1b7fb24b3..5cd6d253d 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -475,7 +475,7 @@ pub fn display_permissions_unix(mode: mode_t, display_file_type: bool) -> String // install -d foo/. should work and just create foo/ // std::fs::create_dir("foo/."); fails in pure Rust // See also mkdir.rs for another occurrence of this -pub fn dir_strip_dot_for_creation(path: PathBuf) -> PathBuf { +pub fn dir_strip_dot_for_creation(path: &Path) -> PathBuf { if path.to_string_lossy().ends_with("/.") { // Do a simple dance to strip the "/." Path::new(&path).components().collect::()