mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Merge pull request #2088 from nthery/cp_reflink_never
cp: add support for --reflink=never
This commit is contained in:
commit
9517395839
2 changed files with 58 additions and 3 deletions
|
@ -210,7 +210,6 @@ pub struct Options {
|
||||||
overwrite: OverwriteMode,
|
overwrite: OverwriteMode,
|
||||||
parents: bool,
|
parents: bool,
|
||||||
strip_trailing_slashes: bool,
|
strip_trailing_slashes: bool,
|
||||||
reflink: bool,
|
|
||||||
reflink_mode: ReflinkMode,
|
reflink_mode: ReflinkMode,
|
||||||
preserve_attributes: Vec<Attribute>,
|
preserve_attributes: Vec<Attribute>,
|
||||||
recursive: bool,
|
recursive: bool,
|
||||||
|
@ -633,12 +632,12 @@ impl Options {
|
||||||
update: matches.is_present(OPT_UPDATE),
|
update: matches.is_present(OPT_UPDATE),
|
||||||
verbose: matches.is_present(OPT_VERBOSE),
|
verbose: matches.is_present(OPT_VERBOSE),
|
||||||
strip_trailing_slashes: matches.is_present(OPT_STRIP_TRAILING_SLASHES),
|
strip_trailing_slashes: matches.is_present(OPT_STRIP_TRAILING_SLASHES),
|
||||||
reflink: matches.is_present(OPT_REFLINK),
|
|
||||||
reflink_mode: {
|
reflink_mode: {
|
||||||
if let Some(reflink) = matches.value_of(OPT_REFLINK) {
|
if let Some(reflink) = matches.value_of(OPT_REFLINK) {
|
||||||
match reflink {
|
match reflink {
|
||||||
"always" => ReflinkMode::Always,
|
"always" => ReflinkMode::Always,
|
||||||
"auto" => ReflinkMode::Auto,
|
"auto" => ReflinkMode::Auto,
|
||||||
|
"never" => ReflinkMode::Never,
|
||||||
value => {
|
value => {
|
||||||
return Err(Error::InvalidArgument(format!(
|
return Err(Error::InvalidArgument(format!(
|
||||||
"invalid argument '{}' for \'reflink\'",
|
"invalid argument '{}' for \'reflink\'",
|
||||||
|
@ -1196,7 +1195,7 @@ fn copy_file(source: &Path, dest: &Path, options: &Options) -> CopyResult<()> {
|
||||||
///Copy the file from `source` to `dest` either using the normal `fs::copy` or the
|
///Copy the file from `source` to `dest` either using the normal `fs::copy` or the
|
||||||
///`FICLONE` ioctl if --reflink is specified and the filesystem supports it.
|
///`FICLONE` ioctl if --reflink is specified and the filesystem supports it.
|
||||||
fn copy_helper(source: &Path, dest: &Path, options: &Options) -> CopyResult<()> {
|
fn copy_helper(source: &Path, dest: &Path, options: &Options) -> CopyResult<()> {
|
||||||
if options.reflink {
|
if options.reflink_mode != ReflinkMode::Never {
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
return Err("--reflink is only supported on linux".to_string().into());
|
return Err("--reflink is only supported on linux".to_string().into());
|
||||||
|
|
||||||
|
|
|
@ -965,3 +965,59 @@ fn test_cp_one_file_system() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
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();
|
||||||
|
|
||||||
|
if result.success {
|
||||||
|
// 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]
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn test_cp_reflink_auto() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
ucmd.arg("--reflink=auto")
|
||||||
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
||||||
|
.arg(TEST_EXISTING_FILE)
|
||||||
|
.succeeds();
|
||||||
|
|
||||||
|
// Check the content of the destination file
|
||||||
|
assert_eq!(at.read(TEST_EXISTING_FILE), "Hello, World!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn test_cp_reflink_never() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
ucmd.arg("--reflink=never")
|
||||||
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
||||||
|
.arg(TEST_EXISTING_FILE)
|
||||||
|
.succeeds();
|
||||||
|
|
||||||
|
// Check the content of the destination file
|
||||||
|
assert_eq!(at.read(TEST_EXISTING_FILE), "Hello, World!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn test_cp_reflink_bad() {
|
||||||
|
let (_, mut ucmd) = at_and_ucmd!();
|
||||||
|
let result = ucmd
|
||||||
|
.arg("--reflink=bad")
|
||||||
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
||||||
|
.arg(TEST_EXISTING_FILE)
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("invalid argument");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue