Skip to content

Commit 480e27d

Browse files
Custom toml parsing for prepare-root.conf
Bootc images have the file "/usr/lib/ostree/prepare-root.conf" with the following contents: ```toml [composefs] enable = yes ``` "enable = yes" is not valid toml, so serde panics while parsing. Signed-off-by: Pragyan Poudyal <[email protected]>
1 parent b1bd9c1 commit 480e27d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/bin/composefs-setup-root.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ struct MountConfig {
4848
transient: bool,
4949
}
5050

51+
#[derive(Deserialize, Default)]
52+
#[allow(dead_code)]
53+
struct ComposeFS {
54+
#[serde(deserialize_with = "yes_no_bool")]
55+
enabled: bool,
56+
}
57+
5158
#[derive(Deserialize, Default)]
5259
struct Config {
5360
#[serde(default)]
@@ -56,6 +63,9 @@ struct Config {
5663
var: MountConfig,
5764
#[serde(default)]
5865
root: RootConfig,
66+
#[allow(dead_code)]
67+
#[serde(default)]
68+
composefs: ComposeFS,
5969
}
6070

6171
// Command-line arguments
@@ -90,6 +100,28 @@ struct Args {
90100
target: Option<PathBuf>,
91101
}
92102

103+
// bootc images have the file "/usr/lib/ostree/prepare-root.conf" with the following contents
104+
//
105+
// ```toml
106+
// [composefs]
107+
// enable = yes
108+
// ```
109+
//
110+
// "enable = yes" is not correct toml, so serde panics while parsing
111+
fn yes_no_bool<'de, D>(deserializer: D) -> Result<bool, D::Error>
112+
where
113+
D: serde::Deserializer<'de>,
114+
{
115+
let s = String::deserialize(deserializer)?;
116+
117+
match s.to_lowercase().as_str() {
118+
"yes" | "true" => Ok(true),
119+
"no" | "false" => Ok(false),
120+
121+
_ => Err(serde::de::Error::custom("expected yes/no or true/false")),
122+
}
123+
}
124+
93125
// Helpers
94126
fn open_dir(dirfd: impl AsFd, name: impl AsRef<Path>) -> rustix::io::Result<OwnedFd> {
95127
openat(

0 commit comments

Comments
 (0)