mirror of
https://github.com/YGGverse/flarumdown.git
synced 2026-03-31 08:45:28 +00:00
minor logic update
This commit is contained in:
parent
00ab15d850
commit
c317362317
1 changed files with 24 additions and 24 deletions
38
src/main.rs
38
src/main.rs
|
|
@ -195,37 +195,35 @@ fn main() -> Result<()> {
|
||||||
p.push(upload);
|
p.push(upload);
|
||||||
p
|
p
|
||||||
};
|
};
|
||||||
// upload option is active, create files copy in the destinations
|
match config.upload {
|
||||||
if let Some(ref upload_source) = config.upload {
|
// upload option is active,
|
||||||
let path_source = {
|
// create files copy in the destinations
|
||||||
|
Some(ref upload_source) => {
|
||||||
let mut p = PathBuf::from(upload_source);
|
let mut p = PathBuf::from(upload_source);
|
||||||
p.push(upload);
|
p.push(upload);
|
||||||
match p.canonicalize() {
|
match p.canonicalize() {
|
||||||
Ok(canonical) => {
|
Ok(src) => {
|
||||||
if canonical.starts_with(upload_source) {
|
if src.starts_with(upload_source) {
|
||||||
canonical
|
if !path_target.exists() {
|
||||||
|
create_dir_all(path_target.parent().unwrap())?;
|
||||||
|
copy(src, path_target)?;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
warn!(
|
warn!(
|
||||||
"Possible traversal injection: `{}` (post #{}, user #{})",
|
"Possible traversal injection: `{}` (post #{}, user #{})",
|
||||||
canonical.to_string_lossy(),
|
src.to_string_lossy(),
|
||||||
post.id,
|
post.id,
|
||||||
post.user_id
|
post.user_id
|
||||||
);
|
)
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => error!("{e}: `{}` (post #{})", p.to_string_lossy(), post.id)
|
||||||
error!("{e}: `{}` (post #{})", p.to_string_lossy(), post.id);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
// task delegated to rsync
|
||||||
|
// * manually pre-copied FoF/upload destinations must exist
|
||||||
|
None => {
|
||||||
if !path_target.exists() {
|
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!(
|
warn!(
|
||||||
"Referenced file does not exist: `{}` (post #{})",
|
"Referenced file does not exist: `{}` (post #{})",
|
||||||
path_target.to_string_lossy(),
|
path_target.to_string_lossy(),
|
||||||
|
|
@ -233,6 +231,8 @@ fn main() -> Result<()> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
content.push("---\n".into())
|
content.push("---\n".into())
|
||||||
}
|
}
|
||||||
content.push(format!("Generated at {}\n", Utc::now()));
|
content.push(format!("Generated at {}\n", Utc::now()));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue