From c3173623176a158e8feb7adef330855d8ee34b6c Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 19 Mar 2026 23:31:06 +0200 Subject: [PATCH] minor logic update --- src/main.rs | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1462795..8e89bb3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -195,42 +195,42 @@ fn main() -> Result<()> { 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 = { + match config.upload { + // upload option is active, + // create files copy in the destinations + Some(ref upload_source) => { let mut p = PathBuf::from(upload_source); p.push(upload); match p.canonicalize() { - Ok(canonical) => { - if canonical.starts_with(upload_source) { - canonical + Ok(src) => { + if src.starts_with(upload_source) { + if !path_target.exists() { + create_dir_all(path_target.parent().unwrap())?; + copy(src, path_target)?; + } } else { warn!( "Possible traversal injection: `{}` (post #{}, user #{})", - canonical.to_string_lossy(), + src.to_string_lossy(), post.id, post.user_id - ); - continue; + ) } } - Err(e) => { - error!("{e}: `{}` (post #{})", p.to_string_lossy(), post.id); - continue; - } + Err(e) => error!("{e}: `{}` (post #{})", p.to_string_lossy(), post.id) + } + }, + // task delegated to rsync + // * manually pre-copied FoF/upload destinations must exist + None => { + if !path_target.exists() { + warn!( + "Referenced file does not exist: `{}` (post #{})", + path_target.to_string_lossy(), + post.id + ) } - }; - 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())