Config: query files
This commit is contained in:
@ -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,
|
||||
}
|
||||
|
||||
|
||||
15
src/lib.rs
15
src/lib.rs
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user