mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-04 06:57:47 +00:00
Merge pull request #1068 from ids1024/cp
Correct behavior of cp -r with non-existent dest
This commit is contained in:
commit
71e8d7ad98
2 changed files with 23 additions and 26 deletions
|
@ -726,7 +726,12 @@ fn copy_directory(root: &Path, target: &Target, options: &Options) -> CopyResult
|
||||||
}
|
}
|
||||||
|
|
||||||
let root_path = Path::new(&root).canonicalize()?;
|
let root_path = Path::new(&root).canonicalize()?;
|
||||||
let root_parent = root_path.parent();
|
|
||||||
|
let root_parent = if target.exists() {
|
||||||
|
root_path.parent()
|
||||||
|
} else {
|
||||||
|
Some(root_path.as_path())
|
||||||
|
};
|
||||||
|
|
||||||
for path in WalkDir::new(root) {
|
for path in WalkDir::new(root) {
|
||||||
let path = or_continue!(or_continue!(path).path().canonicalize());
|
let path = or_continue!(or_continue!(path).path().canonicalize());
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
use common::util::*;
|
use common::util::*;
|
||||||
use std::fs::set_permissions;
|
use std::fs::set_permissions;
|
||||||
|
|
||||||
static TEST_EXISTING_FILE: &str = "existing_file.txt";
|
static TEST_EXISTING_FILE: &str = "existing_file.txt";
|
||||||
static TEST_HELLO_WORLD_SOURCE: &str = "hello_world.txt";
|
static TEST_HELLO_WORLD_SOURCE: &str = "hello_world.txt";
|
||||||
static TEST_HELLO_WORLD_DEST: &str = "copy_of_hello_world.txt";
|
static TEST_HELLO_WORLD_DEST: &str = "copy_of_hello_world.txt";
|
||||||
static TEST_HOW_ARE_YOU_SOURCE: &str = "how_are_you.txt";
|
static TEST_HOW_ARE_YOU_SOURCE: &str = "how_are_you.txt";
|
||||||
static TEST_HOW_ARE_YOU_DEST: &str = "hello_dir/how_are_you.txt";
|
static TEST_HOW_ARE_YOU_DEST: &str = "hello_dir/how_are_you.txt";
|
||||||
static TEST_COPY_TO_FOLDER: &str = "hello_dir/";
|
static TEST_COPY_TO_FOLDER: &str = "hello_dir/";
|
||||||
static TEST_COPY_TO_FOLDER_FILE: &str = "hello_dir/hello_world.txt";
|
static TEST_COPY_TO_FOLDER_FILE: &str = "hello_dir/hello_world.txt";
|
||||||
static TEST_COPY_FROM_FOLDER: &str = "hello_dir_with_file/";
|
static TEST_COPY_FROM_FOLDER: &str = "hello_dir_with_file/";
|
||||||
static TEST_COPY_FROM_FOLDER_FILE: &str = "hello_dir_with_file/hello_world.txt";
|
static TEST_COPY_FROM_FOLDER_FILE: &str = "hello_dir_with_file/hello_world.txt";
|
||||||
|
static TEST_COPY_TO_FOLDER_NEW: &str = "hello_dir_new/";
|
||||||
|
static TEST_COPY_TO_FOLDER_NEW_FILE: &str = "hello_dir_new/hello_world.txt";
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cp_cp() {
|
fn test_cp_cp() {
|
||||||
|
@ -81,27 +83,17 @@ fn test_cp_multiple_files() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cp_recurse() {
|
fn test_cp_recurse() {
|
||||||
//let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
let scene = TestScenario::new(util_name!());
|
|
||||||
let at = &scene.fixtures;
|
|
||||||
|
|
||||||
// Invoke our binary to make the copy.
|
let result = ucmd
|
||||||
let result_to_dir = scene.ucmd()
|
.arg("-r")
|
||||||
.arg(TEST_HELLO_WORLD_SOURCE)
|
.arg(TEST_COPY_FROM_FOLDER)
|
||||||
.arg(TEST_COPY_TO_FOLDER)
|
.arg(TEST_COPY_TO_FOLDER_NEW)
|
||||||
.run();
|
.run();
|
||||||
assert!(result_to_dir.success);
|
|
||||||
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
|
||||||
|
|
||||||
let result = scene.ucmd()
|
|
||||||
.arg("-r")
|
|
||||||
.arg(TEST_COPY_FROM_FOLDER)
|
|
||||||
.arg(TEST_COPY_TO_FOLDER)
|
|
||||||
.run();
|
|
||||||
|
|
||||||
assert!(result.success);
|
assert!(result.success);
|
||||||
// Check the content of the destination file that was copied.
|
// Check the content of the destination file that was copied.
|
||||||
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
assert_eq!(at.read(TEST_COPY_TO_FOLDER_NEW_FILE), "Hello, World!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue