From eef5586f36d2cef71d48fd45019654c6d3f76843 Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 14:06:09 -0600 Subject: [PATCH] fix(id): avoid inheriting archive refs on copy --- pkgs/id/src/fileops.rs | 75 +++++++++++++++++++++++++++++++++++++++++- pkgs/id/src/tags.rs | 20 ++++++++++- 2 files changed, 93 insertions(+), 2 deletions(-) diff --git a/pkgs/id/src/fileops.rs b/pkgs/id/src/fileops.rs index 7aa2b0092d..eed2b3ce3c 100644 --- a/pkgs/id/src/fileops.rs +++ b/pkgs/id/src/fileops.rs @@ -462,7 +462,12 @@ impl<'a> FileOps<'a> { let ns = &self.tags.global; if let Err(e) = self .tags - .copy_all_tags(ns, from.as_bytes(), to.as_bytes()) + .copy_all_tags_except( + ns, + from.as_bytes(), + to.as_bytes(), + &[b"archive.rename", b"archive.replace"], + ) .await { tracing::warn!("failed to copy tags {from} -> {to}: {e:#}"); @@ -931,6 +936,74 @@ mod replacement_metadata_tests { node.shutdown().await.unwrap(); } + /// A copy must not become a second owner of the source's archives + /// (#4761): deleting the copy must leave the source's archives intact. + #[tokio::test] + async fn copy_does_not_inherit_source_archive_refs() { + let node = LocalNode::open(true).await.unwrap(); + put(&node, "source.txt", b"source content").await; + put(&node, "other.txt", b"other content").await; + // Renaming onto source.txt with archiving enabled adds both + // archive.rename and archive.replace refs to the live source. + let rename_outcome = node + .ops() + .rename("other.txt", "source.txt", true) + .await + .unwrap(); + let source_archives = [ + rename_outcome + .archived_original + .expect("original source archived"), + rename_outcome + .archived_replaced + .expect("replaced source archived"), + ]; + let source_before = tags_of(&node, "source.txt").await; + assert!( + has_tag(&source_before, "archive.rename", &source_archives[0]), + "{source_before:?}" + ); + assert!( + has_tag(&source_before, "archive.replace", &source_archives[1]), + "{source_before:?}" + ); + + node.ops().copy("source.txt", "copy.txt").await.unwrap(); + let copy_tags = tags_of(&node, "copy.txt").await; + assert!( + values(©_tags, "archive.rename").is_empty(), + "copy inherited archive.rename refs: {copy_tags:?}" + ); + assert!( + values(©_tags, "archive.replace").is_empty(), + "copy inherited archive.replace refs: {copy_tags:?}" + ); + + // Deleting the copy must not touch the source's archive. + let delete_outcome = node.ops().delete("copy.txt").await.unwrap(); + assert_eq!( + delete_outcome.archives_removed, 0, + "copy delete removed archives" + ); + for archive in &source_archives { + assert!( + !tags_of(&node, archive).await.is_empty(), + "source archive {archive} removed by copy delete" + ); + } + let source_after = tags_of(&node, "source.txt").await; + assert!( + has_tag(&source_after, "archive.rename", &source_archives[0]), + "source lost its archive.rename ref: {source_after:?}" + ); + assert!( + has_tag(&source_after, "archive.replace", &source_archives[1]), + "source lost its archive ref: {source_after:?}" + ); + + node.shutdown().await.unwrap(); + } + #[tokio::test] async fn rename_onto_existing_preserves_replaced_tag_payloads() { let node = LocalNode::open(true).await.unwrap(); diff --git a/pkgs/id/src/tags.rs b/pkgs/id/src/tags.rs index 789d4e3cb9..aa44a8383c 100644 --- a/pkgs/id/src/tags.rs +++ b/pkgs/id/src/tags.rs @@ -1077,9 +1077,26 @@ impl TagStore { /// /// Returns the number of tags copied. pub async fn copy_all_tags(&self, ns: &NamespacePair, from: &[u8], to: &[u8]) -> Result { + self.copy_all_tags_except(ns, from, to, &[]).await + } + + /// Copy tags to another subject, omitting tags whose keys are excluded. + /// + /// Excluded tags remain on the original subject. Returns the number of + /// tags copied. + pub async fn copy_all_tags_except( + &self, + ns: &NamespacePair, + from: &[u8], + to: &[u8], + excluded_keys: &[&[u8]], + ) -> Result { let tags = self.get_tags(ns, from).await?; - let count = tags.len(); + let mut count = 0; for tag in &tags { + if excluded_keys.iter().any(|key| *key == tag.key.as_bytes()) { + continue; + } self.set_tag_hash( ns, to, @@ -1089,6 +1106,7 @@ impl TagStore { tag.len, ) .await?; + count += 1; } Ok(count) }