From 921a48bd14b53dcaaf0c804fd011b9c577bffe06 Mon Sep 17 00:00:00 2001 From: Zhengchao An Date: Fri, 28 Aug 2026 06:56:13 +0800 Subject: [PATCH] refactor(lifecycle): reuse the replication tag parser (#6761) `crates/lifecycle/src/tagging.rs` carried a byte-identical copy of the `form_urlencoded` tag decoder already owned by `rustfs-replication`, plus a duplicate of its test. Since `crates/lifecycle` already depends on `rustfs-replication`, replace the copy with a `pub(crate) use` re-export: no new crate edge, one parser, and no second implementation to drift from the replication contract. The `rule.rs` call site is unchanged. Also drop `crates/ecstore/src/bucket/lifecycle/tagging_boundary.rs`, a migration-era boundary shim with zero call sites in the tree. --- crates/ecstore/src/bucket/lifecycle/mod.rs | 1 - .../src/bucket/lifecycle/tagging_boundary.rs | 37 ------------------- crates/lifecycle/src/tagging.rs | 36 +++--------------- 3 files changed, 6 insertions(+), 68 deletions(-) delete mode 100644 crates/ecstore/src/bucket/lifecycle/tagging_boundary.rs diff --git a/crates/ecstore/src/bucket/lifecycle/mod.rs b/crates/ecstore/src/bucket/lifecycle/mod.rs index 5006dce1b..d87e5436f 100644 --- a/crates/ecstore/src/bucket/lifecycle/mod.rs +++ b/crates/ecstore/src/bucket/lifecycle/mod.rs @@ -27,7 +27,6 @@ pub use self::core as lifecycle; mod replication_sink; pub mod rule; mod runtime_boundary; -mod tagging_boundary; pub mod tier_delete_journal; pub mod tier_free_version_recovery; pub mod tier_last_day_stats; diff --git a/crates/ecstore/src/bucket/lifecycle/tagging_boundary.rs b/crates/ecstore/src/bucket/lifecycle/tagging_boundary.rs deleted file mode 100644 index ff200c98a..000000000 --- a/crates/ecstore/src/bucket/lifecycle/tagging_boundary.rs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2024 RustFS Team -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use std::collections::HashMap; - -#[allow( - dead_code, - reason = "declared boundary surface for the ECStore replication split plan; no caller in this port (backlog#1823)" -)] -pub(crate) fn decode_tags_to_map(tags: &str) -> HashMap { - crate::bucket::tagging::decode_tags_to_map(tags) -} - -#[cfg(test)] -mod tests { - use super::decode_tags_to_map; - - #[test] - fn decode_tags_to_map_preserves_bucket_tagging_parser_behavior() { - let tags = decode_tags_to_map("env=prod&encoded=a%2Fb&=ignored"); - - assert_eq!(tags.get("env").map(String::as_str), Some("prod")); - assert_eq!(tags.get("encoded").map(String::as_str), Some("a/b")); - assert!(!tags.contains_key("")); - } -} diff --git a/crates/lifecycle/src/tagging.rs b/crates/lifecycle/src/tagging.rs index 155965900..18b71072c 100644 --- a/crates/lifecycle/src/tagging.rs +++ b/crates/lifecycle/src/tagging.rs @@ -12,34 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::collections::HashMap; +//! Lifecycle tag decoding reuses the parser owned by `rustfs-replication`. +//! +//! `crates/lifecycle` already depends on `rustfs-replication`, so this is a +//! plain re-export: no new crate edge, and no second copy of the parser to +//! drift from the replication contract. -use url::form_urlencoded; - -pub(crate) fn decode_tags_to_map(tags: &str) -> HashMap { - let mut list = HashMap::new(); - - for (k, v) in form_urlencoded::parse(tags.as_bytes()) { - if k.is_empty() { - continue; - } - - list.insert(k.to_string(), v.to_string()); - } - - list -} - -#[cfg(test)] -mod tests { - use super::decode_tags_to_map; - - #[test] - fn decode_tags_to_map_preserves_bucket_tagging_parser_behavior() { - let tags = decode_tags_to_map("env=prod&encoded=a%2Fb&=ignored"); - - assert_eq!(tags.get("env").map(String::as_str), Some("prod")); - assert_eq!(tags.get("encoded").map(String::as_str), Some("a/b")); - assert!(!tags.contains_key("")); - } -} +pub(crate) use rustfs_replication::tagging::decode_tags_to_map;