diff --git a/system-images/compat/src/config/mod.rs b/system-images/compat/src/config/mod.rs index 05c7d7a00..40070648f 100644 --- a/system-images/compat/src/config/mod.rs +++ b/system-images/compat/src/config/mod.rs @@ -46,7 +46,7 @@ pub fn validate_configuration( pub fn validate_dependency_configuration( name: &str, - config: Config, + config: &Option, parent_name: &str, parent_config: Config, rules_path: &Path, @@ -54,7 +54,11 @@ pub fn validate_dependency_configuration( let rules: Vec = serde_yaml::from_reader(std::fs::File::open(rules_path)?)?; let mut cfgs = LinearMap::new(); cfgs.insert(parent_name, Cow::Borrowed(&parent_config)); - cfgs.insert(name, Cow::Borrowed(&config)); + if let Some(config) = config { + cfgs.insert(name, Cow::Borrowed(&config)) + } else { + cfgs.insert(name, Cow::Owned(serde_json::Map::new())) + }; let rule_check = rules .into_iter() .map(|r| r.check(&parent_config, &cfgs)) @@ -67,7 +71,7 @@ pub fn validate_dependency_configuration( pub fn apply_dependency_configuration( package_id: &str, - config: Config, + config: Option, dependency_id: &str, mut dep_config: Config, rules_path: &Path, @@ -76,7 +80,10 @@ pub fn apply_dependency_configuration( serde_yaml::from_reader(std::fs::File::open(rules_path)?)?; let mut cfgs = LinearMap::new(); cfgs.insert(dependency_id, Cow::Owned(dep_config.clone())); - cfgs.insert(package_id, Cow::Owned(config.clone())); + match config { + Some(config) => cfgs.insert(package_id, Cow::Owned(config.clone())), + None => cfgs.insert(package_id, Cow::Owned(serde_json::Map::new())), + }; let rule_check = rules .into_iter() .map(|r| r.apply(dependency_id, &mut dep_config, &mut cfgs)) diff --git a/system-images/compat/src/main.rs b/system-images/compat/src/main.rs index 932270c81..ea7a67b1b 100644 --- a/system-images/compat/src/main.rs +++ b/system-images/compat/src/main.rs @@ -201,18 +201,19 @@ fn inner_main() -> Result<(), anyhow::Error> { ("dependency", Some(sub_m)) => match sub_m.subcommand() { ("check", Some(sub_m)) => { let parent_config = serde_yaml::from_reader(stdin())?; - let config = serde_yaml::from_reader( - File::open( - Path::new(sub_m.value_of("mountpoint").unwrap()).join("start9/config.yaml"), - ) - .unwrap(), - )?; + let cfg_path = + Path::new(sub_m.value_of("mountpoint").unwrap()).join("start9/config.yaml"); + let config = if cfg_path.exists() { + Some(serde_yaml::from_reader(File::open(cfg_path).unwrap()).unwrap()) + } else { + None + }; let rules_path = Path::new(sub_m.value_of("assets").unwrap()); let name = sub_m.value_of("dependent_package_id").unwrap(); let parent_name = sub_m.value_of("dependency_package_id").unwrap(); match validate_dependency_configuration( name, - config, + &config, parent_name, parent_config, rules_path, @@ -229,12 +230,13 @@ fn inner_main() -> Result<(), anyhow::Error> { } ("auto-configure", Some(sub_m)) => { let dep_config = serde_yaml::from_reader(stdin())?; - let config = serde_yaml::from_reader( - File::open( - Path::new(sub_m.value_of("mountpoint").unwrap()).join("start9/config.yaml"), - ) - .unwrap(), - )?; + let cfg_path = + Path::new(sub_m.value_of("mountpoint").unwrap()).join("start9/config.yaml"); + let config = if cfg_path.exists() { + Some(serde_yaml::from_reader(File::open(cfg_path).unwrap()).unwrap()) + } else { + None + }; let rules_path = Path::new(sub_m.value_of("assets").unwrap()); let package_id = sub_m.value_of("dependent_package_id").unwrap(); let dependency_id = sub_m.value_of("dependency_package_id").unwrap();