feat: 支持多版本 target 配置并优化执行前校验

- 将 MirrorTarget.target 改造为 TargetConfig 枚举(支持 Static 与 Versioned)
- TargetConfig 独立实现 FromLua,解耦反序列化与业务校验
- to_command 调整为显式接收执行路径,简化构建逻辑
- 增加未选择版本时的前置拦截与友好提示
This commit is contained in:
2026-09-10 20:15:37 +08:00
parent 38dabd2ace
commit 0bba69fd51
8 changed files with 355 additions and 22 deletions
+24
View File
@@ -1,3 +1,4 @@
use std::fmt;
use crate::error::validation_error;
use mlua::Value;
@@ -39,3 +40,26 @@ pub fn validate_command_name(name: &Value) -> mlua::Result<String> {
}
Ok(name_str)
}
pub fn ensure_no_nul(context: &impl fmt::Display, os_str: &std::ffi::OsStr) -> mlua::Result<()> {
#[cfg(unix)]
{
use std::os::unix::ffi::OsStrExt;
if os_str.as_bytes().contains(&0) {
return Err(conversion_error(format!(
"{} 的值不能包含 NUL 字符",
context
)));
}
}
#[cfg(windows)]
{
use std::os::windows::ffi::OsStrExt;
if os_str.encode_wide().any(|c| c == 0) {
return Err(validation_error(format!(
"{} 的值不能包含 NUL 字符",
context
)));
}
}
Ok(())
}