From cc3cc15774c7e314ab081cdb3563d5d090358d4a Mon Sep 17 00:00:00 2001 From: mofeng-git Date: Mon, 20 Apr 2026 14:07:28 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=88=A0=E9=99=A4=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=A4=9A=E4=BD=99=E7=9A=84=20Ventoy=20=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/ventoy-img-rs/src/lib.rs | 2 +- libs/ventoy-img-rs/src/resources.rs | 31 +---------------------------- src/main.rs | 13 ++---------- 3 files changed, 4 insertions(+), 42 deletions(-) diff --git a/libs/ventoy-img-rs/src/lib.rs b/libs/ventoy-img-rs/src/lib.rs index cc3636d7..372eeddc 100644 --- a/libs/ventoy-img-rs/src/lib.rs +++ b/libs/ventoy-img-rs/src/lib.rs @@ -45,4 +45,4 @@ pub use error::{Result, VentoyError}; pub use exfat::FileInfo; pub use image::VentoyImage; pub use partition::{parse_size, PartitionLayout}; -pub use resources::{get_resource_dir, init_resources, is_initialized, required_files}; +pub use resources::{init_resources, is_initialized, required_files}; diff --git a/libs/ventoy-img-rs/src/resources.rs b/libs/ventoy-img-rs/src/resources.rs index 43a0fc66..c32477fc 100644 --- a/libs/ventoy-img-rs/src/resources.rs +++ b/libs/ventoy-img-rs/src/resources.rs @@ -5,7 +5,7 @@ use crate::error::{Result, VentoyError}; use std::fs; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::sync::OnceLock; /// Resource file names @@ -151,13 +151,6 @@ pub fn get_ventoy_disk_img() -> Result<&'static [u8]> { }) } -/// Get the resource directory path for a given data directory -/// -/// Returns `{data_dir}/ventoy` -pub fn get_resource_dir(data_dir: &Path) -> PathBuf { - data_dir.join("ventoy") -} - /// List required resource files pub fn required_files() -> &'static [&'static str] { &[BOOT_IMG_NAME, CORE_IMG_NAME, VENTOY_DISK_IMG_NAME] @@ -166,22 +159,6 @@ pub fn required_files() -> &'static [&'static str] { #[cfg(test)] mod tests { use super::*; - use std::io::Write; - use tempfile::TempDir; - - fn create_test_resources(dir: &Path) { - // Create boot.img (512 bytes) - let mut boot = std::fs::File::create(dir.join(BOOT_IMG_NAME)).unwrap(); - boot.write_all(&[0u8; 512]).unwrap(); - - // Create core.img (fake, 1KB) - let mut core = std::fs::File::create(dir.join(CORE_IMG_NAME)).unwrap(); - core.write_all(&[0u8; 1024]).unwrap(); - - // Create ventoy.disk.img (fake, 1KB) - let mut ventoy = std::fs::File::create(dir.join(VENTOY_DISK_IMG_NAME)).unwrap(); - ventoy.write_all(&[0u8; 1024]).unwrap(); - } #[test] fn test_required_files() { @@ -192,10 +169,4 @@ mod tests { assert!(files.contains(&"ventoy.disk.img")); } - #[test] - fn test_get_resource_dir() { - let data_dir = Path::new("/var/lib/one-kvm"); - let resource_dir = get_resource_dir(data_dir); - assert_eq!(resource_dir, PathBuf::from("/var/lib/one-kvm/ventoy")); - } } diff --git a/src/main.rs b/src/main.rs index 22f95130..c31951fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -362,16 +362,11 @@ async fn main() -> anyhow::Result<()> { // Create MSD controller (optional, based on config) let msd = if config.msd.enabled { - // Initialize Ventoy resources from data directory - let ventoy_resource_dir = ventoy_img::get_resource_dir(&data_dir); + // `{data_dir}/ventoy`: boot.img, core.img, ventoy.disk.img for ventoy_img + let ventoy_resource_dir = data_dir.join("ventoy"); if ventoy_resource_dir.exists() { if let Err(e) = ventoy_img::init_resources(&ventoy_resource_dir) { tracing::warn!("Failed to initialize Ventoy resources: {}", e); - tracing::info!( - "Ventoy resource files should be placed in: {}", - ventoy_resource_dir.display() - ); - tracing::info!("Required files: {:?}", ventoy_img::required_files()); } else { tracing::info!( "Ventoy resources initialized from {}", @@ -383,10 +378,6 @@ async fn main() -> anyhow::Result<()> { "Ventoy resource directory not found: {}", ventoy_resource_dir.display() ); - tracing::info!( - "Create the directory and place the following files: {:?}", - ventoy_img::required_files() - ); } let controller = MsdController::new(otg_service.clone(), config.msd.msd_dir_path());