cargo fmt

This commit is contained in:
houseme
2025-06-27 18:53:51 +08:00
parent 8a4cb0319a
commit 7bd8431006
12 changed files with 29 additions and 55 deletions

View File

@@ -929,13 +929,17 @@ impl FileMetaVersion {
}
pub fn get_data_dir(&self) -> Option<Uuid> {
if self.valid() { {
if self.valid() {
{
if self.version_type == VersionType::Object {
self.object.as_ref().map(|v| v.data_dir).unwrap_or_default()
} else {
None
}
} } else { Default::default() }
}
} else {
Default::default()
}
}
pub fn get_version_id(&self) -> Option<Uuid> {

View File

@@ -241,8 +241,7 @@ impl MQTTTarget {
records: vec![event.clone()],
};
let data =
serde_json::to_vec(&log).map_err(|e| TargetError::Serialization(format!("Failed to serialize event: {e}")))?;
let data = serde_json::to_vec(&log).map_err(|e| TargetError::Serialization(format!("Failed to serialize event: {e}")))?;
// Vec<u8> Convert to String, only for printing logs
let data_string = String::from_utf8(data.clone())

View File

@@ -206,8 +206,7 @@ impl WebhookTarget {
records: vec![event.clone()],
};
let data =
serde_json::to_vec(&log).map_err(|e| TargetError::Serialization(format!("Failed to serialize event: {e}")))?;
let data = serde_json::to_vec(&log).map_err(|e| TargetError::Serialization(format!("Failed to serialize event: {e}")))?;
// Vec<u8> Convert to String
let data_string = String::from_utf8(data.clone())

View File

@@ -333,9 +333,7 @@ pub(crate) fn init_telemetry(config: &OtelConfig) -> OtelGuard {
// Configure the flexi_logger
let flexi_logger_result = flexi_logger::Logger::try_with_env_or_str(logger_level)
.unwrap_or_else(|e| {
eprintln!(
"Invalid logger level: {logger_level}, using default: {DEFAULT_LOG_LEVEL}, failed error: {e:?}"
);
eprintln!("Invalid logger level: {logger_level}, using default: {DEFAULT_LOG_LEVEL}, failed error: {e:?}");
flexi_logger::Logger::with(log_spec.clone())
})
.log_to_file(

View File

@@ -484,9 +484,7 @@ mod tests {
}
// 验证 etag注意压缩会改变数据所以这里的 etag 验证可能需要调整)
println!(
"Test completed successfully with compression: {is_compress}, encryption: {is_encrypt}"
);
println!("Test completed successfully with compression: {is_compress}, encryption: {is_encrypt}");
}
#[tokio::test]

View File

@@ -22,9 +22,7 @@ pub fn load_certs(filename: &str) -> io::Result<Vec<CertificateDer<'static>>> {
.collect::<Result<Vec<_>, _>>()
.map_err(|e| certs_error(format!("certificate file {filename} format error:{e:?}")))?;
if certs.is_empty() {
return Err(certs_error(format!(
"No valid certificate was found in the certificate file {filename}"
)));
return Err(certs_error(format!("No valid certificate was found in the certificate file {filename}")));
}
Ok(certs)
}

View File

@@ -47,9 +47,7 @@ fn parse_bitrot_config(s: &str) -> Result<Duration> {
match s.trim_end_matches('m').parse::<u64>() {
Ok(months) => {
if months < RUSTFS_BITROT_CYCLE_IN_MONTHS {
return Err(Error::other(format!(
"minimum bitrot cycle is {RUSTFS_BITROT_CYCLE_IN_MONTHS} month(s)"
)));
return Err(Error::other(format!("minimum bitrot cycle is {RUSTFS_BITROT_CYCLE_IN_MONTHS} month(s)")));
}
Ok(Duration::from_secs(months * 30 * 24 * 60))

View File

@@ -672,14 +672,8 @@ impl LocalDisk {
let volume_dir = self.get_bucket_path(volume)?;
self.write_all_private(
volume,
format!("{path}/{STORAGE_FORMAT_FILE}").as_str(),
buf.into(),
true,
&volume_dir,
)
.await?;
self.write_all_private(volume, format!("{path}/{STORAGE_FORMAT_FILE}").as_str(), buf.into(), true, &volume_dir)
.await?;
Ok(())
}
@@ -1399,8 +1393,7 @@ impl DiskAPI for LocalDisk {
rename_all(&src_file_path, &dst_file_path, &dst_volume_dir).await?;
self.write_all(dst_volume, format!("{dst_path}.meta").as_str(), meta)
.await?;
self.write_all(dst_volume, format!("{dst_path}.meta").as_str(), meta).await?;
if let Some(parent) = src_file_path.parent() {
self.delete_file(&src_volume_dir, &parent.to_path_buf(), false, false).await?;
@@ -2077,9 +2070,8 @@ impl DiskAPI for LocalDisk {
// opts.undo_write && opts.old_data_dir.is_some_and(f)
if let Some(old_data_dir) = opts.old_data_dir {
if opts.undo_write {
let src_path = file_path.join(Path::new(
format!("{old_data_dir}{SLASH_SEPARATOR}{STORAGE_FORMAT_FILE_BACKUP}").as_str(),
));
let src_path =
file_path.join(Path::new(format!("{old_data_dir}{SLASH_SEPARATOR}{STORAGE_FORMAT_FILE_BACKUP}").as_str()));
let dst_path = file_path.join(Path::new(format!("{path}{SLASH_SEPARATOR}{STORAGE_FORMAT_FILE}").as_str()));
return rename_all(src_path, dst_path, file_path).await;
}

View File

@@ -455,10 +455,7 @@ impl ObjectInfo {
}
if self.is_compressed() {
if let Some(size_str) = self
.user_defined
.get(&format!("{RESERVED_METADATA_PREFIX_LOWER}actual-size"))
{
if let Some(size_str) = self.user_defined.get(&format!("{RESERVED_METADATA_PREFIX_LOWER}actual-size")) {
if !size_str.is_empty() {
// Todo: deal with error
let size = size_str.parse::<i64>().map_err(|e| std::io::Error::other(e.to_string()))?;

View File

@@ -67,10 +67,7 @@ fn get_mapped_policy_path(name: &str, user_type: UserType, is_group: bool) -> St
return path_join_buf(&[&IAM_CONFIG_POLICY_DB_GROUPS_PREFIX, format!("{name}.json").as_str()]);
}
match user_type {
UserType::Svc => path_join_buf(&[
&IAM_CONFIG_POLICY_DB_SERVICE_ACCOUNTS_PREFIX,
format!("{name}.json").as_str(),
]),
UserType::Svc => path_join_buf(&[&IAM_CONFIG_POLICY_DB_SERVICE_ACCOUNTS_PREFIX, format!("{name}.json").as_str()]),
UserType::Sts => path_join_buf(&[&IAM_CONFIG_POLICY_DB_STS_USERS_PREFIX, format!("{name}.json").as_str()]),
_ => path_join_buf(&[&IAM_CONFIG_POLICY_DB_USERS_PREFIX, format!("{name}.json").as_str()]),
}

View File

@@ -12,10 +12,10 @@ mod service;
mod storage;
use crate::auth::IAMAuth;
use crate::console::{init_console_cfg, CONSOLE_CONFIG};
use crate::console::{CONSOLE_CONFIG, init_console_cfg};
// Ensure the correct path for parse_license is imported
use crate::event::shutdown_event_notifier;
use crate::server::{wait_for_shutdown, ServiceState, ServiceStateManager, ShutdownSignal, SHUTDOWN_TIMEOUT};
use crate::server::{SHUTDOWN_TIMEOUT, ServiceState, ServiceStateManager, ShutdownSignal, wait_for_shutdown};
use bytes::Bytes;
use chrono::Datelike;
use clap::Parser;
@@ -23,6 +23,7 @@ use common::{
// error::{Error, Result},
globals::set_global_addr,
};
use ecstore::StorageAPI;
use ecstore::bucket::metadata_sys::init_bucket_metadata_sys;
use ecstore::cmd::bucket_replication::init_bucket_replication_pool;
use ecstore::config as ecconfig;
@@ -30,12 +31,11 @@ use ecstore::config::GLOBAL_ConfigSys;
use ecstore::heal::background_heal_ops::init_auto_heal;
use ecstore::rpc::make_server;
use ecstore::store_api::BucketOptions;
use ecstore::StorageAPI;
use ecstore::{
endpoints::EndpointServerPools,
heal::data_scanner::init_data_scanner,
set_global_endpoints,
store::{init_local_disks, ECStore},
store::{ECStore, init_local_disks},
update_erasure_type,
};
use ecstore::{global::set_global_rustfs_port, notification_sys::new_global_notification_sys};
@@ -50,7 +50,7 @@ use iam::init_iam_sys;
use license::init_license;
use protos::proto_gen::node_service::node_service_server::NodeServiceServer;
use rustfs_config::{DEFAULT_ACCESS_KEY, DEFAULT_SECRET_KEY, RUSTFS_TLS_CERT, RUSTFS_TLS_KEY};
use rustfs_obs::{init_obs, set_global_guard, SystemObserver};
use rustfs_obs::{SystemObserver, init_obs, set_global_guard};
use rustfs_utils::net::parse_and_resolve_address;
use rustls::ServerConfig;
use s3s::{host::MultiDomain, service::S3ServiceBuilder};
@@ -62,12 +62,12 @@ use std::sync::Arc;
use std::time::Duration;
use tokio::net::TcpListener;
#[cfg(unix)]
use tokio::signal::unix::{signal, SignalKind};
use tokio::signal::unix::{SignalKind, signal};
use tokio_rustls::TlsAcceptor;
use tonic::{metadata::MetadataValue, Request, Status};
use tonic::{Request, Status, metadata::MetadataValue};
use tower_http::cors::CorsLayer;
use tower_http::trace::TraceLayer;
use tracing::{debug, error, info, instrument, warn, Span};
use tracing::{Span, debug, error, info, instrument, warn};
const MI_B: usize = 1024 * 1024;

View File

@@ -236,10 +236,7 @@ mod tests {
let unicode_letters = ['α', 'β', 'γ', 'Α', 'Β', 'Γ', '中', '文', '日', '本', 'ñ', 'ü', 'ç'];
for ch in unicode_letters {
assert!(
dialect.is_identifier_start(ch),
"Unicode letter '{ch}' should be valid identifier start"
);
assert!(dialect.is_identifier_start(ch), "Unicode letter '{ch}' should be valid identifier start");
assert!(dialect.is_identifier_part(ch), "Unicode letter '{ch}' should be valid identifier part");
}
}
@@ -254,10 +251,7 @@ mod tests {
!dialect.is_identifier_start(digit),
"ASCII digit '{digit}' should not be valid identifier start"
);
assert!(
dialect.is_identifier_part(digit),
"ASCII digit '{digit}' should be valid identifier part"
);
assert!(dialect.is_identifier_part(digit), "ASCII digit '{digit}' should be valid identifier part");
}
}