mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
create a function dir_strip_dot_for_creation to manage the /. issue
This commit is contained in:
parent
2628f3ed60
commit
845b2294e1
2 changed files with 16 additions and 6 deletions
|
@ -20,6 +20,7 @@ use uucore::display::Quotable;
|
||||||
use uucore::entries::{grp2gid, usr2uid};
|
use uucore::entries::{grp2gid, usr2uid};
|
||||||
use uucore::error::{FromIo, UError, UIoError, UResult, UUsageError};
|
use uucore::error::{FromIo, UError, UIoError, UResult, UUsageError};
|
||||||
use uucore::format_usage;
|
use uucore::format_usage;
|
||||||
|
use uucore::fs::dir_strip_dot_for_creation;
|
||||||
use uucore::mode::get_umask;
|
use uucore::mode::get_umask;
|
||||||
use uucore::perms::{wrap_chown, Verbosity, VerbosityLevel};
|
use uucore::perms::{wrap_chown, Verbosity, VerbosityLevel};
|
||||||
|
|
||||||
|
@ -399,12 +400,7 @@ fn directory(paths: &[String], b: &Behavior) -> UResult<()> {
|
||||||
// install -d foo/. should work and just create foo/
|
// install -d foo/. should work and just create foo/
|
||||||
// std::fs::create_dir("foo/."); fails in pure Rust
|
// std::fs::create_dir("foo/."); fails in pure Rust
|
||||||
// See also mkdir.rs for another occurrence of this
|
// See also mkdir.rs for another occurrence of this
|
||||||
let path_to_create = if path.to_string_lossy().ends_with("/.") {
|
let path_to_create = dir_strip_dot_for_creation(path.to_path_buf());
|
||||||
// Do a simple dance to strip the "/."
|
|
||||||
Path::new(path).components().collect::<PathBuf>()
|
|
||||||
} else {
|
|
||||||
path.to_path_buf()
|
|
||||||
};
|
|
||||||
// Differently than the primary functionality
|
// Differently than the primary functionality
|
||||||
// (MainFunction::Standard), the directory functionality should
|
// (MainFunction::Standard), the directory functionality should
|
||||||
// create all ancestors (or components) of a directory
|
// create all ancestors (or components) of a directory
|
||||||
|
|
|
@ -470,6 +470,20 @@ pub fn display_permissions_unix(mode: mode_t, display_file_type: bool) -> String
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For some programs like install or mkdir, dir/. can be provided
|
||||||
|
// Special case to match GNU's behavior:
|
||||||
|
// 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 {
|
||||||
|
if path.to_string_lossy().ends_with("/.") {
|
||||||
|
// Do a simple dance to strip the "/."
|
||||||
|
Path::new(&path).components().collect::<PathBuf>()
|
||||||
|
} else {
|
||||||
|
path.to_path_buf()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
// Note this useful idiom: importing names from outer (for mod tests) scope.
|
// Note this useful idiom: importing names from outer (for mod tests) scope.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue