fix: 升级目录改为使用 /tmp 目录,避免遗留升级文件 #280

This commit is contained in:
mofeng-git
2026-07-29 17:59:28 +08:00
parent 887f29096f
commit fbcd95b617
2 changed files with 10 additions and 8 deletions

View File

@@ -550,7 +550,7 @@ async fn main() -> anyhow::Result<()> {
None None
}; };
let update_service = Arc::new(UpdateService::new(data_dir.join("updates"))); let update_service = Arc::new(UpdateService::new());
let computer_use = ComputerUseManager::new(config_store.clone(), hid.clone()); let computer_use = ComputerUseManager::new(config_store.clone(), hid.clone());
let state = AppState::new( let state = AppState::new(

View File

@@ -110,13 +110,12 @@ pub struct UpdateStatusResponse {
pub struct UpdateService { pub struct UpdateService {
client: reqwest::Client, client: reqwest::Client,
base_url: String, base_url: String,
work_dir: PathBuf,
status: RwLock<UpdateStatusResponse>, status: RwLock<UpdateStatusResponse>,
upgrade_permit: Arc<Semaphore>, upgrade_permit: Arc<Semaphore>,
} }
impl UpdateService { impl UpdateService {
pub fn new(work_dir: PathBuf) -> Self { pub fn new() -> Self {
let base_url = std::env::var("ONE_KVM_UPDATE_BASE_URL") let base_url = std::env::var("ONE_KVM_UPDATE_BASE_URL")
.ok() .ok()
.filter(|url| !url.trim().is_empty()) .filter(|url| !url.trim().is_empty())
@@ -125,7 +124,6 @@ impl UpdateService {
Self { Self {
client: reqwest::Client::new(), client: reqwest::Client::new(),
base_url, base_url,
work_dir,
status: RwLock::new(UpdateStatusResponse { status: RwLock::new(UpdateStatusResponse {
success: true, success: true,
phase: UpdatePhase::Idle, phase: UpdatePhase::Idle,
@@ -289,10 +287,13 @@ impl UpdateService {
) )
.await; .await;
tokio::fs::create_dir_all(&self.work_dir).await?; let download_dir = tempfile::Builder::new()
let staging_path = self .prefix("one-kvm-update-")
.work_dir .tempdir()
.join(format!("one-kvm-{}-download", target_version)); .map_err(|e| {
AppError::Internal(format!("Failed to create update temp directory: {}", e))
})?;
let staging_path = download_dir.path().join("tmpfile");
let artifact_url = self.resolve_url(&artifact.url); let artifact_url = self.resolve_url(&artifact.url);
self.download_and_verify(&artifact_url, &staging_path, &artifact) self.download_and_verify(&artifact_url, &staging_path, &artifact)
@@ -308,6 +309,7 @@ impl UpdateService {
.await; .await;
let restart_exe = self.install_binary(&staging_path).await?; let restart_exe = self.install_binary(&staging_path).await?;
drop(download_dir);
self.set_status( self.set_status(
UpdatePhase::Restarting, UpdatePhase::Restarting,