mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Merge pull request #3657 from ElijahSink/main
closes #3650: install -V does not show the filename
This commit is contained in:
commit
7c7c694837
2 changed files with 47 additions and 26 deletions
|
@ -471,13 +471,19 @@ fn standard(mut paths: Vec<String>, b: &Behavior) -> UResult<()> {
|
||||||
if sources.len() > 1 || (target.exists() && target.is_dir()) {
|
if sources.len() > 1 || (target.exists() && target.is_dir()) {
|
||||||
copy_files_into_dir(sources, &target, b)
|
copy_files_into_dir(sources, &target, b)
|
||||||
} else {
|
} else {
|
||||||
if let Some(parent) = target.parent() {
|
// if -t is used in combination with -D, create whole target because it does not include filename
|
||||||
if !parent.exists() && b.create_leading {
|
let to_create: Option<&Path> = if b.target_dir.is_some() && b.create_leading {
|
||||||
|
Some(target.as_path())
|
||||||
|
} else {
|
||||||
|
target.parent()
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(to_create) = to_create {
|
||||||
|
if !to_create.exists() && b.create_leading {
|
||||||
if b.verbose {
|
if b.verbose {
|
||||||
let mut result = PathBuf::new();
|
let mut result = PathBuf::new();
|
||||||
// When creating directories with -Dv, show directory creations step
|
// When creating directories with -Dv, show directory creations step by step
|
||||||
// by step
|
for part in to_create.components() {
|
||||||
for part in parent.components() {
|
|
||||||
result.push(part.as_os_str());
|
result.push(part.as_os_str());
|
||||||
if !Path::new(part.as_os_str()).is_dir() {
|
if !Path::new(part.as_os_str()).is_dir() {
|
||||||
// Don't display when the directory already exists
|
// Don't display when the directory already exists
|
||||||
|
@ -486,21 +492,19 @@ fn standard(mut paths: Vec<String>, b: &Behavior) -> UResult<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = fs::create_dir_all(parent) {
|
if let Err(e) = fs::create_dir_all(to_create) {
|
||||||
return Err(InstallError::CreateDirFailed(parent.to_path_buf(), e).into());
|
return Err(InstallError::CreateDirFailed(to_create.to_path_buf(), e).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Silent the warning as we want to the error message
|
// Silent the warning as we want to the error message
|
||||||
#[allow(clippy::question_mark)]
|
#[allow(clippy::question_mark)]
|
||||||
if mode::chmod(parent, b.mode()).is_err() {
|
if mode::chmod(to_create, b.mode()).is_err() {
|
||||||
return Err(InstallError::ChmodFailed(parent.to_path_buf()).into());
|
return Err(InstallError::ChmodFailed(to_create.to_path_buf()).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if target.is_file() || is_new_file_path(&target) {
|
let source = sources.first().ok_or_else(|| {
|
||||||
copy(
|
|
||||||
sources.get(0).ok_or_else(|| {
|
|
||||||
UUsageError::new(
|
UUsageError::new(
|
||||||
1,
|
1,
|
||||||
format!(
|
format!(
|
||||||
|
@ -508,10 +512,19 @@ fn standard(mut paths: Vec<String>, b: &Behavior) -> UResult<()> {
|
||||||
target.to_str().unwrap()
|
target.to_str().unwrap()
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
})?,
|
})?;
|
||||||
&target,
|
|
||||||
b,
|
// If the -D flag was passed (target does not include filename),
|
||||||
)
|
// we need to add the source name to the target_dir
|
||||||
|
// because `copy` expects `to` to be a file, not a directory
|
||||||
|
let target = if target.is_dir() && b.create_leading {
|
||||||
|
target.join(source)
|
||||||
|
} else {
|
||||||
|
target // already includes dest filename
|
||||||
|
};
|
||||||
|
|
||||||
|
if target.is_file() || is_new_file_path(&target) {
|
||||||
|
copy(source, &target, b)
|
||||||
} else {
|
} else {
|
||||||
Err(InstallError::InvalidTarget(target).into())
|
Err(InstallError::InvalidTarget(target).into())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1187,7 +1187,6 @@ fn test_install_dir_req_verbose() {
|
||||||
let at = &scene.fixtures;
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
let file_1 = "source_file1";
|
let file_1 = "source_file1";
|
||||||
let dest_dir = "sub4";
|
|
||||||
at.touch(file_1);
|
at.touch(file_1);
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
|
@ -1197,12 +1196,21 @@ fn test_install_dir_req_verbose() {
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_contains("install: creating directory 'sub3'\ninstall: creating directory 'sub3/a'\ninstall: creating directory 'sub3/a/b'\ninstall: creating directory 'sub3/a/b/c'\n'source_file1' -> 'sub3/a/b/c/file'");
|
.stdout_contains("install: creating directory 'sub3'\ninstall: creating directory 'sub3/a'\ninstall: creating directory 'sub3/a/b'\ninstall: creating directory 'sub3/a/b/c'\n'source_file1' -> 'sub3/a/b/c/file'");
|
||||||
|
|
||||||
at.mkdir(dest_dir);
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("-t")
|
||||||
|
.arg("sub4/a")
|
||||||
|
.arg("-Dv")
|
||||||
|
.arg(file_1)
|
||||||
|
.succeeds()
|
||||||
|
.stdout_contains("install: creating directory 'sub4'\ninstall: creating directory 'sub4/a'\n'source_file1' -> 'sub4/a/source_file1'");
|
||||||
|
|
||||||
|
at.mkdir("sub5");
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.arg("-Dv")
|
.arg("-Dv")
|
||||||
.arg(file_1)
|
.arg(file_1)
|
||||||
.arg("sub4/a/b/c/file")
|
.arg("sub5/a/b/c/file")
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_contains("install: creating directory 'sub4/a'\ninstall: creating directory 'sub4/a/b'\ninstall: creating directory 'sub4/a/b/c'\n'source_file1' -> 'sub4/a/b/c/file'");
|
.stdout_contains("install: creating directory 'sub5/a'\ninstall: creating directory 'sub5/a/b'\ninstall: creating directory 'sub5/a/b/c'\n'source_file1' -> 'sub5/a/b/c/file'");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue