From 5845e3ab6a36a699f3342697248c73b51333e7df Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 16 Apr 2021 16:50:50 -0400 Subject: [PATCH] compose: Move repos/lockfile-repos validation to Rust More prep for removing treespec. --- rust/src/treefile.rs | 11 +++++++++++ src/app/rpmostree-composeutil.cxx | 6 ------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/rust/src/treefile.rs b/rust/src/treefile.rs index bae7a88f..7f41d48e 100644 --- a/rust/src/treefile.rs +++ b/rust/src/treefile.rs @@ -612,6 +612,11 @@ impl Treefile { } } } + if config.repos.is_none() && config.lockfile_repos.is_none() { + return Err(anyhow!( + r#"Treefile has neither "repos" nor "lockfile-repos""# + )); + } if let Some(version_suffix) = config.automatic_version_suffix.as_ref() { if !(version_suffix.len() == 1 && version_suffix.is_ascii()) { return Err(io::Error::new( @@ -1235,6 +1240,8 @@ pub(crate) mod tests { pub(crate) static VALID_PRELUDE: &str = indoc! {r#" ref: "exampleos/x86_64/blah" + repos: + - baserepo packages: - foo bar - baz @@ -1485,6 +1492,8 @@ pub(crate) mod tests { "foo.yaml", 0o644, indoc! {" + repos: + - foo packages: - fooinclude "}, @@ -1506,6 +1515,8 @@ pub(crate) mod tests { "foo-x86_64.yaml", 0o644, r#" +repos: + - foo packages: - foo-x86_64-include "#, diff --git a/src/app/rpmostree-composeutil.cxx b/src/app/rpmostree-composeutil.cxx index ce652354..c8090df3 100644 --- a/src/app/rpmostree-composeutil.cxx +++ b/src/app/rpmostree-composeutil.cxx @@ -185,12 +185,6 @@ rpmostree_composeutil_get_treespec (RpmOstreeContext *ctx, return NULL; if (!treespec_bind_array (treedata, treespec, "lockfile-repos", NULL, FALSE, error)) return NULL; - - /* at least one of `repos` and `lockfile-repos` should be defined */ - if (!json_object_has_member (treedata, "repos") && - !json_object_has_member (treedata, "lockfile-repos")) - return (RpmOstreeTreespec*)glnx_null_throw (error, "Treefile has neither \"repos\" nor \"lockfile-repos\" members"); - if (!treespec_bind_array (treedata, treespec, "install-langs", "instlangs", FALSE, error)) return NULL;