fix(runtime-bundle): reject mixed owners of a provider path

This commit is contained in:
Tunglies
2026-12-03 21:39:25 +08:00
parent dc9ace6645
commit 1c4bf7c223
+29 -7
View File
@@ -299,13 +299,15 @@ fn plan_provider(
};
let destination = destination_below_root(config_root, &source)?;
let reserved = TriStr::from(destination.as_str());
if destinations.insert(reserved.clone())
&& let Some(assets) = assets
{
assets.push(RuntimeAsset {
source: source.to_string_lossy().into_owned(),
destination: reserved,
});
if destinations.insert(reserved.clone()) {
if let Some(assets) = assets {
assets.push(RuntimeAsset {
source: source.to_string_lossy().into_owned(),
destination: reserved,
});
}
} else if remote_providers.iter().any(|provider| provider.destination == reserved) {
return Err(RuntimeBundleError::DuplicateDestination(destination));
}
destination
}
@@ -461,6 +463,26 @@ fn normalized_destination(relative: &Path) -> Result<String> {
mod tests {
use super::{collect_runtime_bundle, remote_providers_of, resolve_provider_path_conflicts};
#[test]
fn local_and_remote_providers_cannot_claim_the_same_file() -> Result<(), Box<dyn std::error::Error>> {
let root = std::env::temp_dir().join(format!("clash-verge-mixed-providers-{}", std::process::id()));
std::fs::create_dir_all(&root)?;
std::fs::write(root.join("shared.yaml"), "payload: []")?;
let local = "type: file, path: ./shared.yaml";
let remote = "type: http, url: 'https://example.com/provider', path: shared.yaml";
for (proxy, rule) in [(local, remote), (remote, local)] {
let config = serde_yaml_ng::from_str(&format!(
"proxy-providers: {{a: {{{proxy}}}}}\nrule-providers: {{b: {{{rule}}}}}"
))?;
assert!(matches!(
remote_providers_of(&config, &root),
Err(super::RuntimeBundleError::DuplicateDestination(path)) if path == "shared.yaml"
));
}
std::fs::remove_dir_all(root)?;
Ok(())
}
#[tokio::test]
async fn conflicting_sources_get_separate_paths_in_config_bundle_and_readback()
-> std::result::Result<(), Box<dyn std::error::Error>> {