fix(profiles): add cleanup of orphaned files and adjust logging level

This commit is contained in:
Tunglies 2025-12-26 17:17:18 +08:00
parent 63cd4905f9
commit 9c6f5bc991
No known key found for this signature in database
GPG Key ID: B9B01B389469B3E8
2 changed files with 8 additions and 11 deletions

View File

@ -89,6 +89,12 @@ impl Config {
handle::Handle::notice_message(msg_type, msg_content);
}
{
let profiles = Self::profiles().await.data_arc();
// Logging error internally
let _ = profiles.cleanup_orphaned_files().await;
}
Ok(())
}

View File

@ -8,7 +8,7 @@ use clash_verge_logging::{Type, logging};
use serde::{Deserialize, Serialize};
use serde_yaml_ng::Mapping;
use smartstring::alias::String;
use std::{collections::HashSet, sync::Arc};
use std::collections::HashSet;
use tokio::fs;
/// Define the `profiles.yaml` schema
@ -126,15 +126,6 @@ impl IProfiles {
bail!("failed to get the profile item \"uid:{}\"", uid_str);
}
pub fn get_item_arc(&self, uid: &str) -> Option<Arc<PrfItem>> {
self.items.as_ref().and_then(|items| {
items
.iter()
.find(|it| it.uid.as_deref() == Some(uid))
.map(|it| Arc::new(it.clone()))
})
}
/// append new item
/// if the file_data is some
/// then should save the data to file
@ -420,7 +411,7 @@ impl IProfiles {
match path.to_path_buf().remove_if_exists().await {
Ok(_) => {
deleted_files.push(file_name.into());
logging!(info, Type::Config, "已清理冗余文件: {file_name}");
logging!(debug, Type::Config, "已清理冗余文件: {file_name}");
}
Err(e) => {
failed_deletions.push(format!("{file_name}: {e}").into());