add composite FileKind
This commit is contained in:
+19
-1
@@ -14,7 +14,7 @@ pub async fn files(files: &[crate::File], root: &str, dry_run: bool) -> Result<(
|
|||||||
fs::create_dir_all(parent).await?;
|
fs::create_dir_all(parent).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::FileKind as K;
|
use crate::{FileKind as K, FilePart as P};
|
||||||
match &file.kind {
|
match &file.kind {
|
||||||
K::Content(content) => {
|
K::Content(content) => {
|
||||||
if dry_run {
|
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?
|
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) => {
|
K::Dir(true) => {
|
||||||
if dry_run {
|
if dry_run {
|
||||||
info!("would create {} (directory)", file.path);
|
info!("would create {} (directory)", file.path);
|
||||||
|
|||||||
+10
-2
@@ -72,6 +72,14 @@ pub enum FileKind {
|
|||||||
Content64(String),
|
Content64(String),
|
||||||
Symlink(String),
|
Symlink(String),
|
||||||
Dir(bool),
|
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> {
|
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('='))
|
B64.decode(s.trim_end_matches('='))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn base64_encode(b: &[u8]) -> String {
|
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)
|
B64.encode(b)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user