mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-25 23:15:51 +08:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user