mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
install: improve error message (#7794)
* friendly message install file to directory containing directory with same name * install: test install file to directory containing directory with same name
This commit is contained in:
parent
f92ee6a519
commit
b009cae5a8
2 changed files with 24 additions and 0 deletions
|
@ -98,6 +98,9 @@ enum InstallError {
|
||||||
|
|
||||||
#[error("failed to access {}: Not a directory", .0.quote())]
|
#[error("failed to access {}: Not a directory", .0.quote())]
|
||||||
NotADirectory(PathBuf),
|
NotADirectory(PathBuf),
|
||||||
|
|
||||||
|
#[error("cannot overwrite directory {} with non-directory {}", .0.quote(), .1.quote())]
|
||||||
|
OverrideDirectoryFailed(PathBuf, PathBuf),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UError for InstallError {
|
impl UError for InstallError {
|
||||||
|
@ -748,6 +751,13 @@ fn copy_normal_file(from: &Path, to: &Path) -> UResult<()> {
|
||||||
/// Returns an empty Result or an error in case of failure.
|
/// Returns an empty Result or an error in case of failure.
|
||||||
///
|
///
|
||||||
fn copy_file(from: &Path, to: &Path) -> UResult<()> {
|
fn copy_file(from: &Path, to: &Path) -> UResult<()> {
|
||||||
|
if to.is_dir() && !from.is_dir() {
|
||||||
|
return Err(InstallError::OverrideDirectoryFailed(
|
||||||
|
to.to_path_buf().clone(),
|
||||||
|
from.to_path_buf().clone(),
|
||||||
|
)
|
||||||
|
.into());
|
||||||
|
}
|
||||||
// fs::copy fails if destination is a invalid symlink.
|
// fs::copy fails if destination is a invalid symlink.
|
||||||
// so lets just remove all existing files at destination before copy.
|
// so lets just remove all existing files at destination before copy.
|
||||||
if let Err(e) = fs::remove_file(to) {
|
if let Err(e) = fs::remove_file(to) {
|
||||||
|
|
|
@ -1764,3 +1764,17 @@ fn test_install_from_stdin() {
|
||||||
assert!(at.file_exists(target));
|
assert!(at.file_exists(target));
|
||||||
assert_eq!(at.read(target), test_string);
|
assert_eq!(at.read(target), test_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_install_failing_copy_file_to_target_contain_subdir_with_same_name() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
let file = "file";
|
||||||
|
let dir1 = "dir1";
|
||||||
|
|
||||||
|
at.touch(file);
|
||||||
|
at.mkdir_all(&format!("{dir1}/{file}"));
|
||||||
|
ucmd.arg(file)
|
||||||
|
.arg(dir1)
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("cannot overwrite directory");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue