Skip to content

Commit 0f2e9c0

Browse files
committed
style: 解决代码警告
1 parent f8b142b commit 0f2e9c0

File tree

2 files changed

+53
-64
lines changed

2 files changed

+53
-64
lines changed

src-tauri/src/env_manager.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use async_trait::async_trait;
2-
use log::{debug, error, info};
2+
use log::{error, info};
33
use serde::{Deserialize, Serialize};
44
use std::collections::HashMap;
55
use std::path::PathBuf;
@@ -43,7 +43,7 @@ pub enum DownloadStatus {
4343
Extracting,
4444
Installing,
4545
Completed,
46-
Failed,
46+
_Failed,
4747
}
4848

4949
// 语言环境提供者特征
@@ -72,6 +72,7 @@ pub trait EnvironmentProvider: Send + Sync {
7272
async fn get_current_version(&self) -> Result<Option<String>, String>;
7373

7474
// 获取安装目录
75+
#[allow(dead_code)]
7576
fn get_install_dir(&self) -> PathBuf;
7677
}
7778

src-tauri/src/env_providers/scala.rs

Lines changed: 50 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::env_manager::{
22
DownloadStatus, EnvironmentProvider, EnvironmentVersion, emit_download_progress,
33
};
4-
use log::{debug, error, info, warn};
4+
use log::{error, info, warn};
55
use serde::{Deserialize, Serialize};
6-
use std::path::PathBuf;
6+
use std::path::{Path, PathBuf};
77
use std::time::{Duration, SystemTime};
88
use tauri::AppHandle;
99

@@ -152,7 +152,7 @@ impl ScalaEnvironmentProvider {
152152

153153
let response = request.send().await.map_err(|e| {
154154
// 如果请求失败,尝试使用缓存(即使过期)
155-
if let Some(cached_releases) = self.read_cache_ignore_expiry() {
155+
if let Some(_cached_releases) = self.read_cache_ignore_expiry() {
156156
warn!("GitHub API 请求失败,使用过期缓存: {}", e);
157157
return format!("GitHub API 请求失败,已使用缓存数据: {}", e);
158158
}
@@ -238,12 +238,10 @@ impl ScalaEnvironmentProvider {
238238

239239
// 检查是否有包含 bin 目录的子目录
240240
if let Ok(entries) = std::fs::read_dir(&install_path) {
241-
for entry in entries {
242-
if let Ok(entry) = entry {
243-
let path = entry.path();
244-
if path.is_dir() && path.join("bin").exists() {
245-
return true;
246-
}
241+
for entry in entries.flatten() {
242+
let path = entry.path();
243+
if path.is_dir() && path.join("bin").exists() {
244+
return true;
247245
}
248246
}
249247
}
@@ -358,7 +356,7 @@ impl ScalaEnvironmentProvider {
358356
Ok(())
359357
}
360358

361-
fn extract_zip(&self, archive_path: &PathBuf, dest_dir: &PathBuf) -> Result<(), String> {
359+
fn extract_zip(&self, archive_path: &PathBuf, dest_dir: &Path) -> Result<(), String> {
362360
use zip::ZipArchive;
363361

364362
let file =
@@ -481,13 +479,11 @@ impl EnvironmentProvider for ScalaEnvironmentProvider {
481479
let mut actual_path = version_dir.clone();
482480

483481
if let Ok(entries) = std::fs::read_dir(&version_dir) {
484-
for entry in entries {
485-
if let Ok(entry) = entry {
486-
let path = entry.path();
487-
if path.is_dir() && path.join("bin").exists() {
488-
actual_path = path;
489-
break;
490-
}
482+
for entry in entries.flatten() {
483+
let path = entry.path();
484+
if path.is_dir() && path.join("bin").exists() {
485+
actual_path = path;
486+
break;
491487
}
492488
}
493489
}
@@ -521,40 +517,36 @@ impl EnvironmentProvider for ScalaEnvironmentProvider {
521517
let entries =
522518
std::fs::read_dir(&self.install_dir).map_err(|e| format!("读取安装目录失败: {}", e))?;
523519

524-
for entry in entries {
525-
if let Ok(entry) = entry {
526-
let path = entry.path();
527-
if path.is_dir() {
528-
let version = path
529-
.file_name()
530-
.and_then(|n| n.to_str())
531-
.unwrap_or("")
532-
.to_string();
533-
534-
if self.is_version_installed(&version) {
535-
// 查找实际的包含 bin 目录的路径
536-
let mut actual_install_path = path.clone();
537-
if let Ok(sub_entries) = std::fs::read_dir(&path) {
538-
for sub_entry in sub_entries {
539-
if let Ok(sub_entry) = sub_entry {
540-
let sub_path = sub_entry.path();
541-
if sub_path.is_dir() && sub_path.join("bin").exists() {
542-
actual_install_path = sub_path;
543-
break;
544-
}
545-
}
520+
for entry in entries.flatten() {
521+
let path = entry.path();
522+
if path.is_dir() {
523+
let version = path
524+
.file_name()
525+
.and_then(|n| n.to_str())
526+
.unwrap_or("")
527+
.to_string();
528+
529+
if self.is_version_installed(&version) {
530+
// 查找实际的包含 bin 目录的路径
531+
let mut actual_install_path = path.clone();
532+
if let Ok(sub_entries) = std::fs::read_dir(&path) {
533+
for sub_entry in sub_entries.flatten() {
534+
let sub_path = sub_entry.path();
535+
if sub_path.is_dir() && sub_path.join("bin").exists() {
536+
actual_install_path = sub_path;
537+
break;
546538
}
547539
}
548-
549-
installed.push(EnvironmentVersion {
550-
version: version.clone(),
551-
download_url: String::new(),
552-
install_path: Some(actual_install_path.to_string_lossy().to_string()),
553-
is_installed: true,
554-
size: None,
555-
release_date: None,
556-
});
557540
}
541+
542+
installed.push(EnvironmentVersion {
543+
version: version.clone(),
544+
download_url: String::new(),
545+
install_path: Some(actual_install_path.to_string_lossy().to_string()),
546+
is_installed: true,
547+
size: None,
548+
release_date: None,
549+
});
558550
}
559551
}
560552
}
@@ -621,13 +613,11 @@ impl EnvironmentProvider for ScalaEnvironmentProvider {
621613
// 查找解压后的实际目录(可能包含版本号前缀)
622614
let mut actual_install_path = install_path.clone();
623615
if let Ok(entries) = std::fs::read_dir(&install_path) {
624-
for entry in entries {
625-
if let Ok(entry) = entry {
626-
let path = entry.path();
627-
if path.is_dir() && path.join("bin").exists() {
628-
actual_install_path = path;
629-
break;
630-
}
616+
for entry in entries.flatten() {
617+
let path = entry.path();
618+
if path.is_dir() && path.join("bin").exists() {
619+
actual_install_path = path;
620+
break;
631621
}
632622
}
633623
}
@@ -661,13 +651,11 @@ impl EnvironmentProvider for ScalaEnvironmentProvider {
661651
// 查找实际的安装目录
662652
let mut actual_install_path = install_path.clone();
663653
if let Ok(entries) = std::fs::read_dir(&install_path) {
664-
for entry in entries {
665-
if let Ok(entry) = entry {
666-
let path = entry.path();
667-
if path.is_dir() && path.join("bin").exists() {
668-
actual_install_path = path;
669-
break;
670-
}
654+
for entry in entries.flatten() {
655+
let path = entry.path();
656+
if path.is_dir() && path.join("bin").exists() {
657+
actual_install_path = path;
658+
break;
671659
}
672660
}
673661
}

0 commit comments

Comments
 (0)