fix(config): 优化配置解析

- 完善 `FromLua` 转换与边界校验,拦截空洞 (`nil`) 及非整数键
This commit is contained in:
2026-08-19 11:34:16 +08:00
parent e3cb065b35
commit f59040c11e
7 changed files with 168 additions and 167 deletions

View File

@@ -1,4 +1,4 @@
use crate::error::ShimError;
use anyhow::{Context, Result, bail};
use std::path::{Path, PathBuf};
pub struct ShimLayout {
@@ -9,27 +9,18 @@ pub struct ShimLayout {
impl ShimLayout {
/// 从当前可执行文件解析 shim 安装目录布局
pub fn from_executable(exe_path: impl AsRef<Path>) -> Result<Self, ShimError> {
pub fn from_executable(exe_path: impl AsRef<Path>) -> Result<Self> {
let exe_path = exe_path.as_ref();
let bin_dir = exe_path
.parent()
.ok_or_else(|| {
ShimError::PathResolution(format!(
"无法获取程序 [{}] 的父级 bin 目录",
exe_path.display()
))
})?
.with_context(|| format!("无法获取程序 [{}] 的父级 bin 目录", exe_path.display()))?
.to_path_buf();
eprintln!("bin_dir目录 {}", bin_dir.display());
let root_dir = bin_dir
.parent()
.ok_or_else(|| {
ShimError::PathResolution(format!(
"无法获取 bin 目录 [{}] 的父级 root 目录",
bin_dir.display()
))
})?
.with_context(|| format!("无法获取 bin 目录 [{}] 的父级 root 目录", bin_dir.display()))?
.to_path_buf();
eprintln!("root_dir 目录 {}", root_dir.display());