Fix forgotten unwrap of the core while serializing

The core was serialized into the file within an Ok(), which is not
expected by the mercator service.
This commit is contained in:
2020-01-27 13:35:38 +01:00
parent a72fbcc88f
commit a10ffdac7d
2 changed files with 11 additions and 18 deletions

View File

@@ -4,12 +4,11 @@ mod space_db;
mod space_index; mod space_index;
use std::collections::HashMap; use std::collections::HashMap;
use std::fs::File;
use ironsea_index::Indexed; use ironsea_index::Indexed;
use memmap::Mmap;
use serde::Serialize; use serde::Serialize;
use super::storage;
pub use db_core::Core; pub use db_core::Core;
pub use db_core::CoreQueryParameters; pub use db_core::CoreQueryParameters;
pub use db_core::Properties; pub use db_core::Properties;
@@ -73,22 +72,8 @@ impl DataBase {
Ok(DataBase::new(spaces, cores)) Ok(DataBase::new(spaces, cores))
} }
fn mmap_file(filename: &str) -> Result<Mmap, String> {
let file_in = match File::open(filename) {
Err(e) => return Err(format!("{:?}", e)),
Ok(file) => file,
};
match unsafe { Mmap::map(&file_in) } {
Err(e) => Err(format!("{:?}", e)),
Ok(mmap) => Ok(mmap),
}
}
fn load_core(name: &str) -> Result<(Vec<Space>, Core), String> { fn load_core(name: &str) -> Result<(Vec<Space>, Core), String> {
let mmap = DataBase::mmap_file(&name)?; match storage::bincode::load(name) {
match bincode::deserialize(&mmap[..]) {
Err(e) => Err(format!("Index deserialization error: {:?}", e)), Err(e) => Err(format!("Index deserialization error: {:?}", e)),
Ok(index) => Ok(index), Ok(index) => Ok(index),
} }

View File

@@ -61,7 +61,15 @@ pub fn build(
let objects = load::<Vec<model::SpatialObject>>(&fn_objects)?; let objects = load::<Vec<model::SpatialObject>>(&fn_objects)?;
let core = model::build_index(name, version, &spaces, &objects, scales, max_elements); let core = match model::build_index(name, version, &spaces, &objects, scales, max_elements) {
Ok(core) => core,
Err(e) => {
return Err(Error::new(
ErrorKind::InvalidData,
format!("Failure to build index: {:?}", e),
))
}
};
store((spaces, core), &fn_index) store((spaces, core), &fn_index)
} }