mirror of
https://codeberg.org/postscriptum/snac2nex.git
synced 2026-04-01 05:35:27 +00:00
implement optional binary files copy
This commit is contained in:
parent
cf8c676732
commit
ef1ba39589
5 changed files with 101 additions and 43 deletions
|
|
@ -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());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue