add composite FileKind

This commit is contained in:
Mikaël Cluseau
2026-04-27 21:27:16 +02:00
parent 5414b1d529
commit 71f4faa8cb
2 changed files with 29 additions and 3 deletions
+19 -1
View File
@@ -14,7 +14,7 @@ pub async fn files(files: &[crate::File], root: &str, dry_run: bool) -> Result<(
fs::create_dir_all(parent).await?;
}
use crate::FileKind as K;
use crate::{FileKind as K, FilePart as P};
match &file.kind {
K::Content(content) => {
if dry_run {
@@ -39,6 +39,24 @@ pub async fn files(files: &[crate::File], root: &str, dry_run: bool) -> Result<(
fs::write(path, content).await?
}
}
K::Parts(parts) => {
let mut assembly = Vec::new();
for part in parts {
match part {
P::Content(content) => assembly.extend(content.as_bytes()),
P::Content64(content) => assembly.extend(base64_decode(content)?),
}
}
if dry_run {
info!(
"would create {} ({} bytes from parts)",
file.path,
assembly.len()
);
} else {
fs::write(path, assembly).await?
}
}
K::Dir(true) => {
if dry_run {
info!("would create {} (directory)", file.path);
+10 -2
View File
@@ -72,6 +72,14 @@ pub enum FileKind {
Content64(String),
Symlink(String),
Dir(bool),
Parts(Vec<FilePart>),
}
#[derive(Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "lowercase")]
pub enum FilePart {
Content(String),
Content64(String),
}
// ------------------------------------------------------------------------
@@ -86,11 +94,11 @@ impl Config {
}
pub fn base64_decode(s: &str) -> Result<Vec<u8>, base64::DecodeError> {
use base64::{Engine as _, prelude::BASE64_STANDARD_NO_PAD as B64};
use base64::{prelude::BASE64_STANDARD_NO_PAD as B64, Engine as _};
B64.decode(s.trim_end_matches('='))
}
pub fn base64_encode(b: &[u8]) -> String {
use base64::{Engine as _, prelude::BASE64_STANDARD as B64};
use base64::{prelude::BASE64_STANDARD as B64, Engine as _};
B64.encode(b)
}