use crate::prelude::*;
use std::path::Path;
pub fn create_parent_directories(path: impl AsRef<Path>) -> Result<()> {
let file_dir = path
.as_ref()
.parent()
.ok_or_else(|| format!("Failed to get the parent of {}.", path.as_ref().display()))?;
Ok(std::fs::create_dir_all(file_dir)?)
}
pub fn write_file(path: impl AsRef<Path>, content: impl AsRef<str>) -> Result<()> {
create_parent_directories(path.as_ref())?;
Ok(std::fs::write(path.as_ref(), content.as_ref().as_bytes())?)
}
pub fn copy(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()> {
create_parent_directories(to.as_ref())?;
std::fs::copy(from, to)?;
Ok(())
}