From b07f496b70bc75cd232cfbce901f569925c3e950 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 26 Nov 2020 21:46:03 +0100 Subject: [PATCH] fix(install): 'install file_a file_b' should just copy the file --- src/uu/install/src/install.rs | 4 +++- tests/by-util/test_install.rs | 8 ++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index 0435bb9ce..627803a02 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -390,7 +390,9 @@ fn directory(paths: Vec, b: Behavior) -> i32 { /// Test if the path is a new file path that can be /// created immediately fn is_new_file_path(path: &Path) -> bool { - !path.exists() && path.parent().map(Path::is_dir).unwrap_or(true) + !path.exists() + && (path.parent().map(Path::is_dir).unwrap_or(true) + || path.parent().unwrap().to_string_lossy().is_empty()) // In case of a simple file } /// Perform an install, given a list of paths and behavior. diff --git a/tests/by-util/test_install.rs b/tests/by-util/test_install.rs index 130713f58..ec38d11b0 100644 --- a/tests/by-util/test_install.rs +++ b/tests/by-util/test_install.rs @@ -224,7 +224,6 @@ fn test_install_target_new_file_failing_nonexistent_parent() { assert!(err.contains("not a directory")) } - // These two tests are failing but should work #[test] fn test_install_copy_file() { @@ -233,13 +232,10 @@ fn test_install_copy_file() { let file2 = "test_install_target_dir_file_a2"; at.touch(file1); - ucmd.arg(file1).arg(file2).fails(); - -/* Uncomment when fixed ucmd.arg(file1).arg(file2).succeeds().no_stderr(); assert!(at.file_exists(file1)); - assert!(at.file_exists(file2));*/ + assert!(at.file_exists(file2)); } #[test] @@ -259,4 +255,4 @@ fn test_install_target_file_dev_null() { assert!(at.file_exists(file1)); assert!(at.file_exists(file2)); */ -} \ No newline at end of file +}