mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-04-29 17:36:35 +08:00
refactor: 删除部分多余的 Ventoy 逻辑
This commit is contained in:
@@ -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};
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
13
src/main.rs
13
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());
|
||||
|
||||
Reference in New Issue
Block a user