Merge pull request #3954 from dmatos2012/modify-cp-archive-flag-behavior

cp: modify archive flag to copy dir contents rather than dir
This commit is contained in:
Terts Diepraam 2023-02-26 13:24:45 +01:00 committed by GitHub
commit c148215e7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -93,7 +93,7 @@ impl<'a> Context<'a> {
fn new(root: &'a Path, target: &'a Path) -> std::io::Result<Self> {
let current_dir = env::current_dir()?;
let root_path = current_dir.join(root);
let root_parent = if target.exists() {
let root_parent = if target.exists() && !root.to_str().unwrap().ends_with("/.") {
root_path.parent().map(|p| p.to_path_buf())
} else {
Some(root_path)

View file

@ -2535,3 +2535,14 @@ fn test_src_base_dot() {
.no_stdout();
assert!(!at.dir_exists("y/x"));
}
#[test]
#[cfg(not(windows))]
fn test_cp_archive_on_directory_ending_dot() {
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("dir1");
at.mkdir("dir2");
at.touch("dir1/file");
ucmd.args(&["-a", "dir1/.", "dir2"]).succeeds();
assert!(at.file_exists("dir2/file"));
}