Browse Source

create log and patch directories if they're missing

andy/add-patch-log-dir
andy 1 year ago
parent
commit
a6be644ebf
  1. 11
      src/bin/main.rs
  2. 17
      src/patch/patch.rs

11
src/bin/main.rs

@ -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)

17
src/patch/patch.rs

@ -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…
Cancel
Save