仅当 no_tun = true 时提示迁移,no_tun = false 静默忽略
This commit is contained in:
+10
-3
@@ -181,7 +181,7 @@ pub fn build_config_from_args_and_file(
|
||||
) -> anyhow::Result<(Config, CtrlConfig)> {
|
||||
if file
|
||||
.as_ref()
|
||||
.is_some_and(|config| config.legacy_no_tun.is_some())
|
||||
.is_some_and(|config| config.legacy_no_tun == Some(true))
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"configuration key 'no_tun' was removed; use device_mode = \"no|tun|tap\""
|
||||
@@ -323,7 +323,7 @@ fn build_from_args_only(args: Args) -> anyhow::Result<(Config, CtrlConfig)> {
|
||||
}
|
||||
|
||||
fn build_from_file_only(file: FileConfig) -> anyhow::Result<(Config, CtrlConfig)> {
|
||||
if file.legacy_no_tun.is_some() {
|
||||
if file.legacy_no_tun == Some(true) {
|
||||
return Err(anyhow!(
|
||||
"configuration key 'no_tun' was removed; use device_mode = \"no|tun|tap\""
|
||||
));
|
||||
@@ -546,9 +546,16 @@ mod tests {
|
||||
let legacy: FileConfig = toml::from_str("no_tun = true").unwrap();
|
||||
let error = match build_config_from_args_and_file(None, Some(legacy)) {
|
||||
Err(error) => error,
|
||||
Ok(_) => panic!("legacy no_tun must be rejected"),
|
||||
Ok(_) => panic!("legacy no_tun = true must be rejected"),
|
||||
};
|
||||
assert!(error.to_string().contains("device_mode"));
|
||||
|
||||
let legacy_false: FileConfig = toml::from_str(
|
||||
"no_tun = false\nserver = [\"quic://127.0.0.1:29872\"]\nnetwork_code = \"test\"",
|
||||
)
|
||||
.unwrap();
|
||||
build_config_from_args_and_file(None, Some(legacy_false))
|
||||
.expect("legacy no_tun = false should be ignored");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -288,7 +288,7 @@ pub struct StartConfig {
|
||||
|
||||
impl StartConfig {
|
||||
fn reject_legacy_no_tun(&self) -> anyhow::Result<()> {
|
||||
if self.legacy_no_tun.is_some() {
|
||||
if self.legacy_no_tun == Some(true) {
|
||||
bail!("configuration key 'no_tun' was removed; use device_mode = \"no|tun|tap\"")
|
||||
}
|
||||
Ok(())
|
||||
@@ -1800,6 +1800,10 @@ network_code = "test"
|
||||
|
||||
let legacy: StartConfig = toml::from_str(&format!("{base}no_tun = true\n")).unwrap();
|
||||
assert!(legacy.reject_legacy_no_tun().is_err());
|
||||
|
||||
let legacy_false: StartConfig =
|
||||
toml::from_str(&format!("{base}no_tun = false\n")).unwrap();
|
||||
assert!(legacy_false.reject_legacy_no_tun().is_ok());
|
||||
}
|
||||
|
||||
/// 两个实例同时处于 Starting 互不影响
|
||||
|
||||
Reference in New Issue
Block a user