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 ``` bash
RUST_LOG=warn flarumdown -s '/path/to/flarum.sqlite' \ RUST_LOG=warn flarumdown -s '/path/to/flarum.sqlite' \
-t '/path/to/target' \ -t '/path/to/target' \
-u '/path/to/flarum/public' \
-i index \ -i index \
-r http://[202:68d0:f0d5:b88d:1d1a:555e:2f6b:3148] \ -r http://[202:68d0:f0d5:b88d:1d1a:555e:2f6b:3148] \
-r http://[505:6847:c778:61a1:5c6d:e802:d291:8191] \ -r http://[505:6847:c778:61a1:5c6d:e802:d291:8191] \

View file

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

View file

@ -190,16 +190,23 @@ fn main() -> Result<()> {
post post
}); });
for upload in &uploads { 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 path_source = {
let mut p = PathBuf::from(&config.upload); let mut p = PathBuf::from(upload_source);
p.push(upload); p.push(upload);
match p.canonicalize() { match p.canonicalize() {
Ok(canonical) => { Ok(canonical) => {
if canonical.starts_with(&config.upload) { if canonical.starts_with(upload_source) {
canonical canonical
} else { } else {
warn!( warn!(
"Possible traversal request: `{}` (post #{}, user #{})", "Possible traversal injection: `{}` (post #{}, user #{})",
canonical.to_string_lossy(), canonical.to_string_lossy(),
post.id, post.id,
post.user_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() { if !path_target.exists() {
create_dir_all(path_target.parent().unwrap())?; create_dir_all(path_target.parent().unwrap())?;
copy(path_source, path_target)?; 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()) content.push("---\n".into())
} }