From 022fed41a43ecc8a51f721c86039ac958c237927 Mon Sep 17 00:00:00 2001 From: "shiro.lee" Date: Thu, 15 Aug 2024 09:14:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecstore/src/erasure.rs | 4 +- ecstore/src/peer.rs | 6 +- ecstore/src/utils/mod.rs | 1 - ecstore/src/utils/string.rs | 133 ------------------------------------ rustfs/src/storage/ecfs.rs | 10 +-- 5 files changed, 10 insertions(+), 144 deletions(-) delete mode 100644 ecstore/src/utils/string.rs diff --git a/ecstore/src/erasure.rs b/ecstore/src/erasure.rs index b50b41c0..6c23842a 100644 --- a/ecstore/src/erasure.rs +++ b/ecstore/src/erasure.rs @@ -36,9 +36,9 @@ impl Erasure { Erasure { data_shards, - parity_shards: parity_shards, + parity_shards, block_size, - encoder: encoder, + encoder, _id: Uuid::new_v4(), } } diff --git a/ecstore/src/peer.rs b/ecstore/src/peer.rs index 5013bab0..ed92f68a 100644 --- a/ecstore/src/peer.rs +++ b/ecstore/src/peer.rs @@ -454,12 +454,12 @@ fn is_reserved_bucket(bucket_name: &str) -> bool { // 检查桶名是否为保留名或无效名 fn is_reserved_or_invalid_bucket(bucket_entry: &str, strict: bool) -> bool { - if bucket_entry == "" { + if bucket_entry.is_empty() { return true; } let bucket_entry = bucket_entry.trim_end_matches('/'); - let result = check_bucket_name(&bucket_entry, strict).is_err(); + let result = check_bucket_name(bucket_entry, strict).is_err(); - result || is_meta_bucket(&bucket_entry) || is_reserved_bucket(&bucket_entry) + result || is_meta_bucket(bucket_entry) || is_reserved_bucket(bucket_entry) } diff --git a/ecstore/src/utils/mod.rs b/ecstore/src/utils/mod.rs index d0a295df..2b78d9e7 100644 --- a/ecstore/src/utils/mod.rs +++ b/ecstore/src/utils/mod.rs @@ -3,4 +3,3 @@ pub mod ellipses; pub mod hash; pub mod net; pub mod path; -pub mod string; diff --git a/ecstore/src/utils/string.rs b/ecstore/src/utils/string.rs deleted file mode 100644 index 137f7f1f..00000000 --- a/ecstore/src/utils/string.rs +++ /dev/null @@ -1,133 +0,0 @@ -// use std::collections::HashMap; -// use std::fmt; - -// #[derive(Debug, Clone)] -// pub struct StringSet(HashMap); - -// impl StringSet { -// // ToSlice - returns StringSet as a vector of strings. -// pub fn to_slice(&self) -> Vec { -// let mut keys = self.0.keys().cloned().collect::>(); -// keys.sort(); -// keys -// } - -// // IsEmpty - returns whether the set is empty or not. -// pub fn is_empty(&self) -> bool { -// self.0.len() == 0 -// } - -// // Add - adds a string to the set. -// pub fn add(&mut self, s: String) { -// self.0.insert(s, ()); -// } - -// // Remove - removes a string from the set. It does nothing if the string does not exist in the set. -// pub fn remove(&mut self, s: &str) { -// self.0.remove(s); -// } - -// // Contains - checks if a string is in the set. -// pub fn contains(&self, s: &str) -> bool { -// self.0.contains_key(s) -// } - -// // FuncMatch - returns a new set containing each value that passes the match function. -// pub fn func_match(&self, match_fn: F, match_string: &str) -> StringSet -// where -// F: Fn(&str, &str) -> bool, -// { -// StringSet( -// self.0 -// .iter() -// .filter(|(k, _)| match_fn(k, match_string)) -// .map(|(k, _)| (k.clone(), ())) -// .collect::>(), -// ) -// } - -// // ApplyFunc - returns a new set containing each value processed by 'apply_fn'. -// pub fn apply_func(&self, apply_fn: F) -> StringSet -// where -// F: Fn(&str) -> String, -// { -// StringSet( -// self.0 -// .iter() -// .map(|(k, _)| (apply_fn(k), ())) -// .collect::>(), -// ) -// } - -// // Equals - checks whether the given set is equal to the current set or not. -// pub fn equals(&self, other: &StringSet) -> bool { -// if self.0.len() != other.0.len() { -// return false; -// } -// self.0.iter().all(|(k, _)| other.0.contains_key(k)) -// } - -// // Intersection - returns the intersection with the given set as a new set. -// pub fn intersection(&self, other: &StringSet) -> StringSet { -// StringSet( -// self.0 -// .iter() -// .filter(|(k, _)| other.0.contains_key::(k)) -// .map(|(k, _)| (k.clone(), ())) -// .collect::>(), -// ) -// } - -// // Difference - returns the difference with the given set as a new set. -// pub fn difference(&self, other: &StringSet) -> StringSet { -// StringSet( -// self.0 -// .iter() -// .filter(|(k, _)| !other.0.contains_key::(k)) -// .map(|(k, _)| (k.clone(), ())) -// .collect::>(), -// ) -// } - -// // Union - returns the union with the given set as a new set. -// pub fn union(&self, other: &StringSet) -> StringSet { -// let mut new_set = self.clone(); -// for (k, _) in other.0.iter() { -// new_set.0.insert(k.clone(), ()); -// } -// new_set -// } -// } - -// // Implementing JSON serialization and deserialization would require the serde crate. -// // You would also need to implement Display and PartialEq traits for more idiomatic Rust. - -// // Implementing Display trait to provide a string representation of the set. -// impl fmt::Display for StringSet { -// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { -// write!(f, "{}", self.to_slice().join(", ")) -// } -// } - -// // Implementing PartialEq and Eq traits to allow comparison of StringSet instances. -// impl PartialEq for StringSet { -// fn eq(&self, other: &StringSet) -> bool { -// self.equals(other) -// } -// } - -// impl Eq for StringSet {} - -// // NewStringSet - creates a new string set. -// pub fn new_string_set() -> StringSet { -// StringSet(HashMap::new()) -// } - -// // CreateStringSet - creates a new string set with given string values. -// pub fn create_string_set(sl: Vec) -> StringSet { -// let mut set = new_string_set(); -// for k in sl { -// set.add(k); -// } -// set -// } diff --git a/rustfs/src/storage/ecfs.rs b/rustfs/src/storage/ecfs.rs index 1c291242..07be9c44 100644 --- a/rustfs/src/storage/ecfs.rs +++ b/rustfs/src/storage/ecfs.rs @@ -155,12 +155,12 @@ impl S3 for FS { let info = reader.object_info; let content_type = try_!(ContentType::from_str("application/x-msdownload")); - let last_modified = info.mod_time.map(|v| Timestamp::from(v)); + let last_modified = info.mod_time.map(Timestamp::from); let output = GetObjectOutput { body: Some(reader.stream), content_length: Some(info.size as i64), - last_modified: last_modified, + last_modified, content_type: Some(content_type), ..Default::default() }; @@ -194,12 +194,12 @@ impl S3 for FS { debug!("info {:?}", info); let content_type = try_!(ContentType::from_str("application/x-msdownload")); - let last_modified = info.mod_time.map(|v| Timestamp::from(v)); + let last_modified = info.mod_time.map(Timestamp::from); let output = HeadObjectOutput { content_length: Some(try_!(i64::try_from(info.size))), content_type: Some(content_type), - last_modified: last_modified, + last_modified, // metadata: object_metadata, ..Default::default() }; @@ -215,7 +215,7 @@ impl S3 for FS { let buckets: Vec = bucket_infos .iter() .map(|v| Bucket { - creation_date: v.created.map(|v| Timestamp::from(v)), + creation_date: v.created.map(Timestamp::from), name: Some(v.name.clone()), }) .collect();