Config: query files
This commit is contained in:
@ -189,10 +189,13 @@ pub struct HostConfig {
|
|||||||
pub kernel: String,
|
pub kernel: String,
|
||||||
pub versions: Map<String, String>,
|
pub versions: Map<String, String>,
|
||||||
|
|
||||||
|
/// initrd config template
|
||||||
pub bootstrap_config: String,
|
pub bootstrap_config: String,
|
||||||
|
/// files to add to the final initrd config, with rendering
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||||
pub initrd_files: Vec<crate::File>,
|
pub initrd_files: Vec<crate::File>,
|
||||||
|
|
||||||
|
/// system config template
|
||||||
pub config: String,
|
pub config: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
15
src/lib.rs
15
src/lib.rs
@ -52,7 +52,7 @@ pub struct User {
|
|||||||
pub gid: Option<u32>,
|
pub gid: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
#[derive(Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
|
||||||
pub struct File {
|
pub struct File {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
@ -61,10 +61,21 @@ pub struct File {
|
|||||||
pub kind: FileKind,
|
pub kind: FileKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
#[derive(Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum FileKind {
|
pub enum FileKind {
|
||||||
Content(String),
|
Content(String),
|
||||||
Symlink(String),
|
Symlink(String),
|
||||||
Dir(bool),
|
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