fix: resolve issue with file deletion during subscription removal
This commit is contained in:
@@ -52,6 +52,7 @@
|
||||
- 修复 Linux WebKit 网络进程的崩溃
|
||||
- 修复无法导入订阅
|
||||
- 修复实际导入成功但显示导入失败的问题
|
||||
- 修复删除订阅时未能实际删除相关文件
|
||||
- 修复 macOS 连接界面显示异常
|
||||
|
||||
## v2.4.2
|
||||
|
||||
1
src-tauri/Cargo.lock
generated
1
src-tauri/Cargo.lock
generated
@@ -1104,6 +1104,7 @@ version = "2.4.3"
|
||||
dependencies = [
|
||||
"aes-gcm",
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
"backoff",
|
||||
"base64 0.22.1",
|
||||
"boa_engine",
|
||||
|
||||
@@ -89,6 +89,7 @@ clash_verge_logger = { version = "0.1.0", git = "https://github.com/clash-verge-
|
||||
clash_verge_service_ipc = { version = "2.0.16", features = [
|
||||
"client",
|
||||
], git = "https://github.com/clash-verge-rev/clash-verge-service-ipc" }
|
||||
async-trait = "0.1.89"
|
||||
# clash_verge_service_ipc = { version = "2.0.16", features = [
|
||||
# "client",
|
||||
# ], path = "../../clash-verge-service-ipc" }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::CmdResult;
|
||||
use crate::{
|
||||
cmd::StringifyErr,
|
||||
config::{
|
||||
Config, IProfiles, PrfItem, PrfOption,
|
||||
profiles::{
|
||||
@@ -191,8 +192,10 @@ pub async fn update_profile(index: String, option: Option<PrfOption>) -> CmdResu
|
||||
/// 删除配置文件
|
||||
#[tauri::command]
|
||||
pub async fn delete_profile(index: String) -> CmdResult {
|
||||
println!("delete_profile: {}", index);
|
||||
// 使用Send-safe helper函数
|
||||
let should_update = wrap_err!(profiles_delete_item_safe(index.clone()).await)?;
|
||||
profiles_save_file_safe().await.stringify_err()?;
|
||||
|
||||
if should_update {
|
||||
match CoreManager::global().update_config().await {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::{PrfOption, prfitem::PrfItem};
|
||||
use crate::{
|
||||
logging_error,
|
||||
utils::{dirs, help, logging::Type},
|
||||
use crate::utils::{
|
||||
dirs::{self, PathBufExec},
|
||||
help,
|
||||
};
|
||||
use anyhow::{Context, Result, bail};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -290,20 +290,10 @@ impl IProfiles {
|
||||
if let Some(index) = index
|
||||
&& let Some(file) = items.remove(index).file
|
||||
{
|
||||
let _ = dirs::app_profiles_dir().map(async move |path| {
|
||||
let path = path.join(file);
|
||||
if path.exists() {
|
||||
let result = fs::remove_file(path.clone()).await;
|
||||
if let Err(err) = result {
|
||||
logging_error!(
|
||||
Type::Config,
|
||||
"[配置文件删除] 删除文件 {} 失败: {}",
|
||||
path.display(),
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
let _ = dirs::app_profiles_dir()?
|
||||
.join(file)
|
||||
.remove_if_exists()
|
||||
.await;
|
||||
}
|
||||
// get the merge index
|
||||
for (i, _) in items.iter().enumerate() {
|
||||
@@ -315,20 +305,10 @@ impl IProfiles {
|
||||
if let Some(index) = merge_index
|
||||
&& let Some(file) = items.remove(index).file
|
||||
{
|
||||
let _ = dirs::app_profiles_dir().map(async move |path| {
|
||||
let path = path.join(file);
|
||||
if path.exists() {
|
||||
let result = fs::remove_file(path.clone()).await;
|
||||
if let Err(err) = result {
|
||||
logging_error!(
|
||||
Type::Config,
|
||||
"[配置文件删除] 删除文件 {} 失败: {}",
|
||||
path.display(),
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
let _ = dirs::app_profiles_dir()?
|
||||
.join(file)
|
||||
.remove_if_exists()
|
||||
.await;
|
||||
}
|
||||
// get the script index
|
||||
for (i, _) in items.iter().enumerate() {
|
||||
@@ -340,20 +320,10 @@ impl IProfiles {
|
||||
if let Some(index) = script_index
|
||||
&& let Some(file) = items.remove(index).file
|
||||
{
|
||||
let _ = dirs::app_profiles_dir().map(async move |path| {
|
||||
let path = path.join(file);
|
||||
if path.exists() {
|
||||
let result = fs::remove_file(path.clone()).await;
|
||||
if let Err(err) = result {
|
||||
logging_error!(
|
||||
Type::Config,
|
||||
"[配置文件删除] 删除文件 {} 失败: {}",
|
||||
path.display(),
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
let _ = dirs::app_profiles_dir()?
|
||||
.join(file)
|
||||
.remove_if_exists()
|
||||
.await;
|
||||
}
|
||||
// get the rules index
|
||||
for (i, _) in items.iter().enumerate() {
|
||||
@@ -365,20 +335,10 @@ impl IProfiles {
|
||||
if let Some(index) = rules_index
|
||||
&& let Some(file) = items.remove(index).file
|
||||
{
|
||||
let _ = dirs::app_profiles_dir().map(async move |path| {
|
||||
let path = path.join(file);
|
||||
if path.exists() {
|
||||
let result = fs::remove_file(path.clone()).await;
|
||||
if let Err(err) = result {
|
||||
logging_error!(
|
||||
Type::Config,
|
||||
"[配置文件删除] 删除文件 {} 失败: {}",
|
||||
path.display(),
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
let _ = dirs::app_profiles_dir()?
|
||||
.join(file)
|
||||
.remove_if_exists()
|
||||
.await;
|
||||
}
|
||||
// get the proxies index
|
||||
for (i, _) in items.iter().enumerate() {
|
||||
@@ -390,20 +350,10 @@ impl IProfiles {
|
||||
if let Some(index) = proxies_index
|
||||
&& let Some(file) = items.remove(index).file
|
||||
{
|
||||
let _ = dirs::app_profiles_dir().map(async move |path| {
|
||||
let path = path.join(file);
|
||||
if path.exists() {
|
||||
let result = fs::remove_file(path.clone()).await;
|
||||
if let Err(err) = result {
|
||||
logging_error!(
|
||||
Type::Config,
|
||||
"[配置文件删除] 删除文件 {} 失败: {}",
|
||||
path.display(),
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
let _ = dirs::app_profiles_dir()?
|
||||
.join(file)
|
||||
.remove_if_exists()
|
||||
.await;
|
||||
}
|
||||
// get the groups index
|
||||
for (i, _) in items.iter().enumerate() {
|
||||
@@ -415,20 +365,10 @@ impl IProfiles {
|
||||
if let Some(index) = groups_index
|
||||
&& let Some(file) = items.remove(index).file
|
||||
{
|
||||
let _ = dirs::app_profiles_dir().map(async move |path| {
|
||||
let path = path.join(file);
|
||||
if path.exists() {
|
||||
let result = fs::remove_file(path.clone()).await;
|
||||
if let Err(err) = result {
|
||||
logging_error!(
|
||||
Type::Config,
|
||||
"[配置文件删除] 删除文件 {} 失败: {}",
|
||||
path.display(),
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
let _ = dirs::app_profiles_dir()?
|
||||
.join(file)
|
||||
.remove_if_exists()
|
||||
.await;
|
||||
}
|
||||
// delete the original uid
|
||||
if current == uid {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::core::handle;
|
||||
use crate::{core::handle, logging, utils::logging::Type};
|
||||
use anyhow::Result;
|
||||
use async_trait::async_trait;
|
||||
use once_cell::sync::OnceCell;
|
||||
use std::{fs, path::PathBuf};
|
||||
use tauri::Manager;
|
||||
@@ -232,3 +233,18 @@ pub fn ipc_path() -> Result<PathBuf> {
|
||||
pub fn ipc_path() -> Result<PathBuf> {
|
||||
Ok(PathBuf::from(r"\\.\pipe\verge-mihomo"))
|
||||
}
|
||||
#[async_trait]
|
||||
pub trait PathBufExec {
|
||||
async fn remove_if_exists(&self) -> Result<()>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl PathBufExec for PathBuf {
|
||||
async fn remove_if_exists(&self) -> Result<()> {
|
||||
if self.exists() {
|
||||
tokio::fs::remove_file(self).await?;
|
||||
logging!(info, Type::File, "Removed file: {:?}", self);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ pub enum Type {
|
||||
Timer,
|
||||
Frontend,
|
||||
Backup,
|
||||
File,
|
||||
Lightweight,
|
||||
Network,
|
||||
ProxyMode,
|
||||
@@ -47,6 +48,7 @@ impl fmt::Display for Type {
|
||||
Type::Timer => write!(f, "[Timer]"),
|
||||
Type::Frontend => write!(f, "[Frontend]"),
|
||||
Type::Backup => write!(f, "[Backup]"),
|
||||
Type::File => write!(f, "[File]"),
|
||||
Type::Lightweight => write!(f, "[Lightweight]"),
|
||||
Type::Network => write!(f, "[Network]"),
|
||||
Type::ProxyMode => write!(f, "[ProxMode]"),
|
||||
|
||||
Reference in New Issue
Block a user