2021-05-30 05:10:54 +00:00
|
|
|
// spell-checker:ignore (flags) reflink (fs) tmpfs
|
|
|
|
|
2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2018-09-23 00:11:13 +00:00
|
|
|
#[cfg(not(windows))]
|
2016-12-28 01:08:43 +00:00
|
|
|
use std::fs::set_permissions;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
2020-05-26 19:35:30 +00:00
|
|
|
#[cfg(not(windows))]
|
|
|
|
use std::os::unix::fs;
|
|
|
|
|
2021-06-01 21:06:38 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
use std::os::unix::fs::PermissionsExt;
|
2020-05-26 19:35:30 +00:00
|
|
|
#[cfg(windows)]
|
|
|
|
use std::os::windows::fs::symlink_file;
|
|
|
|
|
2020-08-04 21:15:33 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
use filetime::FileTime;
|
2020-05-28 19:54:03 +00:00
|
|
|
#[cfg(not(windows))]
|
|
|
|
use std::env;
|
2020-08-04 21:15:33 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
use std::fs as std_fs;
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
use std::thread::sleep;
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
use std::time::Duration;
|
2020-05-28 19:54:03 +00:00
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
static TEST_EXISTING_FILE: &str = "existing_file.txt";
|
|
|
|
static TEST_HELLO_WORLD_SOURCE: &str = "hello_world.txt";
|
2020-05-26 19:35:30 +00:00
|
|
|
static TEST_HELLO_WORLD_SOURCE_SYMLINK: &str = "hello_world.txt.link";
|
2020-04-13 18:36:03 +00:00
|
|
|
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_DEST: &str = "hello_dir/how_are_you.txt";
|
|
|
|
static TEST_COPY_TO_FOLDER: &str = "hello_dir/";
|
|
|
|
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_FILE: &str = "hello_dir_with_file/hello_world.txt";
|
2020-05-28 19:54:03 +00:00
|
|
|
static TEST_COPY_TO_FOLDER_NEW: &str = "hello_dir_new";
|
2017-08-10 23:04:25 +00:00
|
|
|
static TEST_COPY_TO_FOLDER_NEW_FILE: &str = "hello_dir_new/hello_world.txt";
|
2021-03-19 20:15:35 +00:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
|
|
|
static TEST_MOUNT_COPY_FROM_FOLDER: &str = "dir_with_mount";
|
|
|
|
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
|
|
|
static TEST_MOUNT_MOUNTPOINT: &str = "mount";
|
|
|
|
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
|
|
|
static TEST_MOUNT_OTHER_FILESYSTEM_FILE: &str = "mount/DO_NOT_copy_me.txt";
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_cp() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2015-11-16 05:25:01 +00:00
|
|
|
// Invoke our binary to make the copy.
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
2020-04-13 18:36:03 +00:00
|
|
|
.arg(TEST_HELLO_WORLD_DEST)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
// Check the content of the destination file that was copied.
|
|
|
|
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
|
|
|
|
}
|
2016-07-15 17:17:30 +00:00
|
|
|
|
2018-09-23 00:10:14 +00:00
|
|
|
#[test]
|
|
|
|
fn test_cp_existing_target() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
2018-09-23 00:10:14 +00:00
|
|
|
.arg(TEST_EXISTING_FILE)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2018-09-23 00:10:14 +00:00
|
|
|
|
|
|
|
// Check the content of the destination file
|
|
|
|
assert_eq!(at.read(TEST_EXISTING_FILE), "Hello, World!\n");
|
|
|
|
|
|
|
|
// No backup should have been created
|
|
|
|
assert!(!at.file_exists(&*format!("{}~", TEST_EXISTING_FILE)));
|
|
|
|
}
|
|
|
|
|
2016-12-28 01:08:43 +00:00
|
|
|
#[test]
|
|
|
|
fn test_cp_duplicate_files() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
2016-12-28 01:08:43 +00:00
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_COPY_TO_FOLDER)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds()
|
|
|
|
.stderr_contains("specified more than once");
|
2016-12-28 01:08:43 +00:00
|
|
|
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_multiple_files_target_is_file() {
|
2021-04-22 20:37:44 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
2016-12-28 01:08:43 +00:00
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_EXISTING_FILE)
|
2021-04-22 20:37:44 +00:00
|
|
|
.fails()
|
|
|
|
.stderr_contains("not a directory");
|
2016-12-28 01:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_directory_not_recursive() {
|
2021-04-22 20:37:44 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.arg(TEST_COPY_TO_FOLDER)
|
2016-12-28 01:08:43 +00:00
|
|
|
.arg(TEST_HELLO_WORLD_DEST)
|
2021-04-22 20:37:44 +00:00
|
|
|
.fails()
|
|
|
|
.stderr_contains("omitting directory");
|
2016-12-28 01:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_multiple_files() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
2016-12-28 01:08:43 +00:00
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
|
|
|
.arg(TEST_COPY_TO_FOLDER)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2016-12-28 01:08:43 +00:00
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_DEST), "How are you?\n");
|
|
|
|
}
|
|
|
|
|
2017-06-02 11:37:31 +00:00
|
|
|
#[test]
|
2020-10-14 20:34:28 +00:00
|
|
|
// FixME: for MacOS, this has intermittent failures; track repair progress at GH:uutils/coreutils/issues/1590
|
2021-05-29 12:32:35 +00:00
|
|
|
#[cfg(not(target_os = "macos"))]
|
2017-06-02 11:37:31 +00:00
|
|
|
fn test_cp_recurse() {
|
2017-08-10 23:04:25 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg("-r")
|
2017-08-10 23:04:25 +00:00
|
|
|
.arg(TEST_COPY_FROM_FOLDER)
|
|
|
|
.arg(TEST_COPY_TO_FOLDER_NEW)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2017-06-02 11:37:31 +00:00
|
|
|
|
|
|
|
// Check the content of the destination file that was copied.
|
2017-08-10 23:04:25 +00:00
|
|
|
assert_eq!(at.read(TEST_COPY_TO_FOLDER_NEW_FILE), "Hello, World!\n");
|
2017-06-02 11:37:31 +00:00
|
|
|
}
|
|
|
|
|
2016-07-15 17:17:30 +00:00
|
|
|
#[test]
|
|
|
|
fn test_cp_with_dirs_t() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg("-t")
|
2016-07-15 17:17:30 +00:00
|
|
|
.arg(TEST_COPY_TO_FOLDER)
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2016-07-15 17:17:30 +00:00
|
|
|
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-10-14 20:34:28 +00:00
|
|
|
// FixME: for MacOS, this has intermittent failures; track repair progress at GH:uutils/coreutils/issues/1590
|
2021-05-29 12:32:35 +00:00
|
|
|
#[cfg(not(target_os = "macos"))]
|
2016-07-15 17:17:30 +00:00
|
|
|
fn test_cp_with_dirs() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let scene = TestScenario::new(util_name!());
|
2016-07-29 21:26:32 +00:00
|
|
|
let at = &scene.fixtures;
|
2016-07-15 17:17:30 +00:00
|
|
|
|
2021-04-22 20:37:44 +00:00
|
|
|
scene
|
2020-04-13 18:36:03 +00:00
|
|
|
.ucmd()
|
2016-07-15 17:17:30 +00:00
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_COPY_TO_FOLDER)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2016-07-15 17:17:30 +00:00
|
|
|
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
|
|
|
|
2021-04-22 20:37:44 +00:00
|
|
|
scene
|
2020-04-13 18:36:03 +00:00
|
|
|
.ucmd()
|
2016-07-15 17:17:30 +00:00
|
|
|
.arg(TEST_COPY_FROM_FOLDER_FILE)
|
|
|
|
.arg(TEST_HELLO_WORLD_DEST)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2016-07-15 17:17:30 +00:00
|
|
|
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
|
2016-07-29 21:26:32 +00:00
|
|
|
}
|
2016-12-28 01:08:43 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_arg_target_directory() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
2016-12-28 01:08:43 +00:00
|
|
|
.arg("-t")
|
|
|
|
.arg(TEST_COPY_TO_FOLDER)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2016-12-28 01:08:43 +00:00
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_arg_no_target_directory() {
|
2021-04-22 20:37:44 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
2016-12-28 01:08:43 +00:00
|
|
|
.arg("-v")
|
|
|
|
.arg("-T")
|
|
|
|
.arg(TEST_COPY_TO_FOLDER)
|
2021-04-22 20:37:44 +00:00
|
|
|
.fails()
|
|
|
|
.stderr_contains("cannot overwrite directory");
|
2016-12-28 01:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_arg_interactive() {
|
2021-04-22 20:37:44 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
2016-12-28 01:08:43 +00:00
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
|
|
|
.arg("-i")
|
|
|
|
.pipe_in("N\n")
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds()
|
|
|
|
.stderr_contains("Not overwriting");
|
2016-12-28 01:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-08-04 21:15:33 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
2016-12-28 01:08:43 +00:00
|
|
|
fn test_cp_arg_link() {
|
|
|
|
use std::os::linux::fs::MetadataExt;
|
|
|
|
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
2016-12-28 01:08:43 +00:00
|
|
|
.arg("--link")
|
|
|
|
.arg(TEST_HELLO_WORLD_DEST)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2016-12-28 01:08:43 +00:00
|
|
|
|
|
|
|
assert_eq!(at.metadata(TEST_HELLO_WORLD_SOURCE).st_nlink(), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_arg_symlink() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
2016-12-28 01:08:43 +00:00
|
|
|
.arg("--symbolic-link")
|
|
|
|
.arg(TEST_HELLO_WORLD_DEST)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2016-12-28 01:08:43 +00:00
|
|
|
|
|
|
|
assert!(at.is_symlink(TEST_HELLO_WORLD_DEST));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_arg_no_clobber() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
2016-12-28 01:08:43 +00:00
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
2021-05-25 20:41:07 +00:00
|
|
|
.arg("--no-clobber")
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2016-12-28 01:08:43 +00:00
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "How are you?\n");
|
2020-12-16 22:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_arg_no_clobber_twice() {
|
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
let at = &scene.fixtures;
|
2021-04-22 20:37:44 +00:00
|
|
|
|
2020-12-16 22:52:42 +00:00
|
|
|
at.touch("source.txt");
|
2021-04-22 20:37:44 +00:00
|
|
|
scene
|
2020-12-16 22:52:42 +00:00
|
|
|
.ucmd()
|
|
|
|
.arg("--no-clobber")
|
|
|
|
.arg("source.txt")
|
|
|
|
.arg("dest.txt")
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
2020-12-16 22:52:42 +00:00
|
|
|
|
|
|
|
assert_eq!(at.read("source.txt"), "");
|
|
|
|
|
|
|
|
at.append("source.txt", "some-content");
|
2021-04-22 20:37:44 +00:00
|
|
|
scene
|
2020-12-16 22:52:42 +00:00
|
|
|
.ucmd()
|
|
|
|
.arg("--no-clobber")
|
|
|
|
.arg("source.txt")
|
|
|
|
.arg("dest.txt")
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_does_not_contain("Not overwriting");
|
2020-12-16 22:52:42 +00:00
|
|
|
|
|
|
|
assert_eq!(at.read("source.txt"), "some-content");
|
|
|
|
// Should be empty as the "no-clobber" should keep
|
|
|
|
// the previous version
|
|
|
|
assert_eq!(at.read("dest.txt"), "");
|
2016-12-28 01:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
fn test_cp_arg_force() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
// create dest without write permissions
|
2020-04-13 18:36:03 +00:00
|
|
|
let mut permissions = at
|
|
|
|
.make_file(TEST_HELLO_WORLD_DEST)
|
|
|
|
.metadata()
|
|
|
|
.unwrap()
|
|
|
|
.permissions();
|
2016-12-28 01:08:43 +00:00
|
|
|
permissions.set_readonly(true);
|
|
|
|
set_permissions(at.plus(TEST_HELLO_WORLD_DEST), permissions).unwrap();
|
|
|
|
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
2016-12-28 01:08:43 +00:00
|
|
|
.arg("--force")
|
|
|
|
.arg(TEST_HELLO_WORLD_DEST)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2016-12-28 01:08:43 +00:00
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// TODO: write a better test that differentiates --remove-destination
|
|
|
|
/// from --force. Also this test currently doesn't work on
|
|
|
|
/// Windows. This test originally checked file timestamps, which
|
|
|
|
/// proved to be unreliable per target / CI platform
|
|
|
|
#[test]
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
fn test_cp_arg_remove_destination() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
// create dest without write permissions
|
2020-04-13 18:36:03 +00:00
|
|
|
let mut permissions = at
|
|
|
|
.make_file(TEST_HELLO_WORLD_DEST)
|
|
|
|
.metadata()
|
|
|
|
.unwrap()
|
|
|
|
.permissions();
|
2016-12-28 01:08:43 +00:00
|
|
|
permissions.set_readonly(true);
|
|
|
|
set_permissions(at.plus(TEST_HELLO_WORLD_DEST), permissions).unwrap();
|
|
|
|
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
2016-12-28 01:08:43 +00:00
|
|
|
.arg("--remove-destination")
|
|
|
|
.arg(TEST_HELLO_WORLD_DEST)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2016-12-28 01:08:43 +00:00
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_arg_backup() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
2021-05-25 20:41:07 +00:00
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
|
|
|
.arg("-b")
|
|
|
|
.succeeds();
|
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
|
|
|
assert_eq!(
|
|
|
|
at.read(&*format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
|
|
|
"How are you?\n"
|
2021-05-26 22:28:17 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_arg_backup_with_other_args() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
|
|
|
.arg("-vbL")
|
|
|
|
.succeeds();
|
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
|
|
|
assert_eq!(
|
|
|
|
at.read(&*format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
|
|
|
"How are you?\n"
|
2021-05-25 20:41:07 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_arg_backup_arg_first() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
ucmd.arg("--backup")
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
2016-12-28 01:08:43 +00:00
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2016-12-28 01:08:43 +00:00
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
2020-04-13 18:36:03 +00:00
|
|
|
assert_eq!(
|
|
|
|
at.read(&*format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
|
|
|
"How are you?\n"
|
|
|
|
);
|
2016-12-28 01:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_arg_suffix() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
2021-05-25 20:41:07 +00:00
|
|
|
.arg("-b")
|
2016-12-28 01:08:43 +00:00
|
|
|
.arg("--suffix")
|
|
|
|
.arg(".bak")
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2016-12-28 01:08:43 +00:00
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
2020-04-13 18:36:03 +00:00
|
|
|
assert_eq!(
|
|
|
|
at.read(&*format!("{}.bak", TEST_HOW_ARE_YOU_SOURCE)),
|
|
|
|
"How are you?\n"
|
|
|
|
);
|
2016-12-28 01:08:43 +00:00
|
|
|
}
|
2020-05-26 19:35:30 +00:00
|
|
|
|
2021-05-25 20:41:07 +00:00
|
|
|
#[test]
|
|
|
|
fn test_cp_custom_backup_suffix_via_env() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let suffix = "super-suffix-of-the-century";
|
|
|
|
|
|
|
|
ucmd.arg("-b")
|
|
|
|
.env("SIMPLE_BACKUP_SUFFIX", suffix)
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
|
|
|
assert_eq!(
|
|
|
|
at.read(&*format!("{}{}", TEST_HOW_ARE_YOU_SOURCE, suffix)),
|
|
|
|
"How are you?\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_backup_numbered_with_t() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
ucmd.arg("--backup=t")
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
|
|
|
assert_eq!(
|
|
|
|
at.read(&*format!("{}.~1~", TEST_HOW_ARE_YOU_SOURCE)),
|
|
|
|
"How are you?\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_backup_numbered() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
ucmd.arg("--backup=numbered")
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
|
|
|
assert_eq!(
|
|
|
|
at.read(&*format!("{}.~1~", TEST_HOW_ARE_YOU_SOURCE)),
|
|
|
|
"How are you?\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_backup_existing() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
ucmd.arg("--backup=existing")
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
|
|
|
assert_eq!(
|
|
|
|
at.read(&*format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
|
|
|
"How are you?\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_backup_nil() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
ucmd.arg("--backup=nil")
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
|
|
|
assert_eq!(
|
|
|
|
at.read(&*format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
|
|
|
"How are you?\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_numbered_if_existing_backup_existing() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let existing_backup = &*format!("{}.~1~", TEST_HOW_ARE_YOU_SOURCE);
|
|
|
|
at.touch(existing_backup);
|
|
|
|
|
|
|
|
ucmd.arg("--backup=existing")
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
|
|
|
|
|
|
|
assert!(at.file_exists(TEST_HOW_ARE_YOU_SOURCE));
|
|
|
|
assert!(at.file_exists(existing_backup));
|
|
|
|
assert_eq!(
|
|
|
|
at.read(&*format!("{}.~2~", TEST_HOW_ARE_YOU_SOURCE)),
|
|
|
|
"How are you?\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_numbered_if_existing_backup_nil() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let existing_backup = &*format!("{}.~1~", TEST_HOW_ARE_YOU_SOURCE);
|
|
|
|
|
|
|
|
at.touch(existing_backup);
|
|
|
|
ucmd.arg("--backup=nil")
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
|
|
|
|
|
|
|
assert!(at.file_exists(TEST_HOW_ARE_YOU_SOURCE));
|
|
|
|
assert!(at.file_exists(existing_backup));
|
|
|
|
assert_eq!(
|
|
|
|
at.read(&*format!("{}.~2~", TEST_HOW_ARE_YOU_SOURCE)),
|
|
|
|
"How are you?\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_backup_simple() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
ucmd.arg("--backup=simple")
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
|
|
|
assert_eq!(
|
|
|
|
at.read(&*format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
|
|
|
"How are you?\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_backup_never() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
ucmd.arg("--backup=never")
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
|
|
|
assert_eq!(
|
|
|
|
at.read(&*format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
|
|
|
"How are you?\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_backup_none() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
ucmd.arg("--backup=none")
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
|
|
|
assert!(!at.file_exists(&format!("{}~", TEST_HOW_ARE_YOU_SOURCE)));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_backup_off() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
ucmd.arg("--backup=off")
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
|
|
|
assert!(!at.file_exists(&format!("{}~", TEST_HOW_ARE_YOU_SOURCE)));
|
|
|
|
}
|
|
|
|
|
2021-05-26 14:50:41 +00:00
|
|
|
#[test]
|
|
|
|
fn test_cp_backup_no_clobber_conflicting_options() {
|
|
|
|
let (_, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
ucmd.arg("--backup")
|
|
|
|
.arg("--no-clobber")
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
|
|
|
.fails()
|
|
|
|
.stderr_is("cp: options --backup and --no-clobber are mutually exclusive\nTry 'cp --help' for more information.");
|
|
|
|
}
|
|
|
|
|
2020-11-11 20:41:02 +00:00
|
|
|
#[test]
|
|
|
|
fn test_cp_deref_conflicting_options() {
|
2021-04-22 20:37:44 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg("-LP")
|
2020-11-11 20:41:02 +00:00
|
|
|
.arg(TEST_COPY_TO_FOLDER)
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.fails();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_deref() {
|
2021-04-22 20:37:44 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2020-11-11 20:41:02 +00:00
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
let _r = fs::symlink(
|
|
|
|
TEST_HELLO_WORLD_SOURCE,
|
|
|
|
at.subdir.join(TEST_HELLO_WORLD_SOURCE_SYMLINK),
|
|
|
|
);
|
|
|
|
#[cfg(windows)]
|
|
|
|
let _r = symlink_file(
|
|
|
|
TEST_HELLO_WORLD_SOURCE,
|
|
|
|
at.subdir.join(TEST_HELLO_WORLD_SOURCE_SYMLINK),
|
|
|
|
);
|
|
|
|
//using -L option
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg("-L")
|
2020-11-11 20:41:02 +00:00
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE_SYMLINK)
|
|
|
|
.arg(TEST_COPY_TO_FOLDER)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2020-11-11 20:41:02 +00:00
|
|
|
|
|
|
|
let path_to_new_symlink = at
|
|
|
|
.subdir
|
|
|
|
.join(TEST_COPY_TO_FOLDER)
|
|
|
|
.join(TEST_HELLO_WORLD_SOURCE_SYMLINK);
|
|
|
|
// unlike -P/--no-deref, we expect a file, not a link
|
|
|
|
assert!(at.file_exists(
|
|
|
|
&path_to_new_symlink
|
|
|
|
.clone()
|
|
|
|
.into_os_string()
|
|
|
|
.into_string()
|
|
|
|
.unwrap()
|
|
|
|
));
|
|
|
|
// Check the content of the destination file that was copied.
|
|
|
|
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
|
|
|
let path_to_check = path_to_new_symlink.to_str().unwrap();
|
|
|
|
assert_eq!(at.read(&path_to_check), "Hello, World!\n");
|
|
|
|
}
|
2020-05-26 19:35:30 +00:00
|
|
|
#[test]
|
|
|
|
fn test_cp_no_deref() {
|
2021-04-22 20:37:44 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2020-05-26 19:35:30 +00:00
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
let _r = fs::symlink(
|
|
|
|
TEST_HELLO_WORLD_SOURCE,
|
|
|
|
at.subdir.join(TEST_HELLO_WORLD_SOURCE_SYMLINK),
|
|
|
|
);
|
|
|
|
#[cfg(windows)]
|
|
|
|
let _r = symlink_file(
|
|
|
|
TEST_HELLO_WORLD_SOURCE,
|
|
|
|
at.subdir.join(TEST_HELLO_WORLD_SOURCE_SYMLINK),
|
|
|
|
);
|
2020-05-28 19:54:03 +00:00
|
|
|
//using -P option
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg("-P")
|
2020-05-26 19:35:30 +00:00
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE_SYMLINK)
|
|
|
|
.arg(TEST_COPY_TO_FOLDER)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2020-05-26 19:35:30 +00:00
|
|
|
|
|
|
|
let path_to_new_symlink = at
|
|
|
|
.subdir
|
|
|
|
.join(TEST_COPY_TO_FOLDER)
|
|
|
|
.join(TEST_HELLO_WORLD_SOURCE_SYMLINK);
|
|
|
|
assert!(at.is_symlink(
|
|
|
|
&path_to_new_symlink
|
|
|
|
.clone()
|
|
|
|
.into_os_string()
|
|
|
|
.into_string()
|
|
|
|
.unwrap()
|
|
|
|
));
|
|
|
|
// Check the content of the destination file that was copied.
|
|
|
|
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
|
|
|
let path_to_check = path_to_new_symlink.to_str().unwrap();
|
|
|
|
assert_eq!(at.read(&path_to_check), "Hello, World!\n");
|
|
|
|
}
|
2020-05-28 19:54:03 +00:00
|
|
|
|
2021-03-09 10:59:26 +00:00
|
|
|
#[test]
|
|
|
|
fn test_cp_strip_trailing_slashes() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
//using --strip-trailing-slashes option
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg("--strip-trailing-slashes")
|
2021-03-09 10:59:26 +00:00
|
|
|
.arg(format!("{}/", TEST_HELLO_WORLD_SOURCE))
|
|
|
|
.arg(TEST_HELLO_WORLD_DEST)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2021-03-09 10:59:26 +00:00
|
|
|
|
|
|
|
// Check the content of the destination file that was copied.
|
|
|
|
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:25:15 +00:00
|
|
|
#[test]
|
|
|
|
fn test_cp_parents() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg("--parents")
|
2021-03-12 12:25:15 +00:00
|
|
|
.arg(TEST_COPY_FROM_FOLDER_FILE)
|
|
|
|
.arg(TEST_COPY_TO_FOLDER)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2021-03-12 12:25:15 +00:00
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
at.read(&format!(
|
|
|
|
"{}/{}",
|
|
|
|
TEST_COPY_TO_FOLDER, TEST_COPY_FROM_FOLDER_FILE
|
|
|
|
)),
|
|
|
|
"Hello, World!\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_parents_multiple_files() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg("--parents")
|
2021-03-12 12:25:15 +00:00
|
|
|
.arg(TEST_COPY_FROM_FOLDER_FILE)
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
|
|
|
.arg(TEST_COPY_TO_FOLDER)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2021-03-12 12:25:15 +00:00
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
at.read(&format!(
|
|
|
|
"{}/{}",
|
|
|
|
TEST_COPY_TO_FOLDER, TEST_COPY_FROM_FOLDER_FILE
|
|
|
|
)),
|
|
|
|
"Hello, World!\n"
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
at.read(&format!(
|
|
|
|
"{}/{}",
|
|
|
|
TEST_COPY_TO_FOLDER, TEST_HOW_ARE_YOU_SOURCE
|
|
|
|
)),
|
|
|
|
"How are you?\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cp_parents_dest_not_directory() {
|
2021-04-22 20:37:44 +00:00
|
|
|
new_ucmd!()
|
2021-03-12 12:25:15 +00:00
|
|
|
.arg("--parents")
|
|
|
|
.arg(TEST_COPY_FROM_FOLDER_FILE)
|
|
|
|
.arg(TEST_HELLO_WORLD_DEST)
|
2021-04-22 20:37:44 +00:00
|
|
|
.fails()
|
|
|
|
.stderr_contains("with --parents, the destination must be a directory");
|
2021-03-12 12:25:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-11 20:41:02 +00:00
|
|
|
#[test]
|
|
|
|
// For now, disable the test on Windows. Symlinks aren't well support on Windows.
|
|
|
|
// It works on Unix for now and it works locally when run from a powershell
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
fn test_cp_deref_folder_to_folder() {
|
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
let at = &scene.fixtures;
|
|
|
|
|
|
|
|
let cwd = env::current_dir().unwrap();
|
|
|
|
|
|
|
|
let path_to_new_symlink = at.subdir.join(TEST_COPY_FROM_FOLDER);
|
|
|
|
|
|
|
|
// Change the cwd to have a correct symlink
|
|
|
|
assert!(env::set_current_dir(&path_to_new_symlink).is_ok());
|
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
let _r = fs::symlink(TEST_HELLO_WORLD_SOURCE, TEST_HELLO_WORLD_SOURCE_SYMLINK);
|
|
|
|
#[cfg(windows)]
|
|
|
|
let _r = symlink_file(TEST_HELLO_WORLD_SOURCE, TEST_HELLO_WORLD_SOURCE_SYMLINK);
|
|
|
|
|
|
|
|
// Back to the initial cwd (breaks the other tests)
|
|
|
|
assert!(env::set_current_dir(&cwd).is_ok());
|
|
|
|
|
|
|
|
//using -P -R option
|
2021-04-22 20:37:44 +00:00
|
|
|
scene
|
2020-11-11 20:41:02 +00:00
|
|
|
.ucmd()
|
|
|
|
.arg("-L")
|
|
|
|
.arg("-R")
|
|
|
|
.arg("-v")
|
|
|
|
.arg(TEST_COPY_FROM_FOLDER)
|
|
|
|
.arg(TEST_COPY_TO_FOLDER_NEW)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2020-11-11 20:41:02 +00:00
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
{
|
|
|
|
let scene2 = TestScenario::new("ls");
|
|
|
|
let result = scene2.cmd("ls").arg("-al").arg(path_to_new_symlink).run();
|
2021-04-05 20:03:43 +00:00
|
|
|
println!("ls source {}", result.stdout_str());
|
2020-11-11 20:41:02 +00:00
|
|
|
|
|
|
|
let path_to_new_symlink = at.subdir.join(TEST_COPY_TO_FOLDER_NEW);
|
|
|
|
|
|
|
|
let result = scene2.cmd("ls").arg("-al").arg(path_to_new_symlink).run();
|
2021-04-05 20:03:43 +00:00
|
|
|
println!("ls dest {}", result.stdout_str());
|
2020-11-11 20:41:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
{
|
|
|
|
// No action as this test is disabled but kept in case we want to
|
|
|
|
// try to make it work in the future.
|
|
|
|
let a = Command::new("cmd").args(&["/C", "dir"]).output();
|
|
|
|
println!("output {:#?}", a);
|
|
|
|
|
|
|
|
let a = Command::new("cmd")
|
|
|
|
.args(&["/C", "dir", &at.as_string()])
|
|
|
|
.output();
|
|
|
|
println!("output {:#?}", a);
|
|
|
|
|
|
|
|
let a = Command::new("cmd")
|
|
|
|
.args(&["/C", "dir", path_to_new_symlink.to_str().unwrap()])
|
|
|
|
.output();
|
|
|
|
println!("output {:#?}", a);
|
|
|
|
|
|
|
|
let path_to_new_symlink = at.subdir.join(TEST_COPY_FROM_FOLDER);
|
|
|
|
|
|
|
|
let a = Command::new("cmd")
|
|
|
|
.args(&["/C", "dir", path_to_new_symlink.to_str().unwrap()])
|
|
|
|
.output();
|
|
|
|
println!("output {:#?}", a);
|
|
|
|
|
|
|
|
let path_to_new_symlink = at.subdir.join(TEST_COPY_TO_FOLDER_NEW);
|
|
|
|
|
|
|
|
let a = Command::new("cmd")
|
|
|
|
.args(&["/C", "dir", path_to_new_symlink.to_str().unwrap()])
|
|
|
|
.output();
|
|
|
|
println!("output {:#?}", a);
|
|
|
|
}
|
|
|
|
|
|
|
|
let path_to_new_symlink = at
|
|
|
|
.subdir
|
|
|
|
.join(TEST_COPY_TO_FOLDER_NEW)
|
|
|
|
.join(TEST_HELLO_WORLD_SOURCE_SYMLINK);
|
|
|
|
assert!(at.file_exists(
|
|
|
|
&path_to_new_symlink
|
|
|
|
.clone()
|
|
|
|
.into_os_string()
|
|
|
|
.into_string()
|
|
|
|
.unwrap()
|
|
|
|
));
|
|
|
|
|
|
|
|
let path_to_new = at.subdir.join(TEST_COPY_TO_FOLDER_NEW_FILE);
|
|
|
|
|
|
|
|
// Check the content of the destination file that was copied.
|
|
|
|
let path_to_check = path_to_new.to_str().unwrap();
|
|
|
|
assert_eq!(at.read(path_to_check), "Hello, World!\n");
|
|
|
|
|
|
|
|
// Check the content of the symlink
|
|
|
|
let path_to_check = path_to_new_symlink.to_str().unwrap();
|
|
|
|
assert_eq!(at.read(&path_to_check), "Hello, World!\n");
|
|
|
|
}
|
|
|
|
|
2020-05-28 19:54:03 +00:00
|
|
|
#[test]
|
|
|
|
// For now, disable the test on Windows. Symlinks aren't well support on Windows.
|
|
|
|
// It works on Unix for now and it works locally when run from a powershell
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
fn test_cp_no_deref_folder_to_folder() {
|
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
let at = &scene.fixtures;
|
|
|
|
|
|
|
|
let cwd = env::current_dir().unwrap();
|
|
|
|
|
|
|
|
let path_to_new_symlink = at.subdir.join(TEST_COPY_FROM_FOLDER);
|
|
|
|
|
|
|
|
// Change the cwd to have a correct symlink
|
|
|
|
assert!(env::set_current_dir(&path_to_new_symlink).is_ok());
|
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
let _r = fs::symlink(TEST_HELLO_WORLD_SOURCE, TEST_HELLO_WORLD_SOURCE_SYMLINK);
|
|
|
|
#[cfg(windows)]
|
|
|
|
let _r = symlink_file(TEST_HELLO_WORLD_SOURCE, TEST_HELLO_WORLD_SOURCE_SYMLINK);
|
|
|
|
|
|
|
|
// Back to the initial cwd (breaks the other tests)
|
|
|
|
assert!(env::set_current_dir(&cwd).is_ok());
|
|
|
|
|
|
|
|
//using -P -R option
|
2021-04-22 20:37:44 +00:00
|
|
|
scene
|
2020-05-28 19:54:03 +00:00
|
|
|
.ucmd()
|
|
|
|
.arg("-P")
|
|
|
|
.arg("-R")
|
|
|
|
.arg("-v")
|
|
|
|
.arg(TEST_COPY_FROM_FOLDER)
|
|
|
|
.arg(TEST_COPY_TO_FOLDER_NEW)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2020-05-28 19:54:03 +00:00
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
{
|
|
|
|
let scene2 = TestScenario::new("ls");
|
|
|
|
let result = scene2.cmd("ls").arg("-al").arg(path_to_new_symlink).run();
|
2021-04-05 20:03:43 +00:00
|
|
|
println!("ls source {}", result.stdout_str());
|
2020-05-28 19:54:03 +00:00
|
|
|
|
|
|
|
let path_to_new_symlink = at.subdir.join(TEST_COPY_TO_FOLDER_NEW);
|
|
|
|
|
|
|
|
let result = scene2.cmd("ls").arg("-al").arg(path_to_new_symlink).run();
|
2021-04-05 20:03:43 +00:00
|
|
|
println!("ls dest {}", result.stdout_str());
|
2020-05-28 19:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
{
|
|
|
|
// No action as this test is disabled but kept in case we want to
|
|
|
|
// try to make it work in the future.
|
|
|
|
let a = Command::new("cmd").args(&["/C", "dir"]).output();
|
|
|
|
println!("output {:#?}", a);
|
|
|
|
|
|
|
|
let a = Command::new("cmd")
|
|
|
|
.args(&["/C", "dir", &at.as_string()])
|
|
|
|
.output();
|
|
|
|
println!("output {:#?}", a);
|
|
|
|
|
|
|
|
let a = Command::new("cmd")
|
|
|
|
.args(&["/C", "dir", path_to_new_symlink.to_str().unwrap()])
|
|
|
|
.output();
|
|
|
|
println!("output {:#?}", a);
|
|
|
|
|
|
|
|
let path_to_new_symlink = at.subdir.join(TEST_COPY_FROM_FOLDER);
|
|
|
|
|
|
|
|
let a = Command::new("cmd")
|
|
|
|
.args(&["/C", "dir", path_to_new_symlink.to_str().unwrap()])
|
|
|
|
.output();
|
|
|
|
println!("output {:#?}", a);
|
|
|
|
|
|
|
|
let path_to_new_symlink = at.subdir.join(TEST_COPY_TO_FOLDER_NEW);
|
|
|
|
|
|
|
|
let a = Command::new("cmd")
|
|
|
|
.args(&["/C", "dir", path_to_new_symlink.to_str().unwrap()])
|
|
|
|
.output();
|
|
|
|
println!("output {:#?}", a);
|
|
|
|
}
|
|
|
|
|
|
|
|
let path_to_new_symlink = at
|
|
|
|
.subdir
|
|
|
|
.join(TEST_COPY_TO_FOLDER_NEW)
|
|
|
|
.join(TEST_HELLO_WORLD_SOURCE_SYMLINK);
|
|
|
|
assert!(at.is_symlink(
|
|
|
|
&path_to_new_symlink
|
|
|
|
.clone()
|
|
|
|
.into_os_string()
|
|
|
|
.into_string()
|
|
|
|
.unwrap()
|
|
|
|
));
|
|
|
|
|
|
|
|
let path_to_new = at.subdir.join(TEST_COPY_TO_FOLDER_NEW_FILE);
|
|
|
|
|
|
|
|
// Check the content of the destination file that was copied.
|
|
|
|
let path_to_check = path_to_new.to_str().unwrap();
|
|
|
|
assert_eq!(at.read(path_to_check), "Hello, World!\n");
|
|
|
|
|
|
|
|
// Check the content of the symlink
|
|
|
|
let path_to_check = path_to_new_symlink.to_str().unwrap();
|
|
|
|
assert_eq!(at.read(&path_to_check), "Hello, World!\n");
|
|
|
|
}
|
2020-08-04 21:15:33 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
fn test_cp_archive() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let ts = time::now().to_timespec();
|
|
|
|
let previous = FileTime::from_unix_time(ts.sec as i64 - 3600, ts.nsec as u32);
|
2021-05-30 05:10:54 +00:00
|
|
|
// set the file creation/modification an hour ago
|
2020-08-04 21:15:33 +00:00
|
|
|
filetime::set_file_times(
|
|
|
|
at.plus_as_string(TEST_HELLO_WORLD_SOURCE),
|
|
|
|
previous,
|
|
|
|
previous,
|
|
|
|
)
|
|
|
|
.unwrap();
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
2020-08-04 21:15:33 +00:00
|
|
|
.arg("--archive")
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2020-08-04 21:15:33 +00:00
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
|
|
|
|
|
|
|
let metadata = std_fs::metadata(at.subdir.join(TEST_HELLO_WORLD_SOURCE)).unwrap();
|
|
|
|
let creation = metadata.modified().unwrap();
|
|
|
|
|
|
|
|
let metadata2 = std_fs::metadata(at.subdir.join(TEST_HOW_ARE_YOU_SOURCE)).unwrap();
|
|
|
|
let creation2 = metadata2.modified().unwrap();
|
|
|
|
|
|
|
|
let scene2 = TestScenario::new("ls");
|
2021-04-22 20:37:44 +00:00
|
|
|
let result = scene2.cmd("ls").arg("-al").arg(at.subdir).succeeds();
|
2020-08-04 21:15:33 +00:00
|
|
|
|
2021-04-05 20:03:43 +00:00
|
|
|
println!("ls dest {}", result.stdout_str());
|
2020-08-04 21:15:33 +00:00
|
|
|
assert_eq!(creation, creation2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[cfg(target_os = "unix")]
|
|
|
|
fn test_cp_archive_recursive() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let cwd = env::current_dir().unwrap();
|
|
|
|
|
|
|
|
// creates
|
|
|
|
// dir/1
|
|
|
|
// dir/1.link => dir/1
|
|
|
|
// dir/2
|
|
|
|
// dir/2.link => dir/2
|
|
|
|
|
|
|
|
let file_1 = at.subdir.join(TEST_COPY_TO_FOLDER).join("1");
|
|
|
|
let file_1_link = at.subdir.join(TEST_COPY_TO_FOLDER).join("1.link");
|
|
|
|
let file_2 = at.subdir.join(TEST_COPY_TO_FOLDER).join("2");
|
|
|
|
let file_2_link = at.subdir.join(TEST_COPY_TO_FOLDER).join("2.link");
|
|
|
|
|
|
|
|
at.touch(&file_1.to_string_lossy());
|
|
|
|
at.touch(&file_2.to_string_lossy());
|
|
|
|
|
|
|
|
// Change the cwd to have a correct symlink
|
|
|
|
assert!(env::set_current_dir(&at.subdir.join(TEST_COPY_TO_FOLDER)).is_ok());
|
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
{
|
|
|
|
let _r = fs::symlink("1", &file_1_link);
|
|
|
|
let _r = fs::symlink("2", &file_2_link);
|
|
|
|
}
|
|
|
|
#[cfg(windows)]
|
|
|
|
{
|
|
|
|
let _r = symlink_file("1", &file_1_link);
|
|
|
|
let _r = symlink_file("2", &file_2_link);
|
|
|
|
}
|
|
|
|
// Back to the initial cwd (breaks the other tests)
|
|
|
|
assert!(env::set_current_dir(&cwd).is_ok());
|
|
|
|
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg("--archive")
|
2020-08-04 21:15:33 +00:00
|
|
|
.arg(TEST_COPY_TO_FOLDER)
|
|
|
|
.arg(TEST_COPY_TO_FOLDER_NEW)
|
2021-04-22 20:37:44 +00:00
|
|
|
.fails(); // fails for now
|
2020-08-04 21:15:33 +00:00
|
|
|
|
|
|
|
let scene2 = TestScenario::new("ls");
|
|
|
|
let result = scene2
|
|
|
|
.cmd("ls")
|
|
|
|
.arg("-al")
|
|
|
|
.arg(&at.subdir.join(TEST_COPY_TO_FOLDER))
|
|
|
|
.run();
|
|
|
|
|
2021-04-05 20:03:43 +00:00
|
|
|
println!("ls dest {}", result.stdout_str());
|
2020-08-04 21:15:33 +00:00
|
|
|
|
|
|
|
let result = scene2
|
|
|
|
.cmd("ls")
|
|
|
|
.arg("-al")
|
|
|
|
.arg(&at.subdir.join(TEST_COPY_TO_FOLDER_NEW))
|
|
|
|
.run();
|
|
|
|
|
2021-04-05 20:03:43 +00:00
|
|
|
println!("ls dest {}", result.stdout_str());
|
2020-08-04 21:15:33 +00:00
|
|
|
assert!(at.file_exists(
|
|
|
|
&at.subdir
|
|
|
|
.join(TEST_COPY_TO_FOLDER_NEW)
|
|
|
|
.join("1.link")
|
|
|
|
.to_string_lossy()
|
|
|
|
));
|
|
|
|
assert!(at.file_exists(
|
|
|
|
&at.subdir
|
|
|
|
.join(TEST_COPY_TO_FOLDER_NEW)
|
|
|
|
.join("2.link")
|
|
|
|
.to_string_lossy()
|
|
|
|
));
|
|
|
|
assert!(at.file_exists(
|
|
|
|
&at.subdir
|
|
|
|
.join(TEST_COPY_TO_FOLDER_NEW)
|
|
|
|
.join("1")
|
|
|
|
.to_string_lossy()
|
|
|
|
));
|
|
|
|
assert!(at.file_exists(
|
|
|
|
&at.subdir
|
|
|
|
.join(TEST_COPY_TO_FOLDER_NEW)
|
|
|
|
.join("2")
|
|
|
|
.to_string_lossy()
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(at.is_symlink(
|
|
|
|
&at.subdir
|
|
|
|
.join(TEST_COPY_TO_FOLDER_NEW)
|
|
|
|
.join("1.link")
|
|
|
|
.to_string_lossy()
|
|
|
|
));
|
|
|
|
assert!(at.is_symlink(
|
|
|
|
&at.subdir
|
|
|
|
.join(TEST_COPY_TO_FOLDER_NEW)
|
|
|
|
.join("2.link")
|
|
|
|
.to_string_lossy()
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
fn test_cp_preserve_timestamps() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let ts = time::now().to_timespec();
|
|
|
|
let previous = FileTime::from_unix_time(ts.sec as i64 - 3600, ts.nsec as u32);
|
2021-05-30 05:10:54 +00:00
|
|
|
// set the file creation/modification an hour ago
|
2020-08-04 21:15:33 +00:00
|
|
|
filetime::set_file_times(
|
|
|
|
at.plus_as_string(TEST_HELLO_WORLD_SOURCE),
|
|
|
|
previous,
|
|
|
|
previous,
|
|
|
|
)
|
|
|
|
.unwrap();
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
2020-08-04 21:15:33 +00:00
|
|
|
.arg("--preserve=timestamps")
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2020-08-04 21:15:33 +00:00
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
|
|
|
|
|
|
|
let metadata = std_fs::metadata(at.subdir.join(TEST_HELLO_WORLD_SOURCE)).unwrap();
|
|
|
|
let creation = metadata.modified().unwrap();
|
|
|
|
|
|
|
|
let metadata2 = std_fs::metadata(at.subdir.join(TEST_HOW_ARE_YOU_SOURCE)).unwrap();
|
|
|
|
let creation2 = metadata2.modified().unwrap();
|
|
|
|
|
|
|
|
let scene2 = TestScenario::new("ls");
|
|
|
|
let result = scene2.cmd("ls").arg("-al").arg(at.subdir).run();
|
|
|
|
|
2021-04-05 20:03:43 +00:00
|
|
|
println!("ls dest {}", result.stdout_str());
|
2020-08-04 21:15:33 +00:00
|
|
|
assert_eq!(creation, creation2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[cfg(target_os = "linux")]
|
2021-05-30 05:10:54 +00:00
|
|
|
fn test_cp_no_preserve_timestamps() {
|
2020-08-04 21:15:33 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let ts = time::now().to_timespec();
|
|
|
|
let previous = FileTime::from_unix_time(ts.sec as i64 - 3600, ts.nsec as u32);
|
2021-05-30 05:10:54 +00:00
|
|
|
// set the file creation/modification an hour ago
|
2020-08-04 21:15:33 +00:00
|
|
|
filetime::set_file_times(
|
|
|
|
at.plus_as_string(TEST_HELLO_WORLD_SOURCE),
|
|
|
|
previous,
|
|
|
|
previous,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
sleep(Duration::from_secs(3));
|
|
|
|
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
2020-08-04 21:15:33 +00:00
|
|
|
.arg("--no-preserve=timestamps")
|
|
|
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2020-08-04 21:15:33 +00:00
|
|
|
|
|
|
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
|
|
|
|
|
|
|
let metadata = std_fs::metadata(at.subdir.join(TEST_HELLO_WORLD_SOURCE)).unwrap();
|
|
|
|
let creation = metadata.modified().unwrap();
|
|
|
|
|
|
|
|
let metadata2 = std_fs::metadata(at.subdir.join(TEST_HOW_ARE_YOU_SOURCE)).unwrap();
|
|
|
|
let creation2 = metadata2.modified().unwrap();
|
|
|
|
|
|
|
|
let scene2 = TestScenario::new("ls");
|
|
|
|
let result = scene2.cmd("ls").arg("-al").arg(at.subdir).run();
|
|
|
|
|
2021-04-05 20:03:43 +00:00
|
|
|
println!("ls dest {}", result.stdout_str());
|
2020-08-04 21:15:33 +00:00
|
|
|
println!("creation {:?} / {:?}", creation, creation2);
|
|
|
|
|
|
|
|
assert_ne!(creation, creation2);
|
|
|
|
let res = creation.elapsed().unwrap() - creation2.elapsed().unwrap();
|
|
|
|
// Some margins with time check
|
|
|
|
assert!(res.as_secs() > 3595);
|
|
|
|
assert!(res.as_secs() < 3605);
|
|
|
|
}
|
2021-01-01 17:36:30 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
fn test_cp_target_file_dev_null() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let file1 = "/dev/null";
|
|
|
|
let file2 = "test_cp_target_file_file_i2";
|
|
|
|
|
|
|
|
at.touch(file2);
|
|
|
|
ucmd.arg(file1).arg(file2).succeeds().no_stderr();
|
|
|
|
|
|
|
|
assert!(at.file_exists(file2));
|
|
|
|
}
|
2021-03-19 20:15:35 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
|
|
|
fn test_cp_one_file_system() {
|
|
|
|
use crate::common::util::AtPath;
|
|
|
|
use walkdir::WalkDir;
|
|
|
|
|
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
|
|
|
|
// Test must be run as root (or with `sudo -E`)
|
2021-04-22 20:37:44 +00:00
|
|
|
if scene.cmd("whoami").run().stdout_str() != "root\n" {
|
2021-03-19 20:15:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let at = scene.fixtures.clone();
|
|
|
|
let at_src = AtPath::new(&at.plus(TEST_MOUNT_COPY_FROM_FOLDER));
|
|
|
|
let at_dst = AtPath::new(&at.plus(TEST_COPY_TO_FOLDER_NEW));
|
|
|
|
|
|
|
|
// Prepare the mount
|
|
|
|
at_src.mkdir(TEST_MOUNT_MOUNTPOINT);
|
|
|
|
let mountpoint_path = &at_src.plus_as_string(TEST_MOUNT_MOUNTPOINT);
|
|
|
|
|
2021-04-17 13:48:23 +00:00
|
|
|
scene
|
2021-03-19 20:15:35 +00:00
|
|
|
.cmd("mount")
|
|
|
|
.arg("-t")
|
|
|
|
.arg("tmpfs")
|
|
|
|
.arg("-o")
|
|
|
|
.arg("size=640k") // ought to be enough
|
|
|
|
.arg("tmpfs")
|
|
|
|
.arg(mountpoint_path)
|
2021-04-17 13:48:23 +00:00
|
|
|
.succeeds();
|
2021-03-19 20:15:35 +00:00
|
|
|
|
|
|
|
at_src.touch(TEST_MOUNT_OTHER_FILESYSTEM_FILE);
|
|
|
|
|
|
|
|
// Begin testing -x flag
|
2021-04-22 20:37:44 +00:00
|
|
|
scene
|
2021-03-19 20:15:35 +00:00
|
|
|
.ucmd()
|
|
|
|
.arg("-rx")
|
|
|
|
.arg(TEST_MOUNT_COPY_FROM_FOLDER)
|
|
|
|
.arg(TEST_COPY_TO_FOLDER_NEW)
|
2021-04-22 20:37:44 +00:00
|
|
|
.succeeds();
|
2021-03-19 20:15:35 +00:00
|
|
|
|
|
|
|
// Ditch the mount before the asserts
|
2021-04-17 13:48:23 +00:00
|
|
|
scene.cmd("umount").arg(mountpoint_path).succeeds();
|
2021-03-19 20:15:35 +00:00
|
|
|
|
|
|
|
assert!(!at_dst.file_exists(TEST_MOUNT_OTHER_FILESYSTEM_FILE));
|
2021-05-30 05:10:54 +00:00
|
|
|
// Check if the other files were copied from the source folder hierarchy
|
2021-03-19 20:15:35 +00:00
|
|
|
for entry in WalkDir::new(at_src.as_string()) {
|
|
|
|
let entry = entry.unwrap();
|
|
|
|
let relative_src = entry
|
|
|
|
.path()
|
|
|
|
.strip_prefix(at_src.as_string())
|
|
|
|
.unwrap()
|
|
|
|
.to_str()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let ft = entry.file_type();
|
|
|
|
match (ft.is_dir(), ft.is_file(), ft.is_symlink()) {
|
|
|
|
(true, _, _) => assert!(at_dst.dir_exists(relative_src)),
|
|
|
|
(_, true, _) => assert!(at_dst.file_exists(relative_src)),
|
|
|
|
(_, _, _) => panic!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-18 12:17:55 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-04-24 17:20:31 +00:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
2021-04-18 12:17:55 +00:00
|
|
|
fn test_cp_reflink_always() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let result = ucmd
|
|
|
|
.arg("--reflink=always")
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_EXISTING_FILE)
|
|
|
|
.run();
|
|
|
|
|
2021-04-24 10:45:55 +00:00
|
|
|
if result.succeeded() {
|
2021-04-18 12:17:55 +00:00
|
|
|
// Check the content of the destination file
|
|
|
|
assert_eq!(at.read(TEST_EXISTING_FILE), "Hello, World!\n");
|
|
|
|
} else {
|
|
|
|
// Older Linux versions do not support cloning.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-04-24 17:20:31 +00:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
2021-04-18 12:17:55 +00:00
|
|
|
fn test_cp_reflink_auto() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-04-23 05:24:47 +00:00
|
|
|
ucmd.arg("--reflink=auto")
|
2021-04-18 12:17:55 +00:00
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_EXISTING_FILE)
|
2021-04-23 05:24:47 +00:00
|
|
|
.succeeds();
|
2021-04-18 12:17:55 +00:00
|
|
|
|
|
|
|
// Check the content of the destination file
|
|
|
|
assert_eq!(at.read(TEST_EXISTING_FILE), "Hello, World!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-04-24 17:20:31 +00:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
2021-04-18 12:17:55 +00:00
|
|
|
fn test_cp_reflink_never() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-04-23 05:24:47 +00:00
|
|
|
ucmd.arg("--reflink=never")
|
2021-04-18 12:17:55 +00:00
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_EXISTING_FILE)
|
2021-04-23 05:24:47 +00:00
|
|
|
.succeeds();
|
2021-04-18 12:17:55 +00:00
|
|
|
|
|
|
|
// Check the content of the destination file
|
|
|
|
assert_eq!(at.read(TEST_EXISTING_FILE), "Hello, World!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-04-24 17:20:31 +00:00
|
|
|
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
2021-04-18 12:17:55 +00:00
|
|
|
fn test_cp_reflink_bad() {
|
|
|
|
let (_, mut ucmd) = at_and_ucmd!();
|
2021-04-24 10:45:55 +00:00
|
|
|
let _result = ucmd
|
2021-04-18 12:17:55 +00:00
|
|
|
.arg("--reflink=bad")
|
|
|
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
|
|
|
.arg(TEST_EXISTING_FILE)
|
2021-04-23 05:24:47 +00:00
|
|
|
.fails()
|
|
|
|
.stderr_contains("invalid argument");
|
2021-04-18 12:17:55 +00:00
|
|
|
}
|
2021-06-01 21:06:38 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
fn test_cp_reflink_insufficient_permission() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
at.make_file("unreadable")
|
|
|
|
.set_permissions(PermissionsExt::from_mode(0o000))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
ucmd.arg("-r")
|
|
|
|
.arg("--reflink=auto")
|
|
|
|
.arg("unreadable")
|
|
|
|
.arg(TEST_EXISTING_FILE)
|
|
|
|
.fails()
|
|
|
|
.stderr_only("cp: 'unreadable' -> 'existing_file.txt': Permission denied (os error 13)");
|
|
|
|
}
|