Skip to content

Commit

Permalink
Test and fix basic link --preserve capability
Browse files Browse the repository at this point in the history
  • Loading branch information
wykurz committed Nov 27, 2023
1 parent 1ff3f11 commit 55a5ca5
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions common/src/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,9 @@ pub async fn link(
tokio::fs::symlink(update_symlink, dst)
.await
.with_context(|| format!("failed creating symlink {:?}", &dst))?;
if settings.preserve {
set_owner_and_time(dst, update_metadata).await?;
}
return Ok(());
}
} else {
Expand All @@ -587,6 +590,9 @@ pub async fn link(
tokio::fs::symlink(src_symlink, dst)
.await
.with_context(|| format!("failed creating symlink {:?}", &dst))?;
if settings.preserve {
set_owner_and_time(dst, &src_metadata).await?;
}
return Ok(());
}
}
Expand Down Expand Up @@ -763,10 +769,14 @@ mod link_tests {
// |- 2.txt -> ../0.txt
let foo_path = tmp_dir.join("update");
tokio::fs::create_dir(&foo_path).await.unwrap();
tokio::fs::write(foo_path.join("0.txt"), "0").await.unwrap();
tokio::fs::write(foo_path.join("0.txt"), "0-new")
.await
.unwrap();
let bar_path = foo_path.join("bar");
tokio::fs::create_dir(&bar_path).await.unwrap();
tokio::fs::write(bar_path.join("1.txt"), "1").await.unwrap();
tokio::fs::write(bar_path.join("1.txt"), "1-new")
.await
.unwrap();
tokio::fs::symlink("../1.txt", bar_path.join("2.txt"))
.await
.unwrap();
Expand All @@ -775,7 +785,7 @@ mod link_tests {
}

#[test(tokio::test)]
async fn check_link_update1() -> Result<()> {
async fn check_link_update() -> Result<()> {
let tmp_dir = testutils::setup_test_dir().await?;
setup_update_dir(&tmp_dir).await?;
let test_path = tmp_dir.as_path();
Expand All @@ -799,4 +809,33 @@ mod link_tests {
.await?;
Ok(())
}

#[test(tokio::test)]
async fn check_link_update_preserve() -> Result<()> {
let tmp_dir = testutils::setup_test_dir().await?;
tokio::time::sleep(std::time::Duration::from_millis(1000)).await;
setup_update_dir(&tmp_dir).await?;
let test_path = tmp_dir.as_path();
let mut settings = COMMON_SETTINGS.clone();
settings.preserve = true;
link(
&PROGRESS,
&test_path.join("foo"),
&test_path.join("bar"),
&Some(test_path.join("update")),
&settings,
)
.await?;
// compare subset of src and dst
testutils::check_dirs_identical(
&test_path.join("foo").join("baz"),
&test_path.join("bar").join("baz"),
true,
)
.await?;
// compare update and dst
testutils::check_dirs_identical(&test_path.join("update"), &test_path.join("bar"), true)
.await?;
Ok(())
}
}

0 comments on commit 55a5ca5

Please sign in to comment.