From 71f4faa8cb4570df976b50bd16a4ab43fe85d468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Cluseau?= Date: Mon, 27 Apr 2026 21:27:16 +0200 Subject: [PATCH] add composite FileKind --- src/apply.rs | 20 +++++++++++++++++++- src/lib.rs | 12 ++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/apply.rs b/src/apply.rs index d6e3f28..7c3f91c 100644 --- a/src/apply.rs +++ b/src/apply.rs @@ -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); diff --git a/src/lib.rs b/src/lib.rs index 57750e0..6c90062 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,6 +72,14 @@ pub enum FileKind { Content64(String), Symlink(String), Dir(bool), + Parts(Vec), +} + +#[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, 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) }