Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prep patches for supporting container overrides #3365

Merged
merged 3 commits into from
Jan 28, 2022

Conversation

cgwalters
Copy link
Member

This is prep for work on #3364


treefile: Don't bail out if /etc/rpm-ostree doesn't exist

As it doesn't by default today, even in a container.


ex-rebuild: Print something in the case where we found no files

Now clearly we should have much more useful information here,
but this is a start.


treefile: Fix parsing of derived config fields

There may be a serde bug going on here. But I think this is
fallout from 72a6a77

Basically we have #[flatten] in 3 places; in both the base
and derive structs, and the base struct has the extra member.

It seems that order matters here. In order to parse the derive
config fields, it needs to be earlier in the struct.

I am at this moment a bit uncertain why this didn't break other
cases.

But this is prep for supporting override-remove in ex rebuild
too.


As it doesn't by default today, even in a container.
Now clearly we should have *much* more useful information here,
but this is a start.
There may be a serde bug going on here.  But I think this is
fallout from coreos@72a6a77

Basically we have `#[flatten]` in 3 places; in both the `base`
and `derive` structs, *and* the `base` struct has the `extra` member.

It seems that order matters here.  In order to parse the derive
config fields, it needs to be earlier in the struct.

I am at this moment a bit uncertain why this didn't break other
cases.

But this is prep for supporting `override-remove` in `ex rebuild`
too.
// TODO use cap-std-ext's https://docs.rs/cap-std-ext/latest/cap_std_ext/dirext/trait.CapStdExtDirExt.html#tymethod.open_dir_optional
let p = Path::new(CLIENT_TREEFILES_DIR);
if !p.exists() {
return Ok(either::Left(std::iter::empty()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I don't follow what either is used for here. Is this just a sneaky way to avoid having to write out the actual chained iterator type?

Copy link
Member Author

@cgwalters cgwalters Jan 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A return value of impl T must have exactly one type determined at compile time. Now, one can return e.g. Box<&dyn T> which does dynamic dispatch.

More at https://internals.rust-lang.org/t/extending-impl-trait-to-allow-multiple-return-types/7921

either is just a convenient enum for returning at most two different types from a function - encapsulated as a single type.

It implements Iterator if both of its element types do, and delegates to them.

@cgwalters
Copy link
Member Author

Trying it out:

$ git diff
diff --git a/rust/src/treefile.rs b/rust/src/treefile.rs
index 0828d595..dfe7cba3 100644
--- a/rust/src/treefile.rs
+++ b/rust/src/treefile.rs
@@ -2292,9 +2292,9 @@ fn iter_etc_treefiles() -> Result<impl Iterator<Item = Result<PathBuf>>> {
     // TODO use cap-std-ext's https://docs.rs/cap-std-ext/latest/cap_std_ext/dirext/trait.CapStdExtDirExt.html#tymethod.open_dir_optional
     let p = Path::new(CLIENT_TREEFILES_DIR);
     if !p.exists() {
-        return Ok(either::Left(std::iter::empty()));
+        return Ok(std::iter::empty());
     }
-    Ok(either::Right(read_dir(CLIENT_TREEFILES_DIR)?.filter_map(
+    Ok(read_dir(CLIENT_TREEFILES_DIR)?.filter_map(
         |res| match res {
             Ok(e) => {
                 let path = e.path();
@@ -2307,7 +2307,7 @@ fn iter_etc_treefiles() -> Result<impl Iterator<Item = Result<PathBuf>>> {
             }
             Err(err) => Some(Err(anyhow::Error::msg(err))),
         },
-    )))
+    ))
 }
 
 /// Create a new client treefile using the treefile dropins in /etc/rpm-ostree/origin.d/.
$ cargo b
cargo b
   Compiling rpmostree-rust v0.1.0 (/var/srv/walters/src/github/coreos/rpm-ostree)
error[E0308]: mismatched types
    --> rust/src/treefile.rs:2297:8
     |
2297 |       Ok(read_dir(CLIENT_TREEFILES_DIR)?.filter_map(
     |  ________^
2298 | |         |res| match res {
2299 | |             Ok(e) => {
2300 | |                 let path = e.path();
...    |
2309 | |         },
2310 | |     ))
     | |_____^ expected struct `std::iter::Empty`, found struct `std::iter::FilterMap`
     |
     = note: expected struct `std::iter::Empty<std::result::Result<PathBuf, anyhow::Error>>`
                found struct `std::iter::FilterMap<std::fs::ReadDir, [closure@rust/src/treefile.rs:2298:9: 2309:10]>`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `rpmostree-rust` due to previous error
$

@cgwalters cgwalters merged commit f75d52e into coreos:main Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants