Skip to content

Commit 2b0730a

Browse files
committed
fix (core): 修复 clippy 错误
1 parent 7b32876 commit 2b0730a

1 file changed

Lines changed: 23 additions & 27 deletions

File tree

src-tauri/src/utils/logger.rs

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,11 @@ pub async fn get_log_files(app: AppHandle) -> Result<Vec<String>, String> {
109109
let mut log_files = Vec::new();
110110

111111
if let Ok(entries) = std::fs::read_dir(&log_dir) {
112-
for entry in entries {
113-
if let Ok(entry) = entry {
114-
if let Some(filename) = entry.file_name().to_str() {
115-
if filename.ends_with(".log") && filename.starts_with("codeforge-") {
116-
log_files.push(filename.to_string());
117-
info!("获取日志 -> 发现日志文件: {}", filename);
118-
}
112+
for entry in entries.flatten() {
113+
if let Some(filename) = entry.file_name().to_str() {
114+
if filename.ends_with(".log") && filename.starts_with("codeforge-") {
115+
log_files.push(filename.to_string());
116+
info!("获取日志 -> 发现日志文件: {}", filename);
119117
}
120118
}
121119
}
@@ -147,29 +145,27 @@ pub async fn clear_logs(app: AppHandle, keep_days: u32) -> Result<u32, String> {
147145
let mut scanned_count = 0;
148146

149147
if let Ok(entries) = std::fs::read_dir(&log_dir) {
150-
for entry in entries {
151-
if let Ok(entry) = entry {
152-
if let Some(filename) = entry.file_name().to_str() {
153-
if filename.ends_with(".log") && filename.starts_with("codeforge-") {
154-
scanned_count += 1;
155-
// 从文件名提取日期 codeforge-2024-08-09.log
156-
if let Some(date_str) = filename
157-
.strip_prefix("codeforge-")
158-
.and_then(|s| s.strip_suffix(".log"))
148+
for entry in entries.flatten() {
149+
if let Some(filename) = entry.file_name().to_str() {
150+
if filename.ends_with(".log") && filename.starts_with("codeforge-") {
151+
scanned_count += 1;
152+
// 从文件名提取日期 codeforge-2024-08-09.log
153+
if let Some(date_str) = filename
154+
.strip_prefix("codeforge-")
155+
.and_then(|s| s.strip_suffix(".log"))
156+
{
157+
if let Ok(file_date) =
158+
chrono::NaiveDate::parse_from_str(date_str, "%Y-%m-%d")
159159
{
160-
if let Ok(file_date) =
161-
chrono::NaiveDate::parse_from_str(date_str, "%Y-%m-%d")
162-
{
163-
if file_date < cutoff_date.date_naive() {
164-
if let Err(e) = std::fs::remove_file(entry.path()) {
165-
warn!("清理日志 -> 删除日志文件失败 {}: {}", filename, e);
166-
} else {
167-
info!("清理日志 -> 已删除日志文件: {}", filename);
168-
deleted_count += 1;
169-
}
160+
if file_date < cutoff_date.date_naive() {
161+
if let Err(e) = std::fs::remove_file(entry.path()) {
162+
warn!("清理日志 -> 删除日志文件失败 {}: {}", filename, e);
170163
} else {
171-
info!("清理日志 -> 日志文件文件未到期,将被保留: {}", filename);
164+
info!("清理日志 -> 已删除日志文件: {}", filename);
165+
deleted_count += 1;
172166
}
167+
} else {
168+
info!("清理日志 -> 日志文件文件未到期,将被保留: {}", filename);
173169
}
174170
}
175171
}

0 commit comments

Comments
 (0)