make upload argument optional (delegate FoF/upload to external rsync logic)

This commit is contained in:
yggverse 2026-03-19 23:24:21 +02:00
parent 42ff89d741
commit 00ab15d850
3 changed files with 41 additions and 30 deletions

View file

@ -19,7 +19,6 @@ cargo install flarumdown
``` bash
RUST_LOG=warn flarumdown -s '/path/to/flarum.sqlite' \
-t '/path/to/target' \
-u '/path/to/flarum/public' \
-i index \
-r http://[202:68d0:f0d5:b88d:1d1a:555e:2f6b:3148] \
-r http://[505:6847:c778:61a1:5c6d:e802:d291:8191] \

View file

@ -8,10 +8,12 @@ pub struct Config {
#[arg(short, long)]
pub source: PathBuf,
/// Path to export FoF/upload tags from
/// * tip: root should be the path to `flarum/public` dir
/// Path to export FoF/upload files from
/// tips:
/// * root should be the path to `flarum/public` dir
/// * use rsync instead of this option for longer SSD life
#[arg(short, long)]
pub upload: PathBuf,
pub upload: Option<PathBuf>,
/// Path to export markdown
#[arg(short, long)]

View file

@ -190,16 +190,23 @@ fn main() -> Result<()> {
post
});
for upload in &uploads {
let path_target = {
let mut p = PathBuf::from(&config.target);
p.push(upload);
p
};
// upload option is active, create files copy in the destinations
if let Some(ref upload_source) = config.upload {
let path_source = {
let mut p = PathBuf::from(&config.upload);
let mut p = PathBuf::from(upload_source);
p.push(upload);
match p.canonicalize() {
Ok(canonical) => {
if canonical.starts_with(&config.upload) {
if canonical.starts_with(upload_source) {
canonical
} else {
warn!(
"Possible traversal request: `{}` (post #{}, user #{})",
"Possible traversal injection: `{}` (post #{}, user #{})",
canonical.to_string_lossy(),
post.id,
post.user_id
@ -213,15 +220,18 @@ fn main() -> Result<()> {
}
}
};
let path_target = {
let mut p = PathBuf::from(&config.target);
p.push(upload);
p
};
if !path_target.exists() {
create_dir_all(path_target.parent().unwrap())?;
copy(path_source, path_target)?;
}
// task delegated to rsync (manually pre-copied FoF/upload destinations must exist)
} else if !path_target.exists() {
warn!(
"Referenced file does not exist: `{}` (post #{})",
path_target.to_string_lossy(),
post.id
)
}
}
content.push("---\n".into())
}