mirror of
https://github.com/YGGverse/flarumdown.git
synced 2026-03-31 08:45:28 +00:00
make upload argument optional (delegate FoF/upload to external rsync logic)
This commit is contained in:
parent
42ff89d741
commit
00ab15d850
3 changed files with 41 additions and 30 deletions
|
|
@ -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] \
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
62
src/main.rs
62
src/main.rs
|
|
@ -190,37 +190,47 @@ fn main() -> Result<()> {
|
|||
post
|
||||
});
|
||||
for upload in &uploads {
|
||||
let path_source = {
|
||||
let mut p = PathBuf::from(&config.upload);
|
||||
p.push(upload);
|
||||
match p.canonicalize() {
|
||||
Ok(canonical) => {
|
||||
if canonical.starts_with(&config.upload) {
|
||||
canonical
|
||||
} else {
|
||||
warn!(
|
||||
"Possible traversal request: `{}` (post #{}, user #{})",
|
||||
canonical.to_string_lossy(),
|
||||
post.id,
|
||||
post.user_id
|
||||
);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!("{e}: `{}` (post #{})", p.to_string_lossy(), post.id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
};
|
||||
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)?;
|
||||
// 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(upload_source);
|
||||
p.push(upload);
|
||||
match p.canonicalize() {
|
||||
Ok(canonical) => {
|
||||
if canonical.starts_with(upload_source) {
|
||||
canonical
|
||||
} else {
|
||||
warn!(
|
||||
"Possible traversal injection: `{}` (post #{}, user #{})",
|
||||
canonical.to_string_lossy(),
|
||||
post.id,
|
||||
post.user_id
|
||||
);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!("{e}: `{}` (post #{})", p.to_string_lossy(), post.id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
};
|
||||
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())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue