implement optional binary files copy

This commit is contained in:
postscriptum 2025-07-01 20:13:44 +03:00
parent cf8c676732
commit ef1ba39589
5 changed files with 101 additions and 43 deletions

View file

@ -7,12 +7,14 @@ use std::path::PathBuf;
pub struct User {
pub name: String,
pub public: PathBuf,
pub root: PathBuf,
}
impl User {
pub fn init(storage: &PathBuf, name: String) -> Result<Self> {
Ok(Self {
public: init(storage, &name, "public")?,
public: init(storage, &name, Some("public"))?,
root: init(storage, &name, None)?,
name,
})
}
@ -36,13 +38,28 @@ impl User {
Ok(posts)
}
pub fn file(&self, name: &str) -> Result<PathBuf> {
let mut p = PathBuf::from(&self.root);
p.push("static");
p.push(name);
if !p.exists() || !p.is_file() {
bail!("File destination `{}` not found!", p.to_string_lossy());
}
Ok(p)
}
}
fn init(storage: &PathBuf, name: &str, target: &str) -> Result<PathBuf> {
fn init(storage: &PathBuf, name: &str, dir: Option<&str>) -> Result<PathBuf> {
let mut p = PathBuf::from(&storage);
p.push("user");
p.push(name);
p.push(target);
if let Some(d) = dir {
p.push(d);
}
if !p.exists() || !p.is_dir() {
bail!("User data location `{}` not found!", p.to_string_lossy());