mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-15 11:36:16 +00:00
Merge pull request #5699 from sylvestre/mv-cp-seen
cp/mv/ln: add support for the "will not overwrite just-created"
This commit is contained in:
commit
f10c6f1d56
6 changed files with 211 additions and 15 deletions
|
@ -3592,3 +3592,36 @@ fn test_cp_attributes_only() {
|
|||
assert_eq!(mode_a, at.metadata(a).mode());
|
||||
assert_eq!(mode_b, at.metadata(b).mode());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_seen_file() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
at.mkdir("a");
|
||||
at.mkdir("b");
|
||||
at.mkdir("c");
|
||||
at.write("a/f", "a");
|
||||
at.write("b/f", "b");
|
||||
|
||||
let result = ts.ucmd().arg("a/f").arg("b/f").arg("c").fails();
|
||||
#[cfg(not(unix))]
|
||||
assert!(result
|
||||
.stderr_str()
|
||||
.contains("will not overwrite just-created 'c\\f' with 'b/f'"));
|
||||
#[cfg(unix)]
|
||||
assert!(result
|
||||
.stderr_str()
|
||||
.contains("will not overwrite just-created 'c/f' with 'b/f'"));
|
||||
|
||||
assert!(at.plus("c").join("f").exists());
|
||||
|
||||
ts.ucmd()
|
||||
.arg("--backup=numbered")
|
||||
.arg("a/f")
|
||||
.arg("b/f")
|
||||
.arg("c")
|
||||
.succeeds();
|
||||
assert!(at.plus("c").join("f").exists());
|
||||
assert!(at.plus("c").join("f.~1~").exists());
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
use crate::common::util::TestScenario;
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[test]
|
||||
|
@ -719,3 +721,49 @@ fn test_symlink_remove_existing_same_src_and_dest() {
|
|||
assert!(at.file_exists("a") && !at.symlink_exists("a"));
|
||||
assert_eq!(at.read("a"), "sample");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_os = "android"))]
|
||||
fn test_ln_seen_file() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
at.mkdir("a");
|
||||
at.mkdir("b");
|
||||
at.mkdir("c");
|
||||
at.write("a/f", "a");
|
||||
at.write("b/f", "b");
|
||||
|
||||
let result = ts.ucmd().arg("a/f").arg("b/f").arg("c").fails();
|
||||
|
||||
#[cfg(not(unix))]
|
||||
assert!(result
|
||||
.stderr_str()
|
||||
.contains("will not overwrite just-created 'c\\f' with 'b/f'"));
|
||||
#[cfg(unix)]
|
||||
assert!(result
|
||||
.stderr_str()
|
||||
.contains("will not overwrite just-created 'c/f' with 'b/f'"));
|
||||
|
||||
assert!(at.plus("c").join("f").exists());
|
||||
// b/f still exists
|
||||
assert!(at.plus("b").join("f").exists());
|
||||
// a/f still exists
|
||||
assert!(at.plus("a").join("f").exists());
|
||||
#[cfg(unix)]
|
||||
{
|
||||
// Check inode numbers
|
||||
let inode_a_f = at.plus("a").join("f").metadata().unwrap().ino();
|
||||
let inode_b_f = at.plus("b").join("f").metadata().unwrap().ino();
|
||||
let inode_c_f = at.plus("c").join("f").metadata().unwrap().ino();
|
||||
|
||||
assert_eq!(
|
||||
inode_a_f, inode_c_f,
|
||||
"Inode numbers of a/f and c/f should be equal"
|
||||
);
|
||||
assert_ne!(
|
||||
inode_b_f, inode_c_f,
|
||||
"Inode numbers of b/f and c/f should not be equal"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1469,6 +1469,65 @@ fn test_mv_file_into_dir_where_both_are_files() {
|
|||
.stderr_contains("mv: failed to access 'b/': Not a directory");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mv_seen_file() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
at.mkdir("a");
|
||||
at.mkdir("b");
|
||||
at.mkdir("c");
|
||||
at.write("a/f", "a");
|
||||
at.write("b/f", "b");
|
||||
|
||||
let result = ts.ucmd().arg("a/f").arg("b/f").arg("c").fails();
|
||||
|
||||
#[cfg(not(unix))]
|
||||
assert!(result
|
||||
.stderr_str()
|
||||
.contains("will not overwrite just-created 'c\\f' with 'b/f'"));
|
||||
#[cfg(unix)]
|
||||
assert!(result
|
||||
.stderr_str()
|
||||
.contains("will not overwrite just-created 'c/f' with 'b/f'"));
|
||||
|
||||
// a/f has been moved into c/f
|
||||
assert!(at.plus("c").join("f").exists());
|
||||
// b/f still exists
|
||||
assert!(at.plus("b").join("f").exists());
|
||||
// a/f no longer exists
|
||||
assert!(!at.plus("a").join("f").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mv_seen_multiple_files_to_directory() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
at.mkdir("a");
|
||||
at.mkdir("b");
|
||||
at.mkdir("c");
|
||||
at.write("a/f", "a");
|
||||
at.write("b/f", "b");
|
||||
at.write("b/g", "g");
|
||||
|
||||
let result = ts.ucmd().arg("a/f").arg("b/f").arg("b/g").arg("c").fails();
|
||||
#[cfg(not(unix))]
|
||||
assert!(result
|
||||
.stderr_str()
|
||||
.contains("will not overwrite just-created 'c\\f' with 'b/f'"));
|
||||
#[cfg(unix)]
|
||||
assert!(result
|
||||
.stderr_str()
|
||||
.contains("will not overwrite just-created 'c/f' with 'b/f'"));
|
||||
|
||||
assert!(!at.plus("a").join("f").exists());
|
||||
assert!(at.plus("b").join("f").exists());
|
||||
assert!(!at.plus("b").join("g").exists());
|
||||
assert!(at.plus("c").join("f").exists());
|
||||
assert!(at.plus("c").join("g").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mv_dir_into_file_where_both_are_files() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue