|
1 | 1 | use crate::env_manager::{ |
2 | 2 | DownloadStatus, EnvironmentProvider, EnvironmentVersion, emit_download_progress, |
3 | 3 | }; |
4 | | -use log::{debug, error, info, warn}; |
| 4 | +use log::{error, info, warn}; |
5 | 5 | use serde::{Deserialize, Serialize}; |
6 | | -use std::path::PathBuf; |
| 6 | +use std::path::{Path, PathBuf}; |
7 | 7 | use std::time::{Duration, SystemTime}; |
8 | 8 | use tauri::AppHandle; |
9 | 9 |
|
@@ -152,7 +152,7 @@ impl ScalaEnvironmentProvider { |
152 | 152 |
|
153 | 153 | let response = request.send().await.map_err(|e| { |
154 | 154 | // 如果请求失败,尝试使用缓存(即使过期) |
155 | | - if let Some(cached_releases) = self.read_cache_ignore_expiry() { |
| 155 | + if let Some(_cached_releases) = self.read_cache_ignore_expiry() { |
156 | 156 | warn!("GitHub API 请求失败,使用过期缓存: {}", e); |
157 | 157 | return format!("GitHub API 请求失败,已使用缓存数据: {}", e); |
158 | 158 | } |
@@ -238,12 +238,10 @@ impl ScalaEnvironmentProvider { |
238 | 238 |
|
239 | 239 | // 检查是否有包含 bin 目录的子目录 |
240 | 240 | 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; |
247 | 245 | } |
248 | 246 | } |
249 | 247 | } |
@@ -358,7 +356,7 @@ impl ScalaEnvironmentProvider { |
358 | 356 | Ok(()) |
359 | 357 | } |
360 | 358 |
|
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> { |
362 | 360 | use zip::ZipArchive; |
363 | 361 |
|
364 | 362 | let file = |
@@ -481,13 +479,11 @@ impl EnvironmentProvider for ScalaEnvironmentProvider { |
481 | 479 | let mut actual_path = version_dir.clone(); |
482 | 480 |
|
483 | 481 | 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; |
491 | 487 | } |
492 | 488 | } |
493 | 489 | } |
@@ -521,40 +517,36 @@ impl EnvironmentProvider for ScalaEnvironmentProvider { |
521 | 517 | let entries = |
522 | 518 | std::fs::read_dir(&self.install_dir).map_err(|e| format!("读取安装目录失败: {}", e))?; |
523 | 519 |
|
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; |
546 | 538 | } |
547 | 539 | } |
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 | | - }); |
557 | 540 | } |
| 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 | + }); |
558 | 550 | } |
559 | 551 | } |
560 | 552 | } |
@@ -621,13 +613,11 @@ impl EnvironmentProvider for ScalaEnvironmentProvider { |
621 | 613 | // 查找解压后的实际目录(可能包含版本号前缀) |
622 | 614 | let mut actual_install_path = install_path.clone(); |
623 | 615 | 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; |
631 | 621 | } |
632 | 622 | } |
633 | 623 | } |
@@ -661,13 +651,11 @@ impl EnvironmentProvider for ScalaEnvironmentProvider { |
661 | 651 | // 查找实际的安装目录 |
662 | 652 | let mut actual_install_path = install_path.clone(); |
663 | 653 | 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; |
671 | 659 | } |
672 | 660 | } |
673 | 661 | } |
|
0 commit comments