base64: be a tolerant reader
This commit is contained in:
@ -3,6 +3,8 @@ use log::info;
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
||||||
|
use crate::base64_decode;
|
||||||
|
|
||||||
pub async fn files(files: &[crate::File], root: &str) -> Result<()> {
|
pub async fn files(files: &[crate::File], root: &str) -> Result<()> {
|
||||||
for file in files {
|
for file in files {
|
||||||
let path = chroot(root, &file.path);
|
let path = chroot(root, &file.path);
|
||||||
@ -16,8 +18,7 @@ pub async fn files(files: &[crate::File], root: &str) -> Result<()> {
|
|||||||
match &file.kind {
|
match &file.kind {
|
||||||
K::Content(content) => fs::write(path, content.as_bytes()).await?,
|
K::Content(content) => fs::write(path, content.as_bytes()).await?,
|
||||||
K::Content64(content) => {
|
K::Content64(content) => {
|
||||||
use base64::prelude::{Engine as _, BASE64_STANDARD_NO_PAD as B64};
|
let content = base64_decode(content)?;
|
||||||
let content = B64.decode(content)?;
|
|
||||||
fs::write(path, content).await?
|
fs::write(path, content).await?
|
||||||
}
|
}
|
||||||
K::Dir(true) => fs::create_dir(path).await?,
|
K::Dir(true) => fs::create_dir(path).await?,
|
||||||
|
|||||||
@ -81,3 +81,8 @@ impl Config {
|
|||||||
self.files.iter().find(|f| f.path == path)
|
self.files.iter().find(|f| f.path == path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn base64_decode(s: &str) -> Result<Vec<u8>, base64::DecodeError> {
|
||||||
|
use base64::{prelude::BASE64_STANDARD_NO_PAD as B64, Engine};
|
||||||
|
B64.decode(s.trim_end_matches('='))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user