Correctly handle invalid upload path without panic

This commit is contained in:
Jake Howard 2024-02-28 21:22:34 +00:00
parent 90646b4cd0
commit faef037bb3
No known key found for this signature in database
GPG Key ID: 57AFB45680EDD477
1 changed files with 8 additions and 6 deletions

View File

@ -13,7 +13,7 @@ use rustypaste::util;
use rustypaste::CONFIG_ENV;
use std::env;
use std::fs;
use std::io::Result as IoResult;
use std::io::{Error as IoError, ErrorKind as IoErrorKind, Result as IoResult};
use std::path::{Path, PathBuf};
use std::sync::{mpsc, RwLock};
use std::thread;
@ -71,11 +71,13 @@ fn setup(config_folder: &Path) -> IoResult<(Data<RwLock<Config>>, ServerConfig,
// Create necessary directories.
fs::create_dir_all(&server_config.upload_path)?;
for paste_type in &[PasteType::Url, PasteType::Oneshot, PasteType::OneshotUrl] {
fs::create_dir_all(
paste_type
.get_path(&server_config.upload_path)
.expect("failed to get path for paste type"),
)?;
let _ = paste_type
.get_path(&server_config.upload_path)
.ok_or(IoError::new(
IoErrorKind::Other,
String::from("Invalid upload path"),
))
.map(fs::create_dir_all)?;
}
// Set up a watcher for the configuration file changes.