mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
fixup! cp: make copy_on_write_linux() func more readable
This commit is contained in:
parent
e0dcc43076
commit
1f907bfd4b
1 changed files with 8 additions and 6 deletions
|
@ -9,7 +9,7 @@
|
||||||
// For the full copyright and license information, please view the LICENSE file
|
// For the full copyright and license information, please view the LICENSE file
|
||||||
// that was distributed with this source code.
|
// that was distributed with this source code.
|
||||||
|
|
||||||
// spell-checker:ignore (ToDO) ficlone ftruncate linkgs lstat nlink nlinks pathbuf pwrite reflink strs xattrs symlinked
|
// spell-checker:ignore (ToDO) ficlone ftruncate linkgs lstat nlink nlinks pathbuf pwrite reflink strs xattrs symlinked fiemap
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate quick_error;
|
extern crate quick_error;
|
||||||
|
@ -22,7 +22,9 @@ use std::env;
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::fs::{self, File, OpenOptions};
|
use std::fs::{self, File, OpenOptions};
|
||||||
use std::io::{self, stderr, stdin, Read, Write};
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
|
use std::io::Read;
|
||||||
|
use std::io::{self, stderr, stdin, Write};
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
@ -1681,7 +1683,7 @@ fn copy_no_cow_fallback(
|
||||||
/// If `fallback` is true and there is a failure performing the clone,
|
/// If `fallback` is true and there is a failure performing the clone,
|
||||||
/// then this function performs a standard [`std::fs::copy`]. Otherwise,
|
/// then this function performs a standard [`std::fs::copy`]. Otherwise,
|
||||||
/// this function returns an error.
|
/// this function returns an error.
|
||||||
#[cfg(unix)]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
fn clone<P>(source: P, dest: P, fallback: bool) -> std::io::Result<()>
|
fn clone<P>(source: P, dest: P, fallback: bool) -> std::io::Result<()>
|
||||||
where
|
where
|
||||||
P: AsRef<Path>,
|
P: AsRef<Path>,
|
||||||
|
@ -1703,7 +1705,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Perform a sparse copy from one file to another.
|
/// Perform a sparse copy from one file to another.
|
||||||
#[cfg(unix)]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
fn sparse_copy<P>(source: P, dest: P) -> std::io::Result<()>
|
fn sparse_copy<P>(source: P, dest: P) -> std::io::Result<()>
|
||||||
where
|
where
|
||||||
P: AsRef<Path>,
|
P: AsRef<Path>,
|
||||||
|
@ -1756,10 +1758,10 @@ fn copy_on_write_linux(
|
||||||
(ReflinkMode::Never, _) => std::fs::copy(source, dest).map(|_| ()),
|
(ReflinkMode::Never, _) => std::fs::copy(source, dest).map(|_| ()),
|
||||||
(ReflinkMode::Auto, SparseMode::Always) => sparse_copy(source, dest),
|
(ReflinkMode::Auto, SparseMode::Always) => sparse_copy(source, dest),
|
||||||
(ReflinkMode::Auto, _) => clone(source, dest, true),
|
(ReflinkMode::Auto, _) => clone(source, dest, true),
|
||||||
(ReflinkMode::Always, SparseMode::Auto) => {
|
(ReflinkMode::Always, SparseMode::Auto) => clone(source, dest, false),
|
||||||
|
(ReflinkMode::Always, _) => {
|
||||||
return Err("`--reflink=always` can be used only with --sparse=auto".into())
|
return Err("`--reflink=always` can be used only with --sparse=auto".into())
|
||||||
}
|
}
|
||||||
(ReflinkMode::Always, _) => clone(source, dest, false),
|
|
||||||
};
|
};
|
||||||
result.context(context)?;
|
result.context(context)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue