1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

mkdir: also use the dir_strip_dot_for_creation function

This commit is contained in:
Sylvestre Ledru 2022-04-02 13:14:09 +02:00
parent 845b2294e1
commit c00a277448
3 changed files with 5 additions and 6 deletions

View file

@ -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

View file

@ -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::<PathBuf>()
let path = if recursive {
dir_strip_dot_for_creation(&PathBuf::from(dir))
} else {
// Normal case
PathBuf::from(dir)

View file

@ -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::<PathBuf>()