Config: query files

This commit is contained in:
Mikaël Cluseau
2025-12-03 12:54:45 +01:00
parent ecbbb82c7a
commit 298366a0aa
2 changed files with 16 additions and 2 deletions

View File

@ -189,10 +189,13 @@ pub struct HostConfig {
pub kernel: String,
pub versions: Map<String, String>,
/// initrd config template
pub bootstrap_config: String,
/// files to add to the final initrd config, with rendering
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub initrd_files: Vec<crate::File>,
/// system config template
pub config: String,
}

View File

@ -52,7 +52,7 @@ pub struct User {
pub gid: Option<u32>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[derive(Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
pub struct File {
pub path: String,
#[serde(skip_serializing_if = "Option::is_none")]
@ -61,10 +61,21 @@ pub struct File {
pub kind: FileKind,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[derive(Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "snake_case")]
pub enum FileKind {
Content(String),
Symlink(String),
Dir(bool),
}
// ------------------------------------------------------------------------
impl Config {
pub fn has_file(&self, path: &str) -> bool {
self.files.iter().any(|f| f.path == path)
}
pub fn file(&self, path: &str) -> Option<&File> {
self.files.iter().find(|f| f.path == path)
}
}