fix(tray): resolve tray open log failed (#6301)

* fix(tray): resolve tray open log failed

* fix(ci): allow missing_const_for_fn

* fix(windows): run snapshot log cleanup unconditionally and cover all temp dirs

* refactor: simplify snapshot_path

* fix: clippy

* refactor: delete_snapshot_logs

---------

Co-authored-by: Slinetrac <realakayuki@gmail.com>
This commit is contained in:
AetherWing
2026-02-12 03:53:36 +00:00
committed by GitHub
co-authored by Slinetrac
parent 81c56d46c1
commit 847a0a6afd
4 changed files with 59 additions and 2 deletions
+23
View File
@@ -4,6 +4,8 @@ use clash_verge_logging::{Type, logging};
use nanoid::nanoid;
use serde::{Serialize, de::DeserializeOwned};
use serde_yaml_ng::Mapping;
#[cfg(target_os = "windows")]
use std::path::Path;
use std::{path::PathBuf, str::FromStr};
/// read data from yaml as struct T
@@ -134,3 +136,24 @@ pub fn linux_elevator() -> String {
Err(_) => "sudo".to_string(),
}
}
#[cfg(target_os = "windows")]
/// copy the file to the dist path and return the dist path
pub fn snapshot_path(original_path: &Path) -> Result<PathBuf> {
let temp_dir = original_path
.parent()
.ok_or_else(|| anyhow!("Invalid log path"))?
.join("temp");
std::fs::create_dir_all(&temp_dir)?;
let temp_path = temp_dir.join(format!(
"{}_{}.log",
original_path.file_stem().unwrap_or_default().to_string_lossy(),
chrono::Local::now().format("%Y-%m-%d_%H-%M-%S")
));
std::fs::copy(original_path, &temp_path)?;
Ok(temp_path)
}