mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
install: support of -d dir/.
to match GNU's
This commit is contained in:
parent
97be8403d3
commit
2628f3ed60
2 changed files with 37 additions and 3 deletions
|
@ -395,6 +395,16 @@ fn directory(paths: &[String], b: &Behavior) -> UResult<()> {
|
||||||
for path in paths.iter().map(Path::new) {
|
for path in paths.iter().map(Path::new) {
|
||||||
// if the path already exist, don't try to create it again
|
// if the path already exist, don't try to create it again
|
||||||
if !path.exists() {
|
if !path.exists() {
|
||||||
|
// 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
|
||||||
|
let path_to_create = 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()
|
||||||
|
};
|
||||||
// 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
|
||||||
|
@ -404,15 +414,15 @@ fn directory(paths: &[String], b: &Behavior) -> UResult<()> {
|
||||||
// target directory. All created ancestor directories will have
|
// target directory. All created ancestor directories will have
|
||||||
// the default mode. Hence it is safe to use fs::create_dir_all
|
// the default mode. Hence it is safe to use fs::create_dir_all
|
||||||
// and then only modify the target's dir mode.
|
// and then only modify the target's dir mode.
|
||||||
if let Err(e) =
|
if let Err(e) = fs::create_dir_all(path_to_create.as_path())
|
||||||
fs::create_dir_all(path).map_err_context(|| path.maybe_quote().to_string())
|
.map_err_context(|| path_to_create.as_path().maybe_quote().to_string())
|
||||||
{
|
{
|
||||||
show!(e);
|
show!(e);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.verbose {
|
if b.verbose {
|
||||||
println!("creating directory {}", path.quote());
|
println!("creating directory {}", path_to_create.quote());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1124,3 +1124,27 @@ fn test_install_missing_destination() {
|
||||||
file_1
|
file_1
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_install_dir_dot() {
|
||||||
|
// To match tests/install/d-slashdot.sh
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
|
||||||
|
scene.ucmd().arg("-d").arg("dir1/.").succeeds();
|
||||||
|
scene.ucmd().arg("-d").arg("dir2/..").succeeds();
|
||||||
|
// Tests that we don't have dir3/. in the output
|
||||||
|
// but only 'dir3'
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("-d")
|
||||||
|
.arg("dir3/.")
|
||||||
|
.arg("-v")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_contains("creating directory 'dir3'");
|
||||||
|
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
|
assert!(at.dir_exists("dir1"));
|
||||||
|
assert!(at.dir_exists("dir2"));
|
||||||
|
assert!(at.dir_exists("dir3"));
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue