diff --git a/crates/ecstore/src/set_disk/core/io_primitives.rs b/crates/ecstore/src/set_disk/core/io_primitives.rs index c0f485994..e065fae69 100644 --- a/crates/ecstore/src/set_disk/core/io_primitives.rs +++ b/crates/ecstore/src/set_disk/core/io_primitives.rs @@ -6737,9 +6737,7 @@ impl SetDisks { object, ); } - let if_none_match = http_preconditions.if_none_match_value().map(str::to_owned); - let if_match = http_preconditions.if_match_value().map(str::to_owned); - if should_prevent_write(&oi, if_none_match, if_match) + if should_prevent_write(&oi, http_preconditions.if_none_match_value(), http_preconditions.if_match_value()) && !crate::data_movement::can_replace_stale_data_movement_target(&oi, opts) { return Some(StorageError::PreconditionFailed); diff --git a/crates/ecstore/src/set_disk/mod.rs b/crates/ecstore/src/set_disk/mod.rs index ec85a6b7b..25ec26742 100644 --- a/crates/ecstore/src/set_disk/mod.rs +++ b/crates/ecstore/src/set_disk/mod.rs @@ -8075,12 +8075,9 @@ fn weak_etag_matches(etag: &str, condition: &str) -> bool { canonicalized_etag(strip_weak(etag)) == canonicalized_etag(strip_weak(condition)) } -pub fn should_prevent_write(oi: &ObjectInfo, if_none_match: Option, if_match: Option) -> bool { - let if_none_match = if_none_match - .as_deref() - .map(str::trim) - .filter(|condition| !condition.is_empty()); - let if_match = if_match.as_deref().map(str::trim).filter(|condition| !condition.is_empty()); +pub fn should_prevent_write(oi: &ObjectInfo, if_none_match: Option<&str>, if_match: Option<&str>) -> bool { + let if_none_match = if_none_match.map(str::trim).filter(|condition| !condition.is_empty()); + let if_match = if_match.map(str::trim).filter(|condition| !condition.is_empty()); match &oi.etag { Some(etag) => { @@ -14375,61 +14372,61 @@ mod tests { etag: Some("abc".to_string()), ..Default::default() }; - let if_none_match = Some("abc".to_string()); + let if_none_match = Some("abc"); let if_match = None; assert!(should_prevent_write(&oi, if_none_match, if_match)); - let if_none_match = Some("*".to_string()); + let if_none_match = Some("*"); let if_match = None; assert!(should_prevent_write(&oi, if_none_match, if_match)); let if_none_match = None; - let if_match = Some("def".to_string()); + let if_match = Some("def"); assert!(should_prevent_write(&oi, if_none_match, if_match)); let if_none_match = None; - let if_match = Some("*".to_string()); + let if_match = Some("*"); assert!(!should_prevent_write(&oi, if_none_match, if_match)); - let if_none_match = Some("def".to_string()); + let if_none_match = Some("def"); let if_match = None; assert!(!should_prevent_write(&oi, if_none_match, if_match)); - let if_none_match = Some("def".to_string()); - let if_match = Some("*".to_string()); + let if_none_match = Some("def"); + let if_match = Some("*"); assert!(!should_prevent_write(&oi, if_none_match, if_match)); - let if_none_match = Some("def".to_string()); - let if_match = Some("\"abc\"".to_string()); + let if_none_match = Some("def"); + let if_match = Some("\"abc\""); assert!(!should_prevent_write(&oi, if_none_match, if_match)); - let if_none_match = Some("*".to_string()); - let if_match = Some("\"abc\"".to_string()); + let if_none_match = Some("*"); + let if_match = Some("\"abc\""); assert!(should_prevent_write(&oi, if_none_match, if_match)); let oi = ObjectInfo { etag: None, ..Default::default() }; - let if_none_match = Some("*".to_string()); - let if_match = Some("\"abc\"".to_string()); + let if_none_match = Some("*"); + let if_match = Some("\"abc\""); assert!(should_prevent_write(&oi, if_none_match, if_match)); let if_none_match = None; let if_match = None; assert!(!should_prevent_write(&oi, if_none_match, if_match)); - let if_none_match = Some(String::new()); - let if_match = Some(" ".to_string()); + let if_none_match = Some(""); + let if_match = Some(" "); assert!(!should_prevent_write(&oi, if_none_match, if_match)); let oi = ObjectInfo { etag: Some("abc".to_string()), ..Default::default() }; - assert!(should_prevent_write(&oi, Some("W/\"abc\"".to_string()), None)); - assert!(!should_prevent_write(&oi, Some("W/\"def\"".to_string()), None)); - assert!(should_prevent_write(&oi, None, Some("W/\"abc\"".to_string()))); + assert!(should_prevent_write(&oi, Some("W/\"abc\""), None)); + assert!(!should_prevent_write(&oi, Some("W/\"def\""), None)); + assert!(should_prevent_write(&oi, None, Some("W/\"abc\""))); } #[test]