mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-05 12:57:42 +00:00
fix:Apply suggestions from clippy 1.88
This commit is contained in:
@@ -30,7 +30,7 @@ pub fn Home() -> Element {
|
||||
#[allow(clippy::redundant_closure)]
|
||||
let service = use_signal(|| ServiceManager::new());
|
||||
let conf = RustFSConfig::load().unwrap_or_else(|e| {
|
||||
ServiceManager::show_error(&format!("加载配置失败:{}", e));
|
||||
ServiceManager::show_error(&format!("加载配置失败:{e}"));
|
||||
RustFSConfig::default()
|
||||
});
|
||||
|
||||
@@ -78,7 +78,7 @@ pub fn Home() -> Element {
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
ServiceManager::show_error(&format!("服务启动失败:{}", e));
|
||||
ServiceManager::show_error(&format!("服务启动失败:{e}"));
|
||||
}
|
||||
}
|
||||
// Only set loading to false when it's actually done
|
||||
@@ -104,7 +104,7 @@ pub fn Home() -> Element {
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
ServiceManager::show_error(&format!("服务停止失败:{}", e));
|
||||
ServiceManager::show_error(&format!("服务停止失败:{e}"));
|
||||
}
|
||||
}
|
||||
debug!("service_state: {:?}", service_state.read());
|
||||
|
||||
@@ -49,7 +49,7 @@ pub fn Setting() -> Element {
|
||||
let config = config.read().clone();
|
||||
spawn(async move {
|
||||
if let Err(e) = service.read().restart(config).await {
|
||||
ServiceManager::show_error(&format!("发送重启命令失败:{}", e));
|
||||
ServiceManager::show_error(&format!("发送重启命令失败:{e}"));
|
||||
}
|
||||
// reset the status when you're done
|
||||
loading.set(false);
|
||||
|
||||
@@ -288,7 +288,7 @@ mod tests {
|
||||
|
||||
for (input, expected) in test_cases {
|
||||
let result = RustFSConfig::extract_host_port(input);
|
||||
assert_eq!(result, expected, "Failed for input: {}", input);
|
||||
assert_eq!(result, expected, "Failed for input: {input}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,7 +306,7 @@ mod tests {
|
||||
|
||||
for input in invalid_cases {
|
||||
let result = RustFSConfig::extract_host_port(input);
|
||||
assert_eq!(result, None, "Should be None for input: {}", input);
|
||||
assert_eq!(result, None, "Should be None for input: {input}");
|
||||
}
|
||||
|
||||
// Special case: empty host but valid port should still work
|
||||
@@ -437,7 +437,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_debug_format() {
|
||||
let config = RustFSConfig::default_config();
|
||||
let debug_str = format!("{:?}", config);
|
||||
let debug_str = format!("{config:?}");
|
||||
|
||||
assert!(debug_str.contains("RustFSConfig"));
|
||||
assert!(debug_str.contains("address"));
|
||||
@@ -484,14 +484,14 @@ mod tests {
|
||||
fn test_very_long_strings() {
|
||||
let long_string = "a".repeat(1000);
|
||||
let config = RustFSConfig {
|
||||
address: format!("{}:9000", long_string),
|
||||
address: format!("{long_string}:9000"),
|
||||
host: long_string.clone(),
|
||||
port: "9000".to_string(),
|
||||
access_key: long_string.clone(),
|
||||
secret_key: long_string.clone(),
|
||||
domain_name: format!("{}.com", long_string),
|
||||
volume_name: format!("/data/{}", long_string),
|
||||
console_address: format!("{}:9001", long_string),
|
||||
domain_name: format!("{long_string}.com"),
|
||||
volume_name: format!("/data/{long_string}"),
|
||||
console_address: format!("{long_string}:9001"),
|
||||
};
|
||||
|
||||
assert_eq!(config.host.len(), 1000);
|
||||
|
||||
@@ -184,7 +184,7 @@ impl ServiceManager {
|
||||
let cached_hash = fs::read_to_string(&hash_path).await?;
|
||||
let expected_hash = RUSTFS_HASH.lock().await;
|
||||
if cached_hash == *expected_hash {
|
||||
println!("Use cached rustfs: {:?}", executable_path);
|
||||
println!("Use cached rustfs: {executable_path:?}");
|
||||
return Ok(executable_path);
|
||||
}
|
||||
}
|
||||
@@ -235,23 +235,23 @@ impl ServiceManager {
|
||||
match cmd {
|
||||
ServiceCommand::Start(config) => {
|
||||
if let Err(e) = Self::start_service(&config).await {
|
||||
Self::show_error(&format!("启动服务失败:{}", e));
|
||||
Self::show_error(&format!("启动服务失败:{e}"));
|
||||
}
|
||||
}
|
||||
ServiceCommand::Stop => {
|
||||
if let Err(e) = Self::stop_service().await {
|
||||
Self::show_error(&format!("停止服务失败:{}", e));
|
||||
Self::show_error(&format!("停止服务失败:{e}"));
|
||||
}
|
||||
}
|
||||
ServiceCommand::Restart(config) => {
|
||||
if Self::check_service_status().await.is_some() {
|
||||
if let Err(e) = Self::stop_service().await {
|
||||
Self::show_error(&format!("重启服务失败:{}", e));
|
||||
Self::show_error(&format!("重启服务失败:{e}"));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if let Err(e) = Self::start_service(&config).await {
|
||||
Self::show_error(&format!("重启服务失败:{}", e));
|
||||
Self::show_error(&format!("重启服务失败:{e}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -283,7 +283,7 @@ impl ServiceManager {
|
||||
async fn start_service(config: &RustFSConfig) -> Result<(), Box<dyn Error>> {
|
||||
// Check if the service is already running
|
||||
if let Some(existing_pid) = Self::check_service_status().await {
|
||||
return Err(format!("服务已经在运行,PID: {}", existing_pid).into());
|
||||
return Err(format!("服务已经在运行,PID: {existing_pid}").into());
|
||||
}
|
||||
|
||||
// Prepare the service program
|
||||
@@ -304,7 +304,7 @@ impl ServiceManager {
|
||||
let ports = vec![main_port, console_port];
|
||||
for port in ports {
|
||||
if Self::is_port_in_use(host, port).await {
|
||||
return Err(format!("端口 {} 已被占用", port).into());
|
||||
return Err(format!("端口 {port} 已被占用").into());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ impl ServiceManager {
|
||||
|
||||
// Check if the service started successfully
|
||||
if Self::is_port_in_use(host, main_port).await {
|
||||
Self::show_info(&format!("服务启动成功!进程 ID: {}", process_pid));
|
||||
Self::show_info(&format!("服务启动成功!进程 ID: {process_pid}"));
|
||||
|
||||
Ok(())
|
||||
} else {
|
||||
@@ -387,7 +387,7 @@ impl ServiceManager {
|
||||
/// println!("{:?}", result);
|
||||
/// ```
|
||||
async fn is_port_in_use(host: &str, port: u16) -> bool {
|
||||
TcpStream::connect(format!("{}:{}", host, port)).await.is_ok()
|
||||
TcpStream::connect(format!("{host}:{port}")).await.is_ok()
|
||||
}
|
||||
|
||||
/// Show an error message
|
||||
@@ -674,7 +674,7 @@ mod tests {
|
||||
message: "Test message".to_string(),
|
||||
};
|
||||
|
||||
let debug_str = format!("{:?}", result);
|
||||
let debug_str = format!("{result:?}");
|
||||
assert!(debug_str.contains("ServiceOperationResult"));
|
||||
assert!(debug_str.contains("success: true"));
|
||||
assert!(debug_str.contains("Test message"));
|
||||
@@ -691,8 +691,8 @@ mod tests {
|
||||
let cloned_manager = service_manager.clone();
|
||||
|
||||
// Both should be valid (we can't test much more without async runtime)
|
||||
assert!(format!("{:?}", service_manager).contains("ServiceManager"));
|
||||
assert!(format!("{:?}", cloned_manager).contains("ServiceManager"));
|
||||
assert!(format!("{service_manager:?}").contains("ServiceManager"));
|
||||
assert!(format!("{cloned_manager:?}").contains("ServiceManager"));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -710,7 +710,7 @@ mod tests {
|
||||
|
||||
for (input, expected) in test_cases {
|
||||
let result = ServiceManager::extract_port(input);
|
||||
assert_eq!(result, expected, "Failed for input: {}", input);
|
||||
assert_eq!(result, expected, "Failed for input: {input}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -729,7 +729,7 @@ mod tests {
|
||||
|
||||
for input in invalid_cases {
|
||||
let result = ServiceManager::extract_port(input);
|
||||
assert_eq!(result, None, "Should be None for input: {}", input);
|
||||
assert_eq!(result, None, "Should be None for input: {input}");
|
||||
}
|
||||
|
||||
// Special case: empty host but valid port should still work
|
||||
|
||||
@@ -94,7 +94,7 @@ mod tests {
|
||||
|
||||
// We can't actually build it without creating directories,
|
||||
// but we can verify the builder pattern works
|
||||
let debug_str = format!("{:?}", builder);
|
||||
let debug_str = format!("{builder:?}");
|
||||
// The actual debug format might be different, so just check it's not empty
|
||||
assert!(!debug_str.is_empty());
|
||||
// Check that it contains some expected parts
|
||||
@@ -112,10 +112,10 @@ mod tests {
|
||||
let never = Rotation::NEVER;
|
||||
|
||||
// Test that rotation types can be created and formatted
|
||||
assert!(!format!("{:?}", daily).is_empty());
|
||||
assert!(!format!("{:?}", hourly).is_empty());
|
||||
assert!(!format!("{:?}", minutely).is_empty());
|
||||
assert!(!format!("{:?}", never).is_empty());
|
||||
assert!(!format!("{daily:?}").is_empty());
|
||||
assert!(!format!("{hourly:?}").is_empty());
|
||||
assert!(!format!("{minutely:?}").is_empty());
|
||||
assert!(!format!("{never:?}").is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -159,10 +159,10 @@ mod tests {
|
||||
let error_filter = tracing_subscriber::EnvFilter::new("error");
|
||||
|
||||
// Test that filters can be created
|
||||
assert!(!format!("{:?}", info_filter).is_empty());
|
||||
assert!(!format!("{:?}", debug_filter).is_empty());
|
||||
assert!(!format!("{:?}", warn_filter).is_empty());
|
||||
assert!(!format!("{:?}", error_filter).is_empty());
|
||||
assert!(!format!("{info_filter:?}").is_empty());
|
||||
assert!(!format!("{debug_filter:?}").is_empty());
|
||||
assert!(!format!("{warn_filter:?}").is_empty());
|
||||
assert!(!format!("{error_filter:?}").is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -201,7 +201,7 @@ mod tests {
|
||||
assert_eq!(suffix, "log");
|
||||
|
||||
// Test that these would create valid filenames
|
||||
let sample_filename = format!("{}.2024-01-01.{}", prefix, suffix);
|
||||
let sample_filename = format!("{prefix}.2024-01-01.{suffix}");
|
||||
assert_eq!(sample_filename, "rustfs-cli.2024-01-01.log");
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ mod tests {
|
||||
assert_eq!(logs_dir_name, "logs");
|
||||
|
||||
// Test path joining
|
||||
let combined = format!("{}/{}", rustfs_dir_name, logs_dir_name);
|
||||
let combined = format!("{rustfs_dir_name}/{logs_dir_name}");
|
||||
assert_eq!(combined, "rustfs/logs");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user