create log and patch directories if they're missing
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
226577f91a
commit
a6be644ebf
@ -15,6 +15,17 @@ use elseware::entity::item::{NewItemEntity, ItemDetail, InventoryItemEntity};
|
||||
use elseware::entity::item;
|
||||
|
||||
fn setup_logger() {
|
||||
match std::fs::create_dir("log") {
|
||||
Ok(()) => {},
|
||||
Err(e) => {
|
||||
match e.kind() {
|
||||
std::io::ErrorKind::AlreadyExists => {}, // false error
|
||||
_ => { // real error
|
||||
panic!("Failed to create \"log\" directory.\n{:?}", e);
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
let colors = fern::colors::ColoredLevelConfig::new()
|
||||
.error(fern::colors::Color::Red)
|
||||
.warn(fern::colors::Color::Yellow)
|
||||
|
@ -217,7 +217,22 @@ impl ServerState for PatchServerState {
|
||||
}
|
||||
|
||||
fn load_patch_dir(basedir: &str, patchbase: &str, file_ids: &mut HashMap<u32, PatchFile>) -> PatchFileTree {
|
||||
let paths = fs::read_dir(basedir).expect("could not read directory");
|
||||
let paths = {
|
||||
match fs::read_dir(basedir) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
match e.kind() {
|
||||
std::io::ErrorKind::NotFound => { // attempt to create the missing directory
|
||||
match std::fs::create_dir(basedir) {
|
||||
Ok(_) => fs::read_dir(basedir).expect("could not read newly created directory"), // created patch directory successfully. return it to paths
|
||||
Err(ee) => panic!("Failed to create directory \"{}\".\n{:?}", basedir, ee), // we already know the path doesnt exist so no need to check for AlreadyExists error. panic
|
||||
}
|
||||
},
|
||||
_ => panic!("Unable to read directory \"{}\".\n{:?}", basedir, e),
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
let mut files = Vec::new();
|
||||
let mut dirs = Vec::new();
|
||||
|
Loading…
x
Reference in New Issue
Block a user