mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
mv: add the check with --b=simple and when the source is a backup
This commit is contained in:
parent
24aff229da
commit
40c598852b
2 changed files with 28 additions and 1 deletions
|
@ -22,7 +22,7 @@ use std::os::unix;
|
|||
#[cfg(windows)]
|
||||
use std::os::windows;
|
||||
use std::path::{Path, PathBuf};
|
||||
use uucore::backup_control::{self, BackupMode};
|
||||
use uucore::backup_control::{self, source_is_target_backup, BackupMode};
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{set_exit_code, FromIo, UError, UResult, USimpleError, UUsageError};
|
||||
use uucore::fs::{are_hardlinks_or_one_way_symlink_to_same_file, are_hardlinks_to_same_file};
|
||||
|
@ -251,6 +251,17 @@ fn parse_paths(files: &[OsString], b: &Behavior) -> Vec<PathBuf> {
|
|||
}
|
||||
|
||||
fn handle_two_paths(source: &Path, target: &Path, b: &Behavior) -> UResult<()> {
|
||||
if b.backup == BackupMode::SimpleBackup && source_is_target_backup(source, target, &b.suffix) {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::NotFound,
|
||||
format!(
|
||||
"backing up {} might destroy source; {} not moved",
|
||||
target.quote(),
|
||||
source.quote()
|
||||
),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
if source.symlink_metadata().is_err() {
|
||||
return Err(MvError::NoSuchFile(source.quote().to_string()).into());
|
||||
}
|
||||
|
|
|
@ -510,6 +510,22 @@ fn test_mv_same_hardlink_backup_simple() {
|
|||
.succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "android")))]
|
||||
fn test_mv_same_hardlink_backup_simple_destroy() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let file_a = "test_mv_same_file_a~";
|
||||
let file_b = "test_mv_same_file_a";
|
||||
at.touch(file_a);
|
||||
at.touch(file_b);
|
||||
|
||||
ucmd.arg(file_a)
|
||||
.arg(file_b)
|
||||
.arg("--b=simple")
|
||||
.fails()
|
||||
.stderr_contains("backing up 'test_mv_same_file_a' might destroy source");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mv_same_file_not_dot_dir() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue